'Get episode statistics for a given show'

def run(self):

    showObj = findCertainShow(sickrage.srCore.SHOWLIST, int(self.indexerid))
    if (not showObj):
        return _responds(RESULT_FAILURE, msg=u'Show    not    found')
    episode_status_counts_total = {u'total': 0}
    for status in statusStrings.statusStrings.keys():
        if (status in [UNKNOWN, DOWNLOADED, SNATCHED, SNATCHED_PROPER, ARCHIVED]):
            continue
        episode_status_counts_total[status] = 0
    episode_qualities_counts_download = {u'total': 0}
    for statusCode in (Quality.DOWNLOADED + Quality.ARCHIVED):
        (status, quality) = Quality.splitCompositeStatus(statusCode)
        if (quality in [Quality.NONE]):
            continue
        episode_qualities_counts_download[statusCode] = 0
    episode_qualities_counts_snatch = {u'total': 0}
    for statusCode in (Quality.SNATCHED + Quality.SNATCHED_PROPER):
        (status, quality) = Quality.splitCompositeStatus(statusCode)
        if (quality not in [Quality.NONE]):
            episode_qualities_counts_snatch[statusCode] = 0
    for row in [x[u'doc'] for x in sickrage.srCore.mainDB.db.get_many(u'tv_episodes', self.indexerid, with_doc=True) if (x[u'doc'][u'season'] != 0)]:
        (status, quality) = Quality.splitCompositeStatus(int(row[u'status']))
        episode_status_counts_total[u'total'] += 1
        if (status in (Quality.DOWNLOADED + Quality.ARCHIVED)):
            episode_qualities_counts_download[u'total'] += 1
            episode_qualities_counts_download[int(row[u'status'])] += 1
        elif (status in (Quality.SNATCHED + Quality.SNATCHED_PROPER)):
            episode_qualities_counts_snatch[u'total'] += 1
            episode_qualities_counts_snatch[int(row[u'status'])] += 1
        elif (status == 0):
            pass
        else:
            episode_status_counts_total[status] += 1
    episodes_stats = {u'downloaded': {}}
    for statusCode in episode_qualities_counts_download:
        if (statusCode == u'total'):
            episodes_stats[u'downloaded'][u'total'] = episode_qualities_counts_download[statusCode]
            continue
        (status, quality) = Quality.splitCompositeStatus(int(statusCode))
        statusString = Quality.qualityStrings[quality].lower().replace(u'    ', u'_').replace(u'(', u'').replace(u')', u'')
        episodes_stats[u'downloaded'][statusString] = episode_qualities_counts_download[statusCode]
    episodes_stats[u'snatched'] = {}
    for statusCode in episode_qualities_counts_snatch:
        if (statusCode == u'total'):
            episodes_stats[u'snatched'][u'total'] = episode_qualities_counts_snatch[statusCode]
            continue
        (status, quality) = Quality.splitCompositeStatus(int(statusCode))
        statusString = Quality.qualityStrings[quality].lower().replace(u'    ', u'_').replace(u'(', u'').replace(u')', u'')
        if (Quality.qualityStrings[quality] in episodes_stats[u'snatched']):
            episodes_stats[u'snatched'][statusString] += episode_qualities_counts_snatch[statusCode]
        else:
            episodes_stats[u'snatched'][statusString] = episode_qualities_counts_snatch[statusCode]
    for statusCode in episode_status_counts_total:
        if (statusCode == u'total'):
            episodes_stats[u'total'] = episode_status_counts_total[statusCode]
            continue
        (status, quality) = Quality.splitCompositeStatus(int(statusCode))
        statusString = statusStrings.statusStrings[statusCode].lower().replace(u'    ', u'_').replace(u'(', u'').replace(u')', u'')
        episodes_stats[statusString] = episode_status_counts_total[statusCode]
    return _responds(RESULT_SUCCESS, episodes_stats)
