'Search for a show with a given name on all the indexers, in a specific language'

def run(self):

    results = []
    lang_id = self.valid_languages[self.lang]
    if (self.name and (not self.indexerid)):
        for _indexer in (sickbeard.indexerApi().indexers if (self.indexer == 0) else [int(self.indexer)]):
            indexer_api_params = sickbeard.indexerApi(_indexer).api_params.copy()
            indexer_api_params[u'language'] = (self.lang or sickbeard.INDEXER_DEFAULT_LANGUAGE)
            indexer_api_params[u'actors'] = False
            indexer_api_params[u'custom_ui'] = classes.AllShowsListUI
            t = sickbeard.indexerApi(_indexer).indexer(**indexer_api_params)
            try:
                api_data = t[str(self.name).encode()]
            except (sickbeard.indexer_shownotfound, sickbeard.indexer_showincomplete, sickbeard.indexer_error):
                logger.log((u'API    ::    Unable    to    find    show    with    id    ' + str(self.indexerid)), logger.WARNING)
                continue
            for curSeries in api_data:
                results.append({indexer_ids[_indexer]: int(curSeries[u'id']), u'name': curSeries[u'seriesname'], u'first_aired': curSeries[u'firstaired'], u'indexer': int(_indexer)})
        return _responds(RESULT_SUCCESS, {u'results': results, u'langid': lang_id})
    elif self.indexerid:
        for _indexer in (sickbeard.indexerApi().indexers if (self.indexer == 0) else [int(self.indexer)]):
            indexer_api_params = sickbeard.indexerApi(_indexer).api_params.copy()
            indexer_api_params[u'language'] = (self.lang or sickbeard.INDEXER_DEFAULT_LANGUAGE)
            indexer_api_params[u'actors'] = False
            t = sickbeard.indexerApi(_indexer).indexer(**indexer_api_params)
            try:
                my_show = t[int(self.indexerid)]
            except (sickbeard.indexer_shownotfound, sickbeard.indexer_showincomplete, sickbeard.indexer_error):
                logger.log((u'API    ::    Unable    to    find    show    with    id    ' + str(self.indexerid)), logger.WARNING)
                return _responds(RESULT_SUCCESS, {u'results': [], u'langid': lang_id})
            if (not my_show.data[u'seriesname']):
                logger.log(((u'API    ::    Found    show    with    indexerid:    ' + str(self.indexerid)) + u',    however    it    contained    no    show    name'), logger.DEBUG)
                return _responds(RESULT_FAILURE, msg=u'Show    contains    no    name,    invalid    result')
            results = [{indexer_ids[_indexer]: int(my_show.data[u'id']), u'name': six.text_type(my_show.data[u'seriesname']), u'first_aired': my_show.data[u'firstaired'], u'indexer': int(_indexer)}]
            break
        return _responds(RESULT_SUCCESS, {u'results': results, u'langid': lang_id})
    else:
        return _responds(RESULT_FAILURE, msg=u'Either    a    unique    id    or    name    is    required!')
