1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-04 07:02:26 -05:00

Fix for issue #946 - Adding of shows via webAPI was failing.

Improvements made to Indexer's API modules, better error handling for missing or incomplete shows, shows that don't have actor or banner info are now properly error handled as well.
This commit is contained in:
echel0n 2014-11-24 18:47:14 -08:00
parent a9b44a156d
commit 9a33ddf85c
7 changed files with 270 additions and 203 deletions

View File

@ -1,6 +1,6 @@
# !/usr/bin/env python2
# encoding:utf-8
#author:dbr/Ben
# author:dbr/Ben
#project:tvdb_api
#repository:http://github.com/dbr/tvdb_api
#license:unlicense (http://unlicense.org/)
@ -39,7 +39,7 @@ from lib.dateutil.parser import parse
from lib.cachecontrol import CacheControl, caches
from tvdb_ui import BaseUI, ConsoleUI
from tvdb_exceptions import (tvdb_error, tvdb_userabort, tvdb_shownotfound,
from tvdb_exceptions import (tvdb_error, tvdb_userabort, tvdb_shownotfound, tvdb_showincomplete,
tvdb_seasonnotfound, tvdb_episodenotfound, tvdb_attributenotfound)
@ -627,10 +627,9 @@ class Tvdb:
"""Loads a URL using caching, returns an ElementTree of the source
"""
try:
src = self._loadUrl(url, params=params, language=language).values()[0]
return src
except:
return []
return self._loadUrl(url, params=params, language=language).values()[0]
except Exception, e:
raise tvdb_error(e)
def _setItem(self, sid, seas, ep, attrib, value):
"""Creates a new episode, creating Show(), Season() and
@ -681,11 +680,7 @@ class Tvdb:
log().debug("Searching for show %s" % series)
self.config['params_getSeries']['seriesname'] = series
try:
seriesFound = self._getetsrc(self.config['url_getSeries'], self.config['params_getSeries']).values()[0]
return seriesFound
except:
return []
return self._getetsrc(self.config['url_getSeries'], self.config['params_getSeries']).values()[0]
def _getSeries(self, series):
"""This searches TheTVDB.com for the series name,
@ -694,13 +689,13 @@ class Tvdb:
BaseUI is used to select the first result.
"""
allSeries = self.search(series)
if not allSeries:
log().debug('Series result returned zero')
raise tvdb_shownotfound("Show search returned zero results (cannot find show on TVDB)")
if not isinstance(allSeries, list):
allSeries = [allSeries]
if len(allSeries) == 0:
log().debug('Series result returned zero')
raise tvdb_shownotfound("Show-name search returned zero results (cannot find show on TVDB)")
if self.config['custom_ui'] is not None:
log().debug("Using custom UI %s" % (repr(self.config['custom_ui'])))
CustomUI = self.config['custom_ui']
@ -735,37 +730,38 @@ class Tvdb:
"""
log().debug('Getting season banners for %s' % (sid))
bannersEt = self._getetsrc(self.config['url_seriesBanner'] % (sid))
if not bannersEt:
log().debug('Banners result returned zero')
return
banners = {}
for cur_banner in bannersEt['banner']:
bid = cur_banner['id']
btype = cur_banner['bannertype']
btype2 = cur_banner['bannertype2']
if btype is None or btype2 is None:
continue
if not btype in banners:
banners[btype] = {}
if not btype2 in banners[btype]:
banners[btype][btype2] = {}
if not bid in banners[btype][btype2]:
banners[btype][btype2][bid] = {}
try:
for cur_banner in bannersEt['banner']:
bid = cur_banner['id']
btype = cur_banner['bannertype']
btype2 = cur_banner['bannertype2']
if btype is None or btype2 is None:
for k, v in cur_banner.items():
if k is None or v is None:
continue
if not btype in banners:
banners[btype] = {}
if not btype2 in banners[btype]:
banners[btype][btype2] = {}
if not bid in banners[btype][btype2]:
banners[btype][btype2][bid] = {}
for k, v in cur_banner.items():
if k is None or v is None:
continue
k, v = k.lower(), v.lower()
banners[btype][btype2][bid][k] = v
k, v = k.lower(), v.lower()
banners[btype][btype2][bid][k] = v
for k, v in banners[btype][btype2][bid].items():
if k.endswith("path"):
new_key = "_%s" % (k)
log().debug("Transforming %s to %s" % (k, new_key))
new_url = self.config['url_artworkPrefix'] % (v)
banners[btype][btype2][bid][new_key] = new_url
except:
pass
for k, v in banners[btype][btype2][bid].items():
if k.endswith("path"):
new_key = "_%s" % (k)
log().debug("Transforming %s to %s" % (k, new_key))
new_url = self.config['url_artworkPrefix'] % (v)
banners[btype][btype2][bid][new_key] = new_url
self._setShowData(sid, "_banners", banners)
@ -796,21 +792,22 @@ class Tvdb:
log().debug("Getting actors for %s" % (sid))
actorsEt = self._getetsrc(self.config['url_actorsInfo'] % (sid))
if not actorsEt:
log().debug('Actors result returned zero')
return
cur_actors = Actors()
try:
for curActorItem in actorsEt["actor"]:
curActor = Actor()
for k, v in curActorItem.items():
k = k.lower()
if v is not None:
if k == "image":
v = self.config['url_artworkPrefix'] % (v)
else:
v = self._cleanData(v)
curActor[k] = v
cur_actors.append(curActor)
except:
pass
for curActorItem in actorsEt["actor"]:
curActor = Actor()
for k, v in curActorItem.items():
k = k.lower()
if v is not None:
if k == "image":
v = self.config['url_artworkPrefix'] % (v)
else:
v = self._cleanData(v)
curActor[k] = v
cur_actors.append(curActor)
self._setShowData(sid, '_actors', cur_actors)
@ -840,18 +837,19 @@ class Tvdb:
self.config['url_seriesInfo'] % (sid, getShowInLanguage)
)
# get series data
try:
for k, v in seriesInfoEt['series'].items():
if v is not None:
if k in ['banner', 'fanart', 'poster']:
v = self.config['url_artworkPrefix'] % (v)
else:
v = self._cleanData(v)
if not seriesInfoEt:
log().debug('Series result returned zero')
raise tvdb_shownotfound("Show search returned zero results (cannot find show on TVDB)")
self._setShowData(sid, k, v)
except:
return False
# get series data
for k, v in seriesInfoEt['series'].items():
if v is not None:
if k in ['banner', 'fanart', 'poster']:
v = self.config['url_artworkPrefix'] % (v)
else:
v = self._cleanData(v)
self._setShowData(sid, k, v)
# get episode data
if getEpInfo:
@ -865,18 +863,17 @@ class Tvdb:
# Parse episode data
log().debug('Getting all episodes of %s' % (sid))
if self.config['useZip']:
url = self.config['url_epInfo_zip'] % (sid, language)
else:
url = self.config['url_epInfo'] % (sid, language)
epsEt = self._getetsrc(url, language=language)
try:
epsEt = self._getetsrc(url, language=language)
episodes = epsEt["episode"]
except:
return False
if not epsEt:
log().debug('Series results incomplete')
raise tvdb_showincomplete("Show search returned incomplete results (cannot find complete show on TVDB)")
episodes = epsEt["episode"]
if not isinstance(episodes, list):
episodes = [episodes]
@ -940,7 +937,7 @@ class Tvdb:
# Item is integer, treat as show id
if key not in self.shows:
self._getShowData(key, self.config['language'], True)
return (None, self.shows[key])[key in self.shows]
return self.shows[key]
key = str(key).lower()
self.config['searchterm'] = key
@ -949,14 +946,10 @@ class Tvdb:
selected_series = [selected_series]
[[self._setShowData(show['id'], k, v) for k, v in show.items()] for show in selected_series]
return selected_series
#test = self._getSeries(key)
#sids = self._nameToSid(key)
#return list(self.shows[sid] for sid in sids)
def __repr__(self):
return str(self.shows)
def main():
"""Simple example of using tvdb_api - it just
grabs an episode name interactively.

View File

@ -11,7 +11,7 @@
__author__ = "dbr/Ben"
__version__ = "1.9"
__all__ = ["tvdb_error", "tvdb_userabort", "tvdb_shownotfound",
__all__ = ["tvdb_error", "tvdb_userabort", "tvdb_shownotfound", "tvdb_showincomplete",
"tvdb_seasonnotfound", "tvdb_episodenotfound", "tvdb_attributenotfound"]
class tvdb_exception(Exception):
@ -35,6 +35,11 @@ class tvdb_shownotfound(tvdb_exception):
"""
pass
class tvdb_showincomplete(tvdb_exception):
"""Show found but incomplete on thetvdb.com (incomplete show)
"""
pass
class tvdb_seasonnotfound(tvdb_exception):
"""Season cannot be found on thetvdb.com
"""

View File

@ -1,7 +1,7 @@
# !/usr/bin/env python2
# encoding:utf-8
#author:echel0n
#project:tvrage_api
# author:echel0n
# project:tvrage_api
#repository:http://github.com/echel0n/tvrage_api
#license:unlicense (http://unlicense.org/)
@ -36,7 +36,7 @@ from lib.dateutil.parser import parse
from cachecontrol import CacheControl, caches
from tvrage_ui import BaseUI
from tvrage_exceptions import (tvrage_error, tvrage_userabort, tvrage_shownotfound,
from tvrage_exceptions import (tvrage_error, tvrage_userabort, tvrage_shownotfound, tvrage_showincomplete,
tvrage_seasonnotfound, tvrage_episodenotfound, tvrage_attributenotfound)
@ -103,7 +103,7 @@ class ShowContainer(dict):
if time.time() - self._lastgc > 20:
for o in self._stack[:-100]:
del self[o]
self._stack = self._stack[-100:]
self._lastgc = time.time()
@ -465,10 +465,6 @@ class TVRage:
elif key == 'firstaired':
value = parse(value, fuzzy=True).date()
value = value.strftime("%Y-%m-%d")
#if key == 'airs_time':
# value = parse(value).time()
# value = value.strftime("%I:%M %p")
except:
pass
@ -485,10 +481,9 @@ class TVRage:
"""
try:
src = self._loadUrl(url, params).values()[0]
return src
except:
return []
return self._loadUrl(url, params).values()[0]
except Exception, e:
raise tvrage_error(e)
def _setItem(self, sid, seas, ep, attrib, value):
"""Creates a new episode, creating Show(), Season() and
@ -518,9 +513,7 @@ class TVRage:
"""
if sid not in self.shows:
self.shows[sid] = Show()
if not isinstance(key, dict or list) and not isinstance(value, dict or list):
self.shows[sid].data[key] = value
self.shows[sid].data[key] = value
def _cleanData(self, data):
"""Cleans up strings returned by tvrage.com
@ -544,11 +537,7 @@ class TVRage:
log().debug("Searching for show %s" % series)
self.config['params_getSeries']['show'] = series
try:
seriesFound = self._getetsrc(self.config['url_getSeries'], self.config['params_getSeries']).values()[0]
return seriesFound
except:
return []
return self._getetsrc(self.config['url_getSeries'], self.config['params_getSeries']).values()[0]
def _getSeries(self, series):
"""This searches tvrage.com for the series name,
@ -557,13 +546,13 @@ class TVRage:
BaseUI is used to select the first result.
"""
allSeries = self.search(series)
if not allSeries:
log().debug('Series result returned zero')
raise tvrage_shownotfound("Show search returned zero results (cannot find show on TVRAGE)")
if not isinstance(allSeries, list):
allSeries = [allSeries]
if len(allSeries) == 0:
log().debug('Series result returned zero')
raise tvrage_shownotfound("Show-name search returned zero results (cannot find show on TVRAGE)")
if self.config['custom_ui'] is not None:
log().debug("Using custom UI %s" % (repr(self.config['custom_ui'])))
CustomUI = self.config['custom_ui']
@ -588,54 +577,55 @@ class TVRage:
self.config['params_seriesInfo']
)
# get series data
try:
for k, v in seriesInfoEt.items():
if v is not None:
v = self._cleanData(v)
if not seriesInfoEt:
log().debug('Series result returned zero')
raise tvrage_shownotfound("Show search returned zero results (cannot find show on TVRAGE)")
self._setShowData(sid, k, v)
except:
return False
# get series data
for k, v in seriesInfoEt.items():
if v is not None:
v = self._cleanData(v)
self._setShowData(sid, k, v)
# get episode data
if getEpInfo:
# Parse episode data
log().debug('Getting all episodes of %s' % (sid))
self.config['params_epInfo']['sid'] = sid
epsEt = self._getetsrc(self.config['url_epInfo'], self.config['params_epInfo'])
try:
epsEt = self._getetsrc(self.config['url_epInfo'], self.config['params_epInfo'])
seasons = epsEt['episodelist']['season']
except:
return False
if not epsEt:
log().debug('Series results incomplete')
raise tvrage_showincomplete(
"Show search returned incomplete results (cannot find complete show on TVRAGE)")
seasons = epsEt['episodelist']['season']
if not isinstance(seasons, list):
seasons = [seasons]
for season in seasons:
seas_no = int(season['@no'])
episodes = season['episode']
if not isinstance(episodes, list):
episodes = [episodes]
for episode in episodes:
ep_no = int(episode['episodenumber'])
self._setItem(sid, seas_no, ep_no, 'seasonnumber', seas_no)
for k, v in episode.items():
try:
k = k.lower()
if v is not None:
if k == 'link':
v = v.rsplit('/', 1)[1]
k = 'id'
k = k.lower()
if v is not None:
if k == 'link':
v = v.rsplit('/', 1)[1]
k = 'id'
else:
v = self._cleanData(v)
self._setItem(sid, seas_no, ep_no, k, v)
except:
continue
self._setItem(sid, seas_no, ep_no, k, v)
return True
def _nameToSid(self, name):
@ -663,9 +653,9 @@ class TVRage:
# Item is integer, treat as show id
if key not in self.shows:
self._getShowData(key, True)
return (None, self.shows[key])[key in self.shows]
return self.shows[key]
key = key.lower()
key = str(key).lower()
self.config['searchterm'] = key
selected_series = self._getSeries(key)
if isinstance(selected_series, dict):

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python2
#encoding:utf-8
# encoding:utf-8
#author:echel0n
#project:tvrage_api
#repository:http://github.com/echel0n/tvrage_api
@ -10,40 +10,53 @@
__author__ = "echel0n"
__version__ = "1.0"
__all__ = ["tvrage_error", "tvrage_userabort", "tvrage_shownotfound",
"tvrage_seasonnotfound", "tvrage_episodenotfound", "tvrage_attributenotfound"]
__all__ = ["tvrage_error", "tvrage_userabort", "tvrage_shownotfound", "tvrage_showincomplete",
"tvrage_seasonnotfound", "tvrage_episodenotfound", "tvrage_attributenotfound"]
class tvrage_exception(Exception):
"""Any exception generated by tvrage_api
"""
pass
class tvrage_error(tvrage_exception):
"""An error with tvrage.com (Cannot connect, for example)
"""
pass
class tvrage_userabort(tvrage_exception):
"""User aborted the interactive selection (via
the q command, ^c etc)
"""
pass
class tvrage_shownotfound(tvrage_exception):
"""Show cannot be found on tvrage.com (non-existant show)
"""
pass
class tvrage_showincomplete(tvrage_exception):
"""Show found but incomplete on tvrage.com (incomplete show)
"""
pass
class tvrage_seasonnotfound(tvrage_exception):
"""Season cannot be found on tvrage.com
"""
pass
class tvrage_episodenotfound(tvrage_exception):
"""Episode cannot be found on tvrage.com
"""
pass
class tvrage_attributenotfound(tvrage_exception):
"""Raised if an episode does not have the requested
attribute (such as a episode name)

View File

@ -45,8 +45,8 @@ from sickbeard import naming
from sickbeard import dailysearcher
from sickbeard import scene_numbering, scene_exceptions, name_cache
from indexers.indexer_api import indexerApi
from indexers.indexer_exceptions import indexer_shownotfound, indexer_exception, indexer_error, indexer_episodenotfound, \
indexer_attributenotfound, indexer_seasonnotfound, indexer_userabort, indexerExcepts
from indexers.indexer_exceptions import indexer_shownotfound, indexer_showincomplete, indexer_exception, indexer_error, \
indexer_episodenotfound, indexer_attributenotfound, indexer_seasonnotfound, indexer_userabort, indexerExcepts
from sickbeard.common import SD, SKIPPED, NAMING_REPEAT
from sickbeard.databases import mainDB, cache_db, failed_db
@ -466,10 +466,12 @@ TRAKT_API_KEY = 'abd806c54516240c76e4ebc9c5ccf394'
__INITIALIZED__ = False
def get_backlog_cycle_time():
cycletime = DAILYSEARCH_FREQUENCY * 2 + 7
return max([cycletime, 720])
def initialize(consoleLogging=True):
with INIT_LOCK:
@ -548,7 +550,8 @@ def initialize(consoleLogging=True):
# git_remote
GIT_REMOTE = check_setting_str(CFG, 'General', 'git_remote', 'origin')
GIT_REMOTE_URL = check_setting_str(CFG, 'General', 'git_remote_url', 'https://github.com/SiCKRAGETV/SickRage.git')
GIT_REMOTE_URL = check_setting_str(CFG, 'General', 'git_remote_url',
'https://github.com/SiCKRAGETV/SickRage.git')
# current commit hash
CUR_COMMIT_HASH = check_setting_str(CFG, 'General', 'cur_commit_hash', '')
@ -659,7 +662,8 @@ def initialize(consoleLogging=True):
NAMING_ABD_PATTERN = check_setting_str(CFG, 'General', 'naming_abd_pattern', '%SN - %A.D - %EN')
NAMING_CUSTOM_ABD = bool(check_setting_int(CFG, 'General', 'naming_custom_abd', 0))
NAMING_SPORTS_PATTERN = check_setting_str(CFG, 'General', 'naming_sports_pattern', '%SN - %A-D - %EN')
NAMING_ANIME_PATTERN = check_setting_str(CFG, 'General', 'naming_anime_pattern', 'Season %0S/%SN - S%0SE%0E - %EN')
NAMING_ANIME_PATTERN = check_setting_str(CFG, 'General', 'naming_anime_pattern',
'Season %0S/%SN - S%0SE%0E - %EN')
NAMING_ANIME = check_setting_int(CFG, 'General', 'naming_anime', 3)
NAMING_CUSTOM_SPORTS = bool(check_setting_int(CFG, 'General', 'naming_custom_sports', 0))
NAMING_CUSTOM_ANIME = bool(check_setting_int(CFG, 'General', 'naming_custom_anime', 0))
@ -1466,7 +1470,7 @@ def save_config():
new_config['General']['keep_processed_dir'] = int(KEEP_PROCESSED_DIR)
new_config['General']['process_method'] = PROCESS_METHOD
new_config['General']['move_associated_files'] = int(MOVE_ASSOCIATED_FILES)
new_config['General']['postpone_if_sync_files'] = int (POSTPONE_IF_SYNC_FILES)
new_config['General']['postpone_if_sync_files'] = int(POSTPONE_IF_SYNC_FILES)
new_config['General']['nfo_rename'] = int(NFO_RENAME)
new_config['General']['process_automatically'] = int(PROCESS_AUTOMATICALLY)
new_config['General']['unpack'] = int(UNPACK)

View File

@ -1,5 +1,5 @@
#!/usr/bin/env python2
#encoding:utf-8
# encoding:utf-8
#author:echel0n
#project:indexer_api
#repository:http://github.com/echel0n/Sick-Beard
@ -12,19 +12,20 @@ __version__ = "1.0"
from lib.tvrage_api.tvrage_exceptions import \
tvrage_exception, tvrage_attributenotfound, tvrage_episodenotfound, tvrage_error, \
tvrage_seasonnotfound, tvrage_shownotfound, tvrage_userabort
tvrage_seasonnotfound, tvrage_shownotfound, tvrage_showincomplete, tvrage_userabort
from lib.tvdb_api.tvdb_exceptions import \
tvdb_exception, tvdb_attributenotfound, tvdb_episodenotfound, tvdb_error, \
tvdb_seasonnotfound, tvdb_shownotfound, tvdb_userabort
tvdb_seasonnotfound, tvdb_shownotfound, tvdb_showincomplete, tvdb_userabort
indexerExcepts = ["indexer_exception", "indexer_error", "indexer_userabort", "indexer_shownotfound",
"indexer_showincomplete",
"indexer_seasonnotfound", "indexer_episodenotfound", "indexer_attributenotfound"]
tvdbExcepts = ["tvdb_exception", "tvdb_error", "tvdb_userabort", "tvdb_shownotfound",
tvdbExcepts = ["tvdb_exception", "tvdb_error", "tvdb_userabort", "tvdb_shownotfound", "tvdb_showincomplete",
"tvdb_seasonnotfound", "tvdb_episodenotfound", "tvdb_attributenotfound"]
tvrageExcepts = ["tvdb_exception", "tvrage_error", "tvrage_userabort", "tvrage_shownotfound",
tvrageExcepts = ["tvdb_exception", "tvrage_error", "tvrage_userabort", "tvrage_shownotfound", "tvrage_showincomplete",
"tvrage_seasonnotfound", "tvrage_episodenotfound", "tvrage_attributenotfound"]
# link API exceptions to our exception handler
@ -34,4 +35,5 @@ indexer_userabort = tvdb_userabort, tvrage_userabort
indexer_attributenotfound = tvdb_attributenotfound, tvrage_attributenotfound
indexer_episodenotfound = tvdb_episodenotfound, tvrage_episodenotfound
indexer_seasonnotfound = tvdb_seasonnotfound, tvrage_seasonnotfound
indexer_shownotfound = tvdb_shownotfound, tvrage_shownotfound
indexer_shownotfound = tvdb_shownotfound, tvrage_shownotfound
indexer_showincomplete = tvdb_showincomplete, tvrage_showincomplete

View File

@ -73,7 +73,6 @@ class Api(webserve.MainHandler):
intent = 4
def index(self, *args, **kwargs):
self.apiKey = sickbeard.API_KEY
access, accessMsg, args, kwargs = self._grand_access(self.apiKey, args, kwargs)
@ -373,7 +372,7 @@ class ApiCall(object):
"""
# auto-select indexer
if key == "indexerid":
if key in indexer_ids:
if "tvdbid" in kwargs:
key = "tvdbid"
elif "tvrageid" in kwargs:
@ -1132,6 +1131,7 @@ class CMD_Exceptions(ApiCall):
# required
# optional
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, False, "int", [])
# super, missing, help
ApiCall.__init__(self, handler, args, kwargs)
@ -1642,7 +1642,6 @@ class CMD_SickBeardSearchIndexers(ApiCall):
self.lang, args = self.check_params(args, kwargs, "lang", "en", False, "string", self.valid_languages.keys())
self.indexerid, args = self.check_params(args, kwargs, "indexerid", None, False, "int", [])
self.indexer, args = self.check_params(args, kwargs, "indexer", self.indexer, False, "int", [])
# super, missing, help
ApiCall.__init__(self, handler, args, kwargs)
@ -1654,42 +1653,45 @@ class CMD_SickBeardSearchIndexers(ApiCall):
lang_id = self.valid_languages[self.lang]
if self.name and not self.indexerid: # only name was given
for self.indexer in sickbeard.indexerApi().indexers if not self.indexer else [int(self.indexer)]:
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
lINDEXER_API_PARMS['language'] = self.lang
for _indexer in sickbeard.indexerApi().indexers if self.indexer == 0 else [int(self.indexer)]:
lINDEXER_API_PARMS = sickbeard.indexerApi(_indexer).api_params.copy()
if self.lang and not self.lang == 'en':
lINDEXER_API_PARMS['language'] = self.lang
lINDEXER_API_PARMS['actors'] = False
lINDEXER_API_PARMS['custom_ui'] = classes.AllShowsListUI
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
apiData = None
t = sickbeard.indexerApi(_indexer).indexer(**lINDEXER_API_PARMS)
try:
apiData = t[str(self.name).encode()]
except Exception, e:
pass
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, {"results": [], "langid": lang_id})
for curSeries in apiData:
results.append({indexer_ids[self.indexer]: int(curSeries['id']),
results.append({indexer_ids[_indexer]: int(curSeries['id']),
"name": curSeries['seriesname'],
"first_aired": curSeries['firstaired'],
"indexer": self.indexer})
"indexer": int(_indexer)})
return _responds(RESULT_SUCCESS, {"results": results, "langid": lang_id})
elif self.indexerid:
for self.indexer in sickbeard.indexerApi().indexers if not self.indexer > 0 else [int(self.indexer)]:
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
for _indexer in sickbeard.indexerApi().indexers if self.indexer == 0 else [int(self.indexer)]:
lINDEXER_API_PARMS = sickbeard.indexerApi(_indexer).api_params.copy()
if self.lang and not self.lang == 'en':
lINDEXER_API_PARMS['language'] = self.lang
lINDEXER_API_PARMS['actors'] = False
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
t = sickbeard.indexerApi(_indexer).indexer(**lINDEXER_API_PARMS)
try:
myShow = t[int(self.indexerid)]
except (sickbeard.indexer_shownotfound, sickbeard.indexer_error):
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, {"results": [], "langid": lang_id})
@ -1699,9 +1701,12 @@ class CMD_SickBeardSearchIndexers(ApiCall):
self.indexerid) + ", however it contained no show name", logger.DEBUG)
return _responds(RESULT_FAILURE, msg="Show contains no name, invalid result")
results = [{indexer_ids[self.indexer]: self.indexerid,
# found show
results = [{indexer_ids[_indexer]: int(myShow.data['id']),
"name": unicode(myShow.data['seriesname']),
"first_aired": myShow.data['firstaired']}]
"first_aired": myShow.data['firstaired'],
"indexer": int(_indexer)}]
break
return _responds(RESULT_SUCCESS, {"results": results, "langid": lang_id})
else:
@ -1711,29 +1716,27 @@ class CMD_SickBeardSearchIndexers(ApiCall):
class CMD_SickBeardSearchTVDB(CMD_SickBeardSearchIndexers):
_help = {"desc": "search for show on theTVDB with a given string and language",
"optionalParameters": {"name": {"desc": "name of the show you want to search for"},
"tvdbid": {
"desc": "thetvdb.com unique id of a show"},
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"lang": {"desc": "the 2 letter abbreviation lang id"}
}
}
def __init__(self, handler, args, kwargs):
self.indexer = 1
self.indexerid, args = self.check_params(args, kwargs, "tvdbid", None, False, "int", [])
CMD_SickBeardSearchIndexers.__init__(self, handler, args, kwargs)
class CMD_SickBeardSearchTVRAGE(CMD_SickBeardSearchIndexers):
_help = {"desc": "search for show on TVRage with a given string and language",
"optionalParameters": {"name": {"desc": "name of the show you want to search for"},
"tvrageid": {
"desc": "tvrage.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
"lang": {"desc": "the 2 letter abbreviation lang id"}
}
}
def __init__(self, handler, args, kwargs):
self.indexer = 2
self.indexerid, args = self.check_params(args, kwargs, "tvrageid", None, False, "int", [])
CMD_SickBeardSearchIndexers.__init__(self, handler, args, kwargs)
@ -1835,8 +1838,9 @@ class CMD_Show(ApiCall):
"requiredParameters": {
"indexerid": {"desc": "unique id of a show"},
},
"optionalParameters": {"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
}
}
@ -1910,13 +1914,16 @@ class CMD_Show(ApiCall):
class CMD_ShowAddExisting(ApiCall):
_help = {"desc": "add a show in sickrage with an existing folder",
"requiredParameters": {"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com id"},
"requiredParameters": {"indexerid": {"desc": "unique id of a show"},
"location": {"desc": "full path to the existing folder for the show"}
},
"optionalParameters": {"initial": {"desc": "initial quality for the show"},
"archive": {"desc": "archive quality for the show"},
"flatten_folders": {"desc": "flatten subfolders for the show"},
"subtitles": {"desc": "allow search episode subtitle"}
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
"initial": {"desc": "initial quality for the show"},
"archive": {"desc": "archive quality for the show"},
"flatten_folders": {"desc": "flatten subfolders for the show"},
"subtitles": {"desc": "allow search episode subtitle"}
}
}
@ -1963,6 +1970,9 @@ class CMD_ShowAddExisting(ApiCall):
if not indexerName:
return _responds(RESULT_FAILURE, msg="Unable to retrieve information from indexer")
# set indexer so we can pass it along when adding show to SR
indexer = indexerResult['data']['results'][0]['indexer']
quality_map = {'sdtv': Quality.SDTV,
'sddvd': Quality.SDDVD,
'hdtv': Quality.HDTV,
@ -1989,7 +1999,7 @@ class CMD_ShowAddExisting(ApiCall):
if iqualityID or aqualityID:
newQuality = Quality.combineQualities(iqualityID, aqualityID)
sickbeard.showQueueScheduler.action.addShow(int(self.indexer), int(self.indexerid), self.location, SKIPPED,
sickbeard.showQueueScheduler.action.addShow(int(indexer), int(self.indexerid), self.location, SKIPPED,
newQuality, int(self.flatten_folders))
return _responds(RESULT_SUCCESS, {"name": indexerName}, indexerName + " has been queued to be added")
@ -1997,17 +2007,20 @@ class CMD_ShowAddExisting(ApiCall):
class CMD_ShowAddNew(ApiCall):
_help = {"desc": "add a new show to sickrage",
"requiredParameters": {"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com id"}
"requiredParameters": {"indexerid": {"desc": "unique id of a show"}
},
"optionalParameters": {"initial": {"desc": "initial quality for the show"},
"location": {"desc": "base path for where the show folder is to be created"},
"archive": {"desc": "archive quality for the show"},
"flatten_folders": {"desc": "flatten subfolders for the show"},
"status": {"desc": "status of missing episodes"},
"lang": {"desc": "the 2 letter lang abbreviation id"},
"subtitles": {"desc": "allow search episode subtitle"},
"anime": {"desc": "set show to anime"},
"scene": {"desc": "show searches episodes by scene numbering"}
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
"initial": {"desc": "initial quality for the show"},
"location": {"desc": "base path for where the show folder is to be created"},
"archive": {"desc": "archive quality for the show"},
"flatten_folders": {"desc": "flatten subfolders for the show"},
"status": {"desc": "status of missing episodes"},
"lang": {"desc": "the 2 letter lang abbreviation id"},
"subtitles": {"desc": "allow search episode subtitle"},
"anime": {"desc": "set show to anime"},
"scene": {"desc": "show searches episodes by scene numbering"}
}
}
@ -2123,6 +2136,9 @@ class CMD_ShowAddNew(ApiCall):
if not indexerName:
return _responds(RESULT_FAILURE, msg="Unable to retrieve information from indexer")
# set indexer for found show so we can pass it along
indexer = indexerResult['data']['results'][0]['indexer']
# moved the logic check to the end in an attempt to eliminate empty directory being created from previous errors
showPath = ek.ek(os.path.join, self.location, helpers.sanitizeFileName(indexerName))
@ -2138,7 +2154,7 @@ class CMD_ShowAddNew(ApiCall):
else:
helpers.chmodAsParent(showPath)
sickbeard.showQueueScheduler.action.addShow(int(self.indexer), int(self.indexerid), showPath, newStatus,
sickbeard.showQueueScheduler.action.addShow(int(indexer), int(self.indexerid), showPath, newStatus,
newQuality,
int(self.flatten_folders), self.lang, self.subtitles, self.anime,
self.scene) # @UndefinedVariable
@ -2149,7 +2165,11 @@ class CMD_ShowAddNew(ApiCall):
class CMD_ShowCache(ApiCall):
_help = {"desc": "check sickrage's cache to see if the banner or poster image for a show is valid",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"}
"indexerid": {"desc": "unique id of a show"}
},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
}
}
@ -2185,7 +2205,11 @@ class CMD_ShowCache(ApiCall):
class CMD_ShowDelete(ApiCall):
_help = {"desc": "delete a show in sickrage",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"},
"indexerid": {"desc": "unique id of a show"},
},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
}
}
@ -2213,7 +2237,11 @@ class CMD_ShowDelete(ApiCall):
class CMD_ShowGetQuality(ApiCall):
_help = {"desc": "get quality setting for a show in sickrage",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"}
"indexerid": {"desc": "unique id of a show"}
},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
}
}
@ -2238,7 +2266,11 @@ class CMD_ShowGetQuality(ApiCall):
class CMD_ShowGetPoster(ApiCall):
_help = {"desc": "get the poster stored for a show in sickrage",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"}
"indexerid": {"desc": "unique id of a show"}
},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
}
}
@ -2257,7 +2289,11 @@ class CMD_ShowGetPoster(ApiCall):
class CMD_ShowGetBanner(ApiCall):
_help = {"desc": "get the banner stored for a show in sickrage",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"}
"indexerid": {"desc": "unique id of a show"}
},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
}
}
@ -2276,9 +2312,12 @@ class CMD_ShowGetBanner(ApiCall):
class CMD_ShowPause(ApiCall):
_help = {"desc": "set a show's paused state in sickrage",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"},
"indexerid": {"desc": "unique id of a show"},
},
"optionalParameters": {"pause": {"desc": "set the pause state of the show"}
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
"pause": {"desc": "set the pause state of the show"}
}
}
@ -2309,7 +2348,11 @@ class CMD_ShowPause(ApiCall):
class CMD_ShowRefresh(ApiCall):
_help = {"desc": "refresh a show in sickrage",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"},
"indexerid": {"desc": "unique id of a show"},
},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
}
}
@ -2337,9 +2380,12 @@ class CMD_ShowRefresh(ApiCall):
class CMD_ShowSeasonList(ApiCall):
_help = {"desc": "display the season list for a given show",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"},
"indexerid": {"desc": "unique id of a show"},
},
"optionalParameters": {"sort": {"desc": "change the sort order from descending to ascending"}
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
"sort": {"desc": "change the sort order from descending to ascending"}
}
}
@ -2376,9 +2422,12 @@ class CMD_ShowSeasonList(ApiCall):
class CMD_ShowSeasons(ApiCall):
_help = {"desc": "display a listing of episodes for all or a given season",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"},
"indexerid": {"desc": "unique id of a show"},
},
"optionalParameters": {"season": {"desc": "the season number"},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
"season": {"desc": "the season number"},
}
}
@ -2445,10 +2494,13 @@ class CMD_ShowSetQuality(ApiCall):
_help = {
"desc": "set desired quality of a show in sickrage. if neither initial or archive are provided then the config default quality will be used",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"}
"indexerid": {"desc": "unique id of a show"}
},
"optionalParameters": {"initial": {"desc": "initial quality for the show"},
"archive": {"desc": "archive quality for the show"}
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
"initial": {"desc": "initial quality for the show"},
"archive": {"desc": "archive quality for the show"}
}
}
@ -2510,7 +2562,11 @@ class CMD_ShowSetQuality(ApiCall):
class CMD_ShowStats(ApiCall):
_help = {"desc": "display episode statistics for a given show",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"},
"indexerid": {"desc": "unique id of a show"},
},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
}
}
@ -2615,7 +2671,11 @@ class CMD_ShowStats(ApiCall):
class CMD_ShowUpdate(ApiCall):
_help = {"desc": "update a show in sickrage",
"requiredParameters": {
"indexerid or tvdbid or tvrageid": {"desc": "thetvdb.com or tvrage.com unique id of a show"},
"indexerid": {"desc": "unique id of a show"},
},
"optionalParameters": {
"tvdbid": {"desc": "thetvdb.com unique id of a show"},
"tvrageid": {"desc": "tvrage.com unique id of a show"},
}
}