Change factor TVDb lib artwork url to one function to remove duplicity issues.

This commit is contained in:
JackDandy 2016-11-05 15:49:03 +00:00
parent 0536f8da19
commit 7b656dca02

View file

@ -563,12 +563,12 @@ class Tvdb:
def process_data(data): def process_data(data):
te = ConvertXmlToDict(data) te = ConvertXmlToDict(data)
if isinstance(te, dict) and 'Data' in te and isinstance(te['Data'], dict) and \ if isinstance(te, dict) and 'Data' in te and isinstance(te['Data'], dict) \
'Series' in te['Data'] and isinstance(te['Data']['Series'], dict) and \ and 'Series' in te['Data'] and isinstance(te['Data']['Series'], dict) \
'FirstAired' in te['Data']['Series']: and 'FirstAired' in te['Data']['Series']:
try: try:
value = parse(te['Data']['Series']['FirstAired'], fuzzy=True).strftime('%Y-%m-%d') value = parse(te['Data']['Series']['FirstAired'], fuzzy=True).strftime('%Y-%m-%d')
except: except (StandardError, Exception):
value = None value = None
te['Data']['Series']['firstaired'] = value te['Data']['Series']['firstaired'] = value
return te return te
@ -587,7 +587,7 @@ class Tvdb:
else: else:
try: try:
return process_data(resp.content.strip()) return process_data(resp.content.strip())
except: except (StandardError, Exception):
return dict([(u'data', None)]) return dict([(u'data', None)])
def _getetsrc(self, url, params=None, language=None): def _getetsrc(self, url, params=None, language=None):
@ -596,7 +596,7 @@ class Tvdb:
try: try:
src = self._load_url(url, params=params, language=language).values()[0] src = self._load_url(url, params=params, language=language).values()[0]
return src return src
except: except (StandardError, Exception):
return [] return []
def _set_item(self, sid, seas, ep, attrib, value): def _set_item(self, sid, seas, ep, attrib, value):
@ -629,7 +629,8 @@ class Tvdb:
self.shows[sid] = Show() self.shows[sid] = Show()
self.shows[sid].data[key] = value self.shows[sid].data[key] = value
def _clean_data(self, data): @staticmethod
def _clean_data(data):
"""Cleans up strings returned by TheTVDB.com """Cleans up strings returned by TheTVDB.com
Issues corrected: Issues corrected:
@ -638,6 +639,9 @@ class Tvdb:
""" """
return data if not isinstance(data, basestring) else data.strip().replace(u'&', u'&') return data if not isinstance(data, basestring) else data.strip().replace(u'&', u'&')
def _get_url_artwork(self, image):
return image and (self.config['url_artworkPrefix'] % image) or image
def search(self, series): def search(self, series):
"""This searches TheTVDB.com for the series name """This searches TheTVDB.com for the series name
and returns the result list and returns the result list
@ -653,7 +657,7 @@ class Tvdb:
series_found['Series'] = [series_found['Series']] series_found['Series'] = [series_found['Series']]
series_found['Series'] = [{k.lower(): v for k, v in s.iteritems()} for s in series_found['Series']] series_found['Series'] = [{k.lower(): v for k, v in s.iteritems()} for s in series_found['Series']]
return series_found.values()[0] return series_found.values()[0]
except: except (StandardError, Exception):
pass pass
return [] return []
@ -733,9 +737,9 @@ class Tvdb:
if k.endswith('path'): if k.endswith('path'):
new_key = '_%s' % k new_key = '_%s' % k
self.log('Transforming %s to %s' % (k, new_key)) self.log('Transforming %s to %s' % (k, new_key))
new_url = self.config['url_artworkPrefix'] % v new_url = self._get_url_artwork(v)
banners[btype][btype2][bid][new_key] = new_url banners[btype][btype2][bid][new_key] = new_url
except: except (StandardError, Exception):
pass pass
self._set_show_data(sid, '_banners', banners) self._set_show_data(sid, '_banners', banners)
@ -775,12 +779,12 @@ class Tvdb:
k = k.lower() k = k.lower()
if None is not v: if None is not v:
if 'image' == k: if 'image' == k:
v = self.config['url_artworkPrefix'] % v v = self._get_url_artwork(v)
else: else:
v = self._clean_data(v) v = self._clean_data(v)
cur_actor[k] = v cur_actor[k] = v
cur_actors.append(cur_actor) cur_actors.append(cur_actor)
except: except (StandardError, Exception):
pass pass
self._set_show_data(sid, '_actors', cur_actors) self._set_show_data(sid, '_actors', cur_actors)
@ -812,7 +816,7 @@ class Tvdb:
for k, v in show_data['Series'].iteritems(): for k, v in show_data['Series'].iteritems():
if None is not v: if None is not v:
if k in ['banner', 'fanart', 'poster']: if k in ['banner', 'fanart', 'poster']:
v = self.config['url_artworkPrefix'] % v v = self._get_url_artwork(v)
else: else:
v = self._clean_data(v) v = self._clean_data(v)
@ -866,7 +870,7 @@ class Tvdb:
if None is not v: if None is not v:
if 'filename' == k: if 'filename' == k:
v = v and (self.config['url_artworkPrefix'] % v) or v v = self._get_url_artwork(v)
else: else:
v = self._clean_data(v) v = self._clean_data(v)