mirror of
https://github.com/SickGear/SickGear.git
synced 2025-01-05 17:43:37 +00:00
Change improve handling tvdb_api data when adding upcoming shows with unfilled data.
Change handle exceptions raised while creating show or episode metadata. Fix shows with no episode data (prevent exception).
This commit is contained in:
parent
0fe11e4d7f
commit
6d0bcddd03
4 changed files with 57 additions and 27 deletions
|
@ -1,6 +1,7 @@
|
|||
### 0.16.6 (2018-05-14 01:00:00 UTC)
|
||||
|
||||
* Change improve tolerance to parse a release title with a badly placed episode name
|
||||
* Change improve handling tvdb_api data when adding upcoming shows with unfilled data
|
||||
|
||||
|
||||
### 0.16.5 (2018-05-07 21:15:00 UTC)
|
||||
|
|
|
@ -563,6 +563,10 @@ class Tvdb:
|
|||
|
||||
return os.path.join(tempfile.gettempdir(), 'tvdb_api-%s' % uid)
|
||||
|
||||
def _match_url_pattern(self, pattern, url):
|
||||
if pattern in self.config:
|
||||
return re.search('^%s$' % re.escape(self.config[pattern]).replace('\\%s', '[^/]+'), url)
|
||||
|
||||
@retry((tvdb_error, tvdb_tokenexpired))
|
||||
def _load_url(self, url, params=None, language=None):
|
||||
log().debug('Retrieving URL %s' % url)
|
||||
|
@ -583,7 +587,7 @@ class Tvdb:
|
|||
session.headers.update({'Accept-Language': language})
|
||||
|
||||
resp = None
|
||||
if re.search(re.escape(self.config['url_seriesInfo']).replace('%s', '.*'), url):
|
||||
if self._match_url_pattern('url_seriesInfo', url):
|
||||
self.show_not_found = False
|
||||
self.not_found = False
|
||||
try:
|
||||
|
@ -595,8 +599,10 @@ class Tvdb:
|
|||
sickbeard.THETVDB_V2_API_TOKEN = self.get_new_token()
|
||||
raise tvdb_tokenexpired
|
||||
elif 404 == e.response.status_code:
|
||||
if re.search(re.escape(self.config['url_seriesInfo']).replace('%s', '.*'), url):
|
||||
if self._match_url_pattern('url_seriesInfo', url):
|
||||
self.show_not_found = True
|
||||
elif self._match_url_pattern('url_epInfo', url):
|
||||
resp = {'data': []}
|
||||
self.not_found = True
|
||||
elif 404 != e.response.status_code:
|
||||
raise tvdb_error
|
||||
|
@ -647,10 +653,16 @@ class Tvdb:
|
|||
try:
|
||||
src = self._load_url(url, params=params, language=language)
|
||||
if isinstance(src, dict):
|
||||
data = src['data'] or {}
|
||||
if None is not src['data']:
|
||||
data = src['data']
|
||||
else:
|
||||
data = {}
|
||||
# data = src['data'] or {}
|
||||
if isinstance(data, list):
|
||||
data = data[0] or {}
|
||||
if 1 > len(data.keys()):
|
||||
if 0 < len(data):
|
||||
data = data[0]
|
||||
# data = data[0] or {}
|
||||
if None is data or (isinstance(data, dict) and 1 > len(data.keys())):
|
||||
raise ValueError
|
||||
return src
|
||||
except (KeyError, IndexError, Exception):
|
||||
|
@ -912,9 +924,9 @@ class Tvdb:
|
|||
episode_data = self._getetsrc(self.config['url_epInfo'] % (sid, page), language=language)
|
||||
if None is episode_data:
|
||||
raise tvdb_error('Exception retrieving episodes for show')
|
||||
if None is not episode_data.get('data'):
|
||||
if not getattr(self, 'not_found', False) and None is not episode_data.get('data'):
|
||||
episodes.extend(episode_data['data'])
|
||||
page = episode_data.get('links', {}).get('next')
|
||||
page = episode_data.get('links', {}).get('next', None)
|
||||
|
||||
ep_map_keys = {'absolutenumber': u'absolute_number', 'airedepisodenumber': u'episodenumber',
|
||||
'airedseason': u'seasonnumber', 'airedseasonid': u'seasonid',
|
||||
|
|
|
@ -290,17 +290,29 @@ class GenericMetadata():
|
|||
return None
|
||||
|
||||
def create_show_metadata(self, show_obj):
|
||||
result = False
|
||||
if self.show_metadata and show_obj and not self._has_show_metadata(show_obj):
|
||||
logger.log(u"Metadata provider " + self.name + " creating show metadata for " + show_obj.name, logger.DEBUG)
|
||||
return self.write_show_file(show_obj)
|
||||
return False
|
||||
logger.log('Metadata provider %s creating show metadata for %s' % (self.name, show_obj.name), logger.DEBUG)
|
||||
try:
|
||||
result = self.write_show_file(show_obj)
|
||||
except sickbeard.indexer_error as e:
|
||||
logger.log('Unable to find useful show metadata for %s on %s: %s' % (
|
||||
self.name, sickbeard.indexerApi(show_obj.indexer).name, ex(e)), logger.WARNING)
|
||||
|
||||
return result
|
||||
|
||||
def create_episode_metadata(self, ep_obj):
|
||||
result = False
|
||||
if self.episode_metadata and ep_obj and not self._has_episode_metadata(ep_obj):
|
||||
logger.log(u"Metadata provider " + self.name + " creating episode metadata for " + ep_obj.prettyName(),
|
||||
logger.log('Metadata provider %s creating episode metadata for %s' % (self.name, ep_obj.prettyName()),
|
||||
logger.DEBUG)
|
||||
return self.write_ep_file(ep_obj)
|
||||
return False
|
||||
try:
|
||||
result = self.write_ep_file(ep_obj)
|
||||
except sickbeard.indexer_error as e:
|
||||
logger.log('Unable to find useful episode metadata for %s on %s: %s' % (
|
||||
self.name, sickbeard.indexerApi(ep_obj.show.indexer).name, ex(e)), logger.WARNING)
|
||||
|
||||
return result
|
||||
|
||||
def update_show_indexer_metadata(self, show_obj):
|
||||
if self.show_metadata and show_obj and self._has_show_metadata(show_obj):
|
||||
|
@ -804,7 +816,7 @@ class GenericMetadata():
|
|||
indexer_show_obj = t[show_obj.indexerid, False]
|
||||
except (sickbeard.indexer_error, IOError) as e:
|
||||
logger.log(u"Unable to look up show on " + sickbeard.indexerApi(
|
||||
show_obj.indexer).name + ", not downloading images: " + ex(e), logger.ERROR)
|
||||
show_obj.indexer).name + ", not downloading images: " + ex(e), logger.WARNING)
|
||||
return None
|
||||
|
||||
if not self._valid_show(indexer_show_obj, show_obj):
|
||||
|
@ -893,7 +905,7 @@ class GenericMetadata():
|
|||
indexer_show_obj = t[show_obj.indexerid]
|
||||
except (sickbeard.indexer_error, IOError) as e:
|
||||
logger.log(u'Unable to look up show on ' + sickbeard.indexerApi(
|
||||
show_obj.indexer).name + ', not downloading images: ' + ex(e), logger.ERROR)
|
||||
show_obj.indexer).name + ', not downloading images: ' + ex(e), logger.WARNING)
|
||||
return result
|
||||
|
||||
if not self._valid_show(indexer_show_obj, show_obj):
|
||||
|
|
|
@ -580,7 +580,6 @@ class TVShow(object):
|
|||
myDB = db.DBConnection()
|
||||
myDB.mass_action(sql_l)
|
||||
|
||||
|
||||
def loadEpisodesFromDB(self, update=False):
|
||||
|
||||
logger.log('Loading all episodes for [%s] from the DB' % self.name)
|
||||
|
@ -601,7 +600,12 @@ class TVShow(object):
|
|||
|
||||
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
|
||||
|
||||
cachedShow = t[self.indexerid]
|
||||
cachedShow = None
|
||||
try:
|
||||
cachedShow = t[self.indexerid]
|
||||
except sickbeard.indexer_error as e:
|
||||
logger.log('Unable to find cached seasons from %s: %s' % (
|
||||
sickbeard.indexerApi(self.indexer).name, ex(e)), logger.WARNING)
|
||||
if None is cachedShow:
|
||||
return scannedEps
|
||||
|
||||
|
@ -878,16 +882,17 @@ class TVShow(object):
|
|||
sqlResults = myDB.select('SELECT * FROM tv_shows WHERE indexer_id = ?', [self.indexerid])
|
||||
|
||||
if 1 != len(sqlResults):
|
||||
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
|
||||
if self.lang:
|
||||
lINDEXER_API_PARMS['language'] = self.lang
|
||||
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
|
||||
cached_show = t[self.indexerid]
|
||||
vals = (self.indexerid, '' if not cached_show else ' [%s]' % cached_show['seriesname'].strip())
|
||||
if 0 != len(sqlResults):
|
||||
logger.log('%s: Loading show info%s from database' % vals)
|
||||
raise exceptions.MultipleDBShowsException()
|
||||
logger.log('%s: Unable to find the show%s in the database' % vals)
|
||||
if 1 < len(sqlResults):
|
||||
lINDEXER_API_PARMS = sickbeard.indexerApi(self.indexer).api_params.copy()
|
||||
if self.lang:
|
||||
lINDEXER_API_PARMS['language'] = self.lang
|
||||
t = sickbeard.indexerApi(self.indexer).indexer(**lINDEXER_API_PARMS)
|
||||
cached_show = t[self.indexerid]
|
||||
vals = (self.indexerid, '' if not cached_show else ' [%s]' % cached_show['seriesname'].strip())
|
||||
if 0 != len(sqlResults):
|
||||
logger.log('%s: Loading show info%s from database' % vals)
|
||||
raise exceptions.MultipleDBShowsException()
|
||||
logger.log('%s: Unable to find the show%s in the database' % (self.indexerid, self.name))
|
||||
return
|
||||
else:
|
||||
if not self.indexer:
|
||||
|
|
Loading…
Reference in a new issue