diff --git a/sickbeard/__init__.py b/sickbeard/__init__.py index c70ff9ac..a8014452 100644 --- a/sickbeard/__init__.py +++ b/sickbeard/__init__.py @@ -29,12 +29,13 @@ import urllib from threading import Lock # apparently py2exe won't build these unless they're imported somewhere +from sickbeard import indexers +from indexers import indexer_api, indexer_exceptions, indexer_config from sickbeard import providers, metadata from providers import ezrss, tvtorrents, btn, newznab, womble, thepiratebay, torrentleech, kat, publichd, iptorrents, omgwtfnzbs, scc, hdtorrents, torrentday, hdbits, nextgen from sickbeard.config import CheckSection, check_setting_int, check_setting_str, ConfigMigrator - from sickbeard import searchCurrent, searchBacklog, showUpdater, versionChecker, properFinder, autoPostProcesser, subtitles, traktWatchListChecker -from sickbeard import helpers, db, exceptions, show_queue, search_queue, scheduler +from sickbeard import helpers, db, exceptions, show_queue, search_queue, scheduler, show_name_helpers from sickbeard import logger from sickbeard import naming @@ -146,10 +147,6 @@ NAMING_CUSTOM_ABD = None NAMING_FORCE_FOLDERS = False NAMING_STRIP_YEAR = None -TVDB_API_KEY = '9DAF49C96CBF8DAC' -TVDB_BASE_URL = None -INDEXER_API_PARMS = {} - USE_NZBS = None USE_TORRENTS = None @@ -467,8 +464,8 @@ def initialize(consoleLogging=True): USE_PUSHALOT, PUSHALOT_NOTIFY_ONSNATCH, PUSHALOT_NOTIFY_ONDOWNLOAD, PUSHALOT_NOTIFY_ONSUBTITLEDOWNLOAD, PUSHALOT_AUTHORIZATIONTOKEN, \ USE_PUSHBULLET, PUSHBULLET_NOTIFY_ONSNATCH, PUSHBULLET_NOTIFY_ONDOWNLOAD, PUSHBULLET_NOTIFY_ONSUBTITLEDOWNLOAD, PUSHBULLET_API, PUSHBULLET_DEVICE, \ versionCheckScheduler, VERSION_NOTIFY, PROCESS_AUTOMATICALLY, UNPACK, \ - KEEP_PROCESSED_DIR, PROCESS_METHOD, TV_DOWNLOAD_DIR, TVDB_BASE_URL, MIN_SEARCH_FREQUENCY, \ - showQueueScheduler, searchQueueScheduler, ROOT_DIRS, CACHE_DIR, ACTUAL_CACHE_DIR, INDEXER_API_PARMS, \ + KEEP_PROCESSED_DIR, PROCESS_METHOD, TV_DOWNLOAD_DIR, MIN_SEARCH_FREQUENCY, \ + showQueueScheduler, searchQueueScheduler, ROOT_DIRS, CACHE_DIR, ACTUAL_CACHE_DIR, \ NAMING_PATTERN, NAMING_MULTI_EP, NAMING_FORCE_FOLDERS, NAMING_ABD_PATTERN, NAMING_CUSTOM_ABD, NAMING_STRIP_YEAR, \ RENAME_EPISODES, properFinderScheduler, PROVIDER_ORDER, autoPostProcesserScheduler, \ WOMBLE, OMGWTFNZBS, OMGWTFNZBS_USERNAME, OMGWTFNZBS_APIKEY, providerList, newznabProviderList, torrentRssProviderList,\ @@ -580,14 +577,6 @@ def initialize(consoleLogging=True): elif 'ftp' in proxies: proxy_url = proxies['ftp'] - # Set our common indexer_api options here - INDEXER_API_PARMS = {'apikey': TVDB_API_KEY, - 'language': 'en', - 'useZip': True} - - if CACHE_DIR: - INDEXER_API_PARMS['cache'] = os.path.join(CACHE_DIR, 'tvdb') - QUALITY_DEFAULT = check_setting_int(CFG, 'General', 'quality_default', SD) STATUS_DEFAULT = check_setting_int(CFG, 'General', 'status_default', SKIPPED) VERSION_NOTIFY = check_setting_int(CFG, 'General', 'version_notify', 1) @@ -602,8 +591,6 @@ def initialize(consoleLogging=True): NAMING_FORCE_FOLDERS = naming.check_force_season_folders() NAMING_STRIP_YEAR = bool(check_setting_int(CFG, 'General', 'naming_strip_year', 0)) - TVDB_BASE_URL = 'http://thetvdb.com/api/' + TVDB_API_KEY - USE_NZBS = bool(check_setting_int(CFG, 'General', 'use_nzbs', 0)) USE_TORRENTS = bool(check_setting_int(CFG, 'General', 'use_torrents', 1)) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index a249027a..b9c37e58 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -351,11 +351,13 @@ def searchIndexersForShow(regShowName): for indexer in indexerStrings: logger.log(u"Trying to find the " + name + " on " + indexer, logger.DEBUG) - # try each indexer till we find a match - sickbeard.INDEXER_API_PARMS['indexer'] = indexer - try: - t = indexer_api.indexerApi(custom_ui=classes.ShowListUI, **sickbeard.INDEXER_API_PARMS) + lINDEXER_API_PARMS = {'indexer': indexer} + + lINDEXER_API_PARMS['search_all_languages'] = True + lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI + + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) showObj = t[name] return indexer except (indexer_exceptions.indexer_exception, IOError): @@ -363,10 +365,13 @@ def searchIndexersForShow(regShowName): try: # There's gotta be a better way of doing this but we don't wanna # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + + lINDEXER_API_PARMS = {'indexer': indexer} lINDEXER_API_PARMS['search_all_languages'] = True - t = indexer_api.indexerApi(custom_ui=classes.ShowListUI, **lINDEXER_API_PARMS) + lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI + + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) showObj = t[name] return indexer except (indexer_exceptions.indexer_exception, IOError): @@ -954,23 +959,23 @@ def get_show_by_name(name, showList, useIndexer=False): return show if useIndexer: - showResult = None for indexer in indexerStrings: - # try each indexer till we find a match - sickbeard.INDEXER_API_PARMS['indexer'] = indexer - try: - t = indexer_api.indexerApi(custom_ui=classes.ShowListUI, **sickbeard.INDEXER_API_PARMS) + lINDEXER_API_PARMS = {'indexer': indexer} + + lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI + + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) showObj = t[name] except (indexer_exceptions.indexer_exception, IOError): # if none found, search on all languages try: - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': indexer} lINDEXER_API_PARMS['search_all_languages'] = True - t = indexer_api.indexerApi(custom_ui=classes.ShowListUI, **lINDEXER_API_PARMS) + lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI + + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) showObj = t[name] except (indexer_exceptions.indexer_exception, IOError): pass diff --git a/sickbeard/indexers/__init__.py b/sickbeard/indexers/__init__.py index e69de29b..8c650d6f 100644 --- a/sickbeard/indexers/__init__.py +++ b/sickbeard/indexers/__init__.py @@ -0,0 +1,19 @@ +# Author: Nic Wolfe +# URL: http://code.google.com/p/sickbeard/ +# +# This file is part of Sick Beard. +# +# Sick Beard is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Sick Beard is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Sick Beard. If not, see . + +__all__ = ["indexer_api", "indexer_exceptions", "indexer_config"] \ No newline at end of file diff --git a/sickbeard/indexers/indexer_api.py b/sickbeard/indexers/indexer_api.py index e909ee9e..830fcc86 100644 --- a/sickbeard/indexers/indexer_api.py +++ b/sickbeard/indexers/indexer_api.py @@ -15,7 +15,11 @@ # # You should have received a copy of the GNU General Public License # along with Sick Beard. If not, see . +import os +import sickbeard + +from indexer_config import * from lib.tvdb_api.tvdb_api import Tvdb from lib.tvrage_api.tvrage_api import TVRage @@ -26,33 +30,18 @@ class indexerApi: return object.__new__(new_type) def __init__(self, indexer=None, language=None, *args, **kwargs): + self.name = indexer + self.config = INDEXER_CONFIG.copy() + + # wrap the indexer API object and return it back if indexer is not None: - self.name = indexer - self._wrapped = eval(indexer)(*args, **kwargs) - else: - self.name = "Indexer" + if sickbeard.CACHE_DIR: + INDEXER_API_PARMS[indexer]['cache'] = os.path.join(sickbeard.CACHE_DIR, indexer) - self.config = {} + lINDEXER_API_PARMS = INDEXER_API_PARMS[indexer].copy() + lINDEXER_API_PARMS.update(**kwargs) - self.config['valid_languages'] = [ - "da", "fi", "nl", "de", "it", "es", "fr","pl", "hu","el","tr", - "ru","he","ja","pt","zh","cs","sl", "hr","ko","en","sv","no" - ] - - self.config['langabbv_to_id'] = {'el': 20, 'en': 7, 'zh': 27, - 'it': 15, 'cs': 28, 'es': 16, 'ru': 22, 'nl': 13, 'pt': 26, 'no': 9, - 'tr': 21, 'pl': 18, 'fr': 17, 'hr': 31, 'de': 14, 'da': 10, 'fi': 11, - 'hu': 19, 'ja': 25, 'he': 24, 'ko': 32, 'sv': 8, 'sl': 30} - - if language is None: - self.config['language'] = 'en' - else: - if language not in self.config['valid_languages']: - raise ValueError("Invalid language %s, options are: %s" % ( - language, self.config['valid_languages'] - )) - else: - self.config['language'] = language + self._wrapped = eval(indexer)(*args, **lINDEXER_API_PARMS) def __getattr__(self, attr): return getattr(self._wrapped, attr) diff --git a/sickbeard/indexers/indexer_config.py b/sickbeard/indexers/indexer_config.py new file mode 100644 index 00000000..3db1b41a --- /dev/null +++ b/sickbeard/indexers/indexer_config.py @@ -0,0 +1,29 @@ +INDEXER_TVDB = 'Tvdb' +INDEXER_TVRAGE = 'TVRage' + +INDEXER_API_KEY = {} +INDEXER_API_KEY[INDEXER_TVDB] = '9DAF49C96CBF8DAC' +INDEXER_API_KEY[INDEXER_TVRAGE] = 'Uhewg1Rr0o62fvZvUIZt' + +INDEXER_BASEURL = {} +INDEXER_BASEURL[INDEXER_TVDB] = 'http://thetvdb.com/api/' + INDEXER_API_KEY[INDEXER_TVDB] +INDEXER_BASEURL[INDEXER_TVRAGE] = 'http://tvrage.com/feeds/' + INDEXER_API_KEY[INDEXER_TVRAGE] + +INDEXER_API_PARMS = {} +INDEXER_API_PARMS[INDEXER_TVDB] = {'apikey': INDEXER_API_KEY[INDEXER_TVDB], + 'language': 'en', + 'useZip': True} + +INDEXER_API_PARMS[INDEXER_TVRAGE] = {'apikey': INDEXER_API_KEY[INDEXER_TVRAGE], + 'language': 'en'} + + +INDEXER_CONFIG = {} +INDEXER_CONFIG['valid_languages'] = [ + "da", "fi", "nl", "de", "it", "es", "fr","pl", "hu","el","tr", + "ru","he","ja","pt","zh","cs","sl", "hr","ko","en","sv","no"] + +INDEXER_CONFIG['langabbv_to_id'] = {'el': 20, 'en': 7, 'zh': 27, +'it': 15, 'cs': 28, 'es': 16, 'ru': 22, 'nl': 13, 'pt': 26, 'no': 9, +'tr': 21, 'pl': 18, 'fr': 17, 'hr': 31, 'de': 14, 'da': 10, 'fi': 11, +'hu': 19, 'ja': 25, 'he': 24, 'ko': 32, 'sv': 8, 'sl': 30} \ No newline at end of file diff --git a/sickbeard/metadata/generic.py b/sickbeard/metadata/generic.py index 209e4f82..f792767e 100644 --- a/sickbeard/metadata/generic.py +++ b/sickbeard/metadata/generic.py @@ -338,15 +338,18 @@ class GenericMetadata(): try: # There's gotta be a better way of doing this but we don't wanna # change the language value elsewhere - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': ep_obj.show.indexer} + + lINDEXER_API_PARMS['actors'] = True if indexer_lang and not indexer_lang == 'en': - lindexer_api_parms['language'] = indexer_lang + lINDEXER_API_PARMS['language'] = indexer_lang if ep_obj.show.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True + + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) - t = indexer_api.indexerApi(actors=True, **lindexer_api_parms) indexer_show_obj = t[ep_obj.show.indexerid] except indexer_exceptions.indexer_shownotfound, e: raise exceptions.ShowNotFoundException(e.message) @@ -716,15 +719,17 @@ class GenericMetadata(): try: # There's gotta be a better way of doing this but we don't wanna # change the language value elsewhere - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': show_obj.indexer} + + lINDEXER_API_PARMS['banners'] = True if indexer_lang and not indexer_lang == 'en': - lindexer_api_parms['language'] = indexer_lang + lINDEXER_API_PARMS['language'] = indexer_lang if show_obj.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(banners=True, **lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) indexer_show_obj = t[show_obj.indexerid] except (indexer_exceptions.indexer_error, IOError), e: logger.log(u"Unable to look up show on " + show_obj.indexer + ", not downloading images: " + ex(e), logger.ERROR) @@ -764,15 +769,17 @@ class GenericMetadata(): try: # There's gotta be a better way of doing this but we don't wanna # change the language value elsewhere - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': show_obj.indexer} + + lINDEXER_API_PARMS['banners'] = True if indexer_lang and not indexer_lang == 'en': - lindexer_api_parms['language'] = indexer_lang + lINDEXER_API_PARMS['language'] = indexer_lang if show_obj.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(banners=True, **lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) indexer_show_obj = t[show_obj.indexerid] except (indexer_exceptions.indexer_error, IOError), e: logger.log(u"Unable to look up show on " + show_obj.indexer + ", not downloading images: " + ex(e), logger.ERROR) @@ -814,12 +821,14 @@ class GenericMetadata(): try: # There's gotta be a better way of doing this but we don't wanna # change the language value elsewhere - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': show_obj.indexer} + + lINDEXER_API_PARMS['banners'] = True if indexer_lang and not indexer_lang == 'en': - lindexer_api_parms['language'] = indexer_lang + lINDEXER_API_PARMS['language'] = indexer_lang - t = indexer_api.indexerApi(banners=True, **lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) indexer_show_obj = t[show_obj.indexerid] except (indexer_exceptions.indexer_error, IOError), e: logger.log(u"Unable to look up show on " + show_obj.indexer + ", not downloading images: " + ex(e), logger.ERROR) diff --git a/sickbeard/metadata/mediabrowser.py b/sickbeard/metadata/mediabrowser.py index 8d24936c..f882c1bc 100644 --- a/sickbeard/metadata/mediabrowser.py +++ b/sickbeard/metadata/mediabrowser.py @@ -227,7 +227,9 @@ class MediaBrowserMetadata(generic.GenericMetadata): indexer_lang = show_obj.lang # There's gotta be a better way of doing this but we don't wanna # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': show_obj.indexer} + + lINDEXER_API_PARMS['actors'] = True if indexer_lang and not indexer_lang == 'en': lINDEXER_API_PARMS['language'] = indexer_lang @@ -235,7 +237,7 @@ class MediaBrowserMetadata(generic.GenericMetadata): if show_obj.dvdorder != 0: lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(actors=True, **lINDEXER_API_PARMS) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) tv_node = etree.Element("Series") @@ -388,9 +390,9 @@ class MediaBrowserMetadata(generic.GenericMetadata): indexer_lang = ep_obj.show.lang try: - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': ep_obj.show.indexer} + + lINDEXER_API_PARMS['actors'] = True if indexer_lang and not indexer_lang == 'en': lINDEXER_API_PARMS['language'] = indexer_lang @@ -398,7 +400,8 @@ class MediaBrowserMetadata(generic.GenericMetadata): if ep_obj.show.dvdorder != 0: lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(actors=True, **lINDEXER_API_PARMS) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) + myShow = t[ep_obj.show.indexerid] except indexer_exceptions.indexer_shownotfound, e: raise exceptions.ShowNotFoundException(e.message) diff --git a/sickbeard/metadata/tivo.py b/sickbeard/metadata/tivo.py index ecd18c3b..dac42d93 100644 --- a/sickbeard/metadata/tivo.py +++ b/sickbeard/metadata/tivo.py @@ -169,9 +169,9 @@ class TIVOMetadata(generic.GenericMetadata): indexer_lang = ep_obj.show.lang try: - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': ep_obj.show.indexer} + + lINDEXER_API_PARMS['actors'] = True if indexer_lang and not indexer_lang == 'en': lINDEXER_API_PARMS['language'] = indexer_lang @@ -179,12 +179,12 @@ class TIVOMetadata(generic.GenericMetadata): if ep_obj.show.dvdorder != 0: lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(actors=True, **lINDEXER_API_PARMS) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) myShow = t[ep_obj.show.indexerid] except indexer_exceptions.indexer_shownotfound, e: raise exceptions.ShowNotFoundException(str(e)) except indexer_exceptions.indexer_error, e: - logger.log(u"Unable to connect to " + self.indexer + " while creating meta files - skipping - " + str(e), logger.ERROR) + logger.log(u"Unable to connect to " + ep_obj.show.indexer + " while creating meta files - skipping - " + str(e), logger.ERROR) return False for curEpToWrite in eps_to_write: diff --git a/sickbeard/metadata/wdtv.py b/sickbeard/metadata/wdtv.py index f0bac074..df3d93bb 100644 --- a/sickbeard/metadata/wdtv.py +++ b/sickbeard/metadata/wdtv.py @@ -177,9 +177,9 @@ class WDTVMetadata(generic.GenericMetadata): indexer_lang = ep_obj.show.lang try: - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': ep_obj.show.indexer} + + lINDEXER_API_PARMS['actors'] = True if indexer_lang and not indexer_lang == 'en': lINDEXER_API_PARMS['language'] = indexer_lang @@ -187,7 +187,7 @@ class WDTVMetadata(generic.GenericMetadata): if ep_obj.show.dvdorder != 0: lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(actors=True, **lINDEXER_API_PARMS) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) myShow = t[ep_obj.show.indexerid] except indexer_exceptions.indexer_shownotfound, e: raise exceptions.ShowNotFoundException(e.message) diff --git a/sickbeard/metadata/xbmc_12plus.py b/sickbeard/metadata/xbmc_12plus.py index ba620930..e5b71b24 100644 --- a/sickbeard/metadata/xbmc_12plus.py +++ b/sickbeard/metadata/xbmc_12plus.py @@ -16,13 +16,13 @@ # along with Sick Beard. If not, see . import generic - import datetime +import sickbeard from sickbeard.indexers import indexer_api, indexer_exceptions +from sickbeard.indexers.indexer_config import INDEXER_BASEURL -import sickbeard from sickbeard import logger, exceptions, helpers from sickbeard.exceptions import ex @@ -100,17 +100,17 @@ class XBMC_12PlusMetadata(generic.GenericMetadata): show_ID = show_obj.indexerid indexer_lang = show_obj.lang - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': show_obj.indexer} + + lINDEXER_API_PARMS['actors'] = True if indexer_lang and not indexer_lang == 'en': - lindexer_api_parms['language'] = indexer_lang + lINDEXER_API_PARMS['language'] = indexer_lang if show_obj.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(actors=True, **lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) tv_node = etree.Element("tvshow") @@ -153,8 +153,8 @@ class XBMC_12PlusMetadata(generic.GenericMetadata): episodeguide = etree.SubElement(tv_node, "episodeguide") episodeguideurl = etree.SubElement(episodeguide, "url") episodeguideurl2 = etree.SubElement(tv_node, "episodeguideurl") - if myShow["id"] != None: - showurl = sickbeard.TVDB_BASE_URL + '/series/' + myShow["id"] + '/all/en.zip' + if getattr(myShow, 'id', None) is not None: + showurl = INDEXER_BASEURL[show_obj.indexer] + '/series/' + myShow["id"] + '/all/en.zip' episodeguideurl.text = showurl episodeguideurl2.text = showurl @@ -219,18 +219,19 @@ class XBMC_12PlusMetadata(generic.GenericMetadata): eps_to_write = [ep_obj] + ep_obj.relatedEps indexer_lang = ep_obj.show.lang - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + + lINDEXER_API_PARMS = {'indexer': ep_obj.show.indexer} + + lINDEXER_API_PARMS['actors'] = True if indexer_lang and not indexer_lang == 'en': - lindexer_api_parms['language'] = indexer_lang + lINDEXER_API_PARMS['language'] = indexer_lang if ep_obj.show.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True try: - t = indexer_api.indexerApi(actors=True, **lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) myShow = t[ep_obj.show.indexerid] except indexer_exceptions.indexer_shownotfound, e: raise exceptions.ShowNotFoundException(e.message) diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index 6c607801..1f61e602 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -24,9 +24,10 @@ import regexes import sickbeard -from sickbeard import logger - +from sickbeard import logger, classes +from sickbeard import scene_numbering, scene_exceptions from sickbeard.indexers import indexer_api, indexer_exceptions +from sickbeard.common import indexerStrings from time import strptime @@ -285,31 +286,36 @@ class NameParser(object): # see if we can find the name with a TVDB lookup if check_indexer: for cur_name in name_list: - try: - t = indexer_api.indexerApi(custom_ui=sickbeard.classes.ShowListUI, **sickbeard.INDEXER_API_PARMS) - - logger.log(u"Looking up name "+cur_name+u" on the Indexer", logger.DEBUG) - showObj = t[cur_name] - except (indexer_exceptions): - # if none found, search on all languages + for indexer in indexerStrings: try: - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() - - lINDEXER_API_PARMS['search_all_languages'] = True - t = indexer_api.indexerApi(custom_ui=sickbeard.classes.ShowListUI, **lINDEXER_API_PARMS) - - logger.log(u"Looking up name "+cur_name+u" in all languages on the Indexer", logger.DEBUG) + lINDEXER_API_PARMS = {'indexer': indexer} + + lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI + + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) + + logger.log(u"Looking up name "+cur_name+u" on the Indexer", logger.DEBUG) showObj = t[cur_name] - except (indexer_exceptions.indexer_exception, IOError): - pass - - continue - except (IOError): - continue - - return showObj["id"] + except (indexer_exceptions): + # if none found, search on all languages + try: + lINDEXER_API_PARMS = {'indexer': indexer} + + lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI + lINDEXER_API_PARMS['search_all_languages'] = True + + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) + + logger.log(u"Looking up name "+cur_name+u" in all languages on the Indexer", logger.DEBUG) + showObj = t[cur_name] + except (indexer_exceptions.indexer_exception, IOError): + pass + + continue + except (IOError): + continue + + return showObj["id"] return None @@ -402,7 +408,7 @@ class ParseResult(object): new_episode_numbers = [] new_season_numbers = [] for epNo in self.episode_numbers: - (s, e) = sickbeard.scene_numbering.get_indexer_numbering(indexer_id, self.season_number, epNo) + (s, e) = scene_numbering.get_indexer_numbering(indexer_id, self.season_number, epNo) new_episode_numbers.append(e) new_season_numbers.append(s) diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index 6c3bdddf..57639139 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -517,19 +517,23 @@ class PostProcessor(object): # see if we can find the name with a TVDB lookup for cur_name in name_list: try: - t = indexer_api.indexerApi(custom_ui=classes.ShowListUI, **sickbeard.INDEXER_API_PARMS) + lINDEXER_API_PARMS = {'indexer': self.indexer} + + lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI + + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) self._log(u"Looking up name " + cur_name + u" on " + self.indexer + "", logger.DEBUG) showObj = t[cur_name] except (indexer_exceptions.indexer_exception, IOError): # if none found, search on all languages try: - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': self.indexer} lINDEXER_API_PARMS['search_all_languages'] = True - t = indexer_api.indexerApi(custom_ui=classes.ShowListUI, **lINDEXER_API_PARMS) + lINDEXER_API_PARMS['custom_ui'] = classes.ShowListUI + + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) self._log(u"Looking up name " + cur_name + u" in all languages on " + self.indexer + "", logger.DEBUG) showObj = t[cur_name] @@ -601,27 +605,25 @@ class PostProcessor(object): try: showObj = helpers.findCertainShow(sickbeard.showList, indexer_id) if(showObj != None): - # correct the indexer with the proper one linked to the show - self.indexer = showObj.indexer - sickbeard.INDEXER_API_PARMS['indexer'] = self.indexer - # set the language of the show indexer_lang = showObj.lang + self.indexer = showObj.indexer except exceptions.MultipleShowObjectsException: raise #TODO: later I'll just log this, for now I want to know about it ASAP try: - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': self.indexer} if indexer_lang and not indexer_lang == 'en': - lINDEXER_API_PARMS['language'] = indexer_lang + lINDEXER_API_PARMS = {'language': indexer_lang} t = indexer_api.indexerApi(**lINDEXER_API_PARMS) + epObj = t[indexer_id].airedOn(episodes[0])[0] + season = int(epObj["seasonnumber"]) episodes = [int(epObj["episodenumber"])] + self._log(u"Got season " + str(season) + " episodes " + str(episodes), logger.DEBUG) except indexer_exceptions.indexer_episodenotfound, e: self._log(u"Unable to find episode with date " + str(episodes[0]) + u" for show " + str(indexer_id) + u", skipping", logger.DEBUG) @@ -819,11 +821,11 @@ class PostProcessor(object): # reset per-file stuff self.in_history = False + # try to find the file info indexer_id = season = episodes = None if 'auto' in self.indexer: for indexer in indexerStrings: self.indexer = indexer - sickbeard.INDEXER_API_PARMS['indexer'] = self.indexer # try to find the file info (indexer_id, season, episodes) = self._find_info() @@ -832,9 +834,6 @@ class PostProcessor(object): self._log(u"Can't find show on " + self.indexer + ", auto trying next indexer in list", logger.WARNING) else: - sickbeard.INDEXER_API_PARMS['indexer'] = self.indexer - - # try to find the file info (indexer_id, season, episodes) = self._find_info() if not indexer_id or season == None or not episodes: diff --git a/sickbeard/properFinder.py b/sickbeard/properFinder.py index 4b45b0e1..f9d1f3fb 100644 --- a/sickbeard/properFinder.py +++ b/sickbeard/properFinder.py @@ -167,21 +167,18 @@ class ProperFinder(): logger.log(u"This should never have happened, post a bug about this!", logger.ERROR) raise Exception("BAD STUFF HAPPENED") - # correct the indexer with the proper one linked to the show - self.indexer = showObj.indexer - sickbeard.INDEXER_API_PARMS['indexer'] = self.indexer - indexer_lang = showObj.lang - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + + lINDEXER_API_PARMS = {'indexer': showObj.indexer} if indexer_lang and not indexer_lang == 'en': lINDEXER_API_PARMS['language'] = indexer_lang try: t = indexer_api.indexerApi(**lINDEXER_API_PARMS) + epObj = t[curProper.indexerid].airedOn(curProper.episode)[0] + curProper.season = int(epObj["seasonnumber"]) curProper.episodes = [int(epObj["episodenumber"])] except indexer_exceptions.indexer_episodenotfound: diff --git a/sickbeard/show_queue.py b/sickbeard/show_queue.py index 7a140b30..27ba14c4 100644 --- a/sickbeard/show_queue.py +++ b/sickbeard/show_queue.py @@ -231,14 +231,15 @@ class QueueItemAdd(ShowQueueItem): try: # make sure the indexer ids are valid try: - sickbeard.INDEXER_API_PARMS['indexer'] = self.indexer - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + + lINDEXER_API_PARMS = {'indexer': self.indexer} + if self.lang: - lindexer_api_parms['language'] = self.lang + lINDEXER_API_PARMS['language'] = self.lang - logger.log(u"" + self.indexer + ": " + repr(lindexer_api_parms)) + logger.log(u"" + self.indexer + ": " + repr(lINDEXER_API_PARMS)) - t = indexer_api.indexerApi(**lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) s = t[self.indexer_id] # this usually only happens if they have an NFO in their show dir which gave us a indexer ID that has no proper english version of the show diff --git a/sickbeard/tv.py b/sickbeard/tv.py index 2032bda6..419791ad 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -58,8 +58,6 @@ class TVShow(object): def __init__(self, indexer, indexerid, lang=""): - sickbeard.INDEXER_API_PARMS['indexer'] = indexer - self.indexerid = indexerid self.indexer = indexer self.name = "" @@ -351,15 +349,15 @@ class TVShow(object): scannedEps = {} - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': self.indexer} if self.lang: - lindexer_api_parms['language'] = self.lang + lINDEXER_API_PARMS['language'] = self.lang if self.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(**lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) cachedShow = t[self.indexerid] cachedSeasons = {} @@ -400,21 +398,19 @@ class TVShow(object): def loadEpisodesFromIndexer(self, cache=True): - # There's gotta be a better way of doing this but we don't wanna - # change the cache value elsewhere - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': self.indexer} if not cache: - lindexer_api_parms['cache'] = False + lINDEXER_API_PARMS['cache'] = False if self.lang: - lindexer_api_parms['language'] = self.lang + lINDEXER_API_PARMS['language'] = self.lang if self.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True try: - t = indexer_api.indexerApi(**lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) showObj = t[self.indexerid] except indexer_exceptions.indexer_error: logger.log(u"" + self.indexer + " timed out, unable to update episodes from " + self.indexer, logger.ERROR) @@ -505,17 +501,15 @@ class TVShow(object): # if we have an air-by-date show then get the real season/episode numbers if parse_result.air_by_date: try: - # There's gotta be a better way of doing this but we don't wanna - # change the cache value elsewhere - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': self.indexer} if self.lang: - lindexer_api_parms['language'] = self.lang + lINDEXER_API_PARMS['language'] = self.lang if self.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(**lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) epObj = t[self.indexerid].airedOn(parse_result.air_date)[0] season = int(epObj["seasonnumber"]) @@ -698,18 +692,18 @@ class TVShow(object): # There's gotta be a better way of doing this but we don't wanna # change the cache value elsewhere if tvapi is None: - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': self.indexer} if not cache: - lindexer_api_parms['cache'] = False + lINDEXER_API_PARMS['cache'] = False if self.lang: - lindexer_api_parms['language'] = self.lang + lINDEXER_API_PARMS['language'] = self.lang if self.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(**lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) else: t = tvapi @@ -1305,20 +1299,18 @@ class TVEpisode(object): try: if cachedSeason is None: if tvapi is None: - # There's gotta be a better way of doing this but we don't wanna - # change the cache value elsewhere - lindexer_api_parms = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': self.indexer} if not cache: - lindexer_api_parms['cache'] = False + lINDEXER_API_PARMS['cache'] = False if indexer_lang: - lindexer_api_parms['language'] = indexer_lang + lINDEXER_API_PARMS['language'] = indexer_lang if self.show.dvdorder != 0: - lindexer_api_parms['dvdorder'] = True + lINDEXER_API_PARMS['dvdorder'] = True - t = indexer_api.indexerApi(**lindexer_api_parms) + t = indexer_api.indexerApi(**lINDEXER_API_PARMS) else: t = tvapi myEp = t[self.show.indexerid][season][episode] diff --git a/sickbeard/tvcache.py b/sickbeard/tvcache.py index ce349380..41cc6c08 100644 --- a/sickbeard/tvcache.py +++ b/sickbeard/tvcache.py @@ -236,10 +236,6 @@ class TVCache(): except (MultipleShowObjectsException): showObj = None if showObj: - # correct the indexer with the proper one linked to the show - self.indexer = showObj.indexer - sickbeard.INDEXER_API_PARMS['indexer'] = self.indexer - indexer_lang = showObj.lang # if they're both empty then fill out as much info as possible by searching the show name @@ -290,10 +286,7 @@ class TVCache(): except (MultipleShowObjectsException): showObj = None if showObj: - # correct the indexer with the proper one linked to the show - self.indexer = showObj.indexer - sickbeard.INDEXER_API_PARMS['indexer'] = self.indexer - + self.indexer = showObj.inexer indexer_lang = showObj.lang # if we weren't provided with season/episode information then get it from the name that we parsed @@ -305,14 +298,13 @@ class TVCache(): # if we have an air-by-date show then get the real season/episode numbers if parse_result.air_by_date and indexer_id: try: - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': self.indexer} if not (indexer_lang == "" or indexer_lang == "en" or indexer_lang == None): lINDEXER_API_PARMS['language'] = indexer_lang t = indexer_api.indexerApi(**lINDEXER_API_PARMS) + epObj = t[indexer_id].airedOn(parse_result.air_date)[0] season = int(epObj["seasonnumber"]) episodes = [int(epObj["episodenumber"])] diff --git a/sickbeard/webapi.py b/sickbeard/webapi.py index 19f6f827..683821fa 100644 --- a/sickbeard/webapi.py +++ b/sickbeard/webapi.py @@ -37,6 +37,7 @@ from sickbeard import search_queue from sickbeard.common import SNATCHED, SNATCHED_PROPER, DOWNLOADED, SKIPPED, UNAIRED, IGNORED, ARCHIVED, WANTED, UNKNOWN from common import Quality, qualityPresetStrings, statusStrings from sickbeard import image_cache +from sickbeard.common import indexerStrings from sickbeard.indexers import indexer_api, indexer_exceptions try: @@ -1515,6 +1516,8 @@ class CMD_SickBeardSearchTVDB(ApiCall): self.name, args = self.check_params(args, kwargs, "name", None, False, "string", []) self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, False, "int", []) self.lang, args = self.check_params(args, kwargs, "lang", "en", False, "string", self.valid_languages.keys()) + self.indexer, args = self.check_params(args, kwargs, "indexer", None, False, "string", []) + # super, missing, help ApiCall.__init__(self, args, kwargs) @@ -1546,9 +1549,7 @@ class CMD_SickBeardSearchTVDB(ApiCall): return _responds(RESULT_SUCCESS, {"results": results, "langid": lang_id}) elif self.indexerid: - # There's gotta be a better way of doing this but we don't wanna - # change the language value elsewhere - lINDEXER_API_PARMS = sickbeard.INDEXER_API_PARMS.copy() + lINDEXER_API_PARMS = {'indexer': self.indexer} lang_id = self.valid_languages[self.lang] if self.lang and not self.lang == 'en': diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 4279e820..6bd20697 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -2840,10 +2840,6 @@ class Home: air_by_date = config.checkbox_to_value(air_by_date) subtitles = config.checkbox_to_value(subtitles) - # correct the indexer with the proper one linked to the show - self.indexer = showObj.indexer - sickbeard.INDEXER_API_PARMS['indexer'] = self.indexer - indexer_lang = showObj.lang # if we changed the language then kick off an update