'Get the list of episodes for one or all seasons of a show'

def run(self):

    sho_obj = Show.find(sickbeard.showList, int(self.indexerid))
    if (not sho_obj):
        return _responds(RESULT_FAILURE, msg=u'Show    not    found')
    main_db_con = db.DBConnection(row_type=u'dict')
    if (self.season is None):
        sql_results = main_db_con.select(u'SELECT    name,    episode,    airdate,    status,    release_name,    season,    location,    file_size,    subtitles    FROM    tv_episodes    WHERE    showid    =    ?', [self.indexerid])
        seasons = {}
        for row in sql_results:
            (status, quality) = Quality.splitCompositeStatus(int(row['status']))
            row['status'] = _get_status_strings(status)
            row['quality'] = get_quality_string(quality)
            if (try_int(row['airdate'], 1) > 693595):
                dt_episode_airs = sbdatetime.sbdatetime.convert_to_setting(network_timezones.parse_date_time(row['airdate'], sho_obj.airs, sho_obj.network))
                row['airdate'] = sbdatetime.sbdatetime.sbfdate(dt_episode_airs, d_preset=dateFormat)
            else:
                row['airdate'] = u'Never'
            cur_season = int(row['season'])
            cur_episode = int(row['episode'])
            del row['season']
            del row['episode']
            if (cur_season not in seasons):
                seasons[cur_season] = {}
            seasons[cur_season][cur_episode] = row
    else:
        sql_results = main_db_con.select(u'SELECT    name,    episode,    airdate,    status,    location,    file_size,    release_name,    subtitles    FROM    tv_episodes    WHERE    showid    =    ?    AND    season    =    ?', [self.indexerid, self.season])
        if (not sql_results):
            return _responds(RESULT_FAILURE, msg=u'Season    not    found')
        seasons = {}
        for row in sql_results:
            cur_episode = int(row['episode'])
            del row['episode']
            (status, quality) = Quality.splitCompositeStatus(int(row['status']))
            row['status'] = _get_status_strings(status)
            row['quality'] = get_quality_string(quality)
            if (try_int(row['airdate'], 1) > 693595):
                dt_episode_airs = sbdatetime.sbdatetime.convert_to_setting(network_timezones.parse_date_time(row['airdate'], sho_obj.airs, sho_obj.network))
                row['airdate'] = sbdatetime.sbdatetime.sbfdate(dt_episode_airs, d_preset=dateFormat)
            else:
                row['airdate'] = u'Never'
            if (cur_episode not in seasons):
                seasons[cur_episode] = {}
            seasons[cur_episode] = row
    return _responds(RESULT_SUCCESS, seasons)
