mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-02 17:33:37 +00:00
Fix issue with tvdb response data.
Change move data cleaner to helpers.
This commit is contained in:
parent
92fcdaf5df
commit
dc4cd6e2a6
5 changed files with 38 additions and 55 deletions
|
@ -1,4 +1,9 @@
|
||||||
### 0.17.2 (2018-08-30 15:06:00 UTC)
|
### 0.17.3 (2018-09-01 02:10:00 UTC)
|
||||||
|
|
||||||
|
* Fix issue with tvdb response data
|
||||||
|
|
||||||
|
|
||||||
|
### 0.17.2 (2018-08-30 15:06:00 UTC)
|
||||||
|
|
||||||
* Fix Blutopia, Skytorrents, and SpeedCD torrent providers
|
* Fix Blutopia, Skytorrents, and SpeedCD torrent providers
|
||||||
|
|
||||||
|
|
|
@ -125,19 +125,6 @@ class TraktIndexer:
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(self.shows)
|
return str(self.shows)
|
||||||
|
|
||||||
def _clean_data(self, data):
|
|
||||||
"""Cleans up strings, lists, dicts returned
|
|
||||||
|
|
||||||
Issues corrected:
|
|
||||||
- Replaces & with &
|
|
||||||
- Trailing whitespace
|
|
||||||
"""
|
|
||||||
if isinstance(data, list):
|
|
||||||
return [self._clean_data(d) for d in data]
|
|
||||||
if isinstance(data, dict):
|
|
||||||
return {k: self._clean_data(v) for k, v in data.iteritems()}
|
|
||||||
return data if not isinstance(data, (str, unicode)) else data.strip().replace(u'&', u'&')
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _dict_prevent_none(d, key, default):
|
def _dict_prevent_none(d, key, default):
|
||||||
v = None
|
v = None
|
||||||
|
@ -156,12 +143,13 @@ class TraktIndexer:
|
||||||
if None is not self.config['sleep_retry']:
|
if None is not self.config['sleep_retry']:
|
||||||
kwargs['sleep_retry'] = self.config['sleep_retry']
|
kwargs['sleep_retry'] = self.config['sleep_retry']
|
||||||
try:
|
try:
|
||||||
|
from sickbeard.helpers import clean_data
|
||||||
resp = TraktAPI().trakt_request(url, **kwargs)
|
resp = TraktAPI().trakt_request(url, **kwargs)
|
||||||
if len(resp):
|
if len(resp):
|
||||||
for d in resp:
|
for d in resp:
|
||||||
if isinstance(d, dict) and 'type' in d and d['type'] in self.config['result_types']:
|
if isinstance(d, dict) and 'type' in d and d['type'] in self.config['result_types']:
|
||||||
for k, v in d.iteritems():
|
for k, v in d.iteritems():
|
||||||
d[k] = self._clean_data(v)
|
d[k] = clean_data(v)
|
||||||
if 'show' in d and TraktResultTypes.show == d['type']:
|
if 'show' in d and TraktResultTypes.show == d['type']:
|
||||||
d.update(d['show'])
|
d.update(d['show'])
|
||||||
del d['show']
|
del d['show']
|
||||||
|
|
|
@ -22,11 +22,9 @@ import requests.exceptions
|
||||||
import datetime
|
import datetime
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from sickbeard.helpers import getURL, tryInt
|
from sickbeard.helpers import getURL, tryInt, clean_data
|
||||||
import sickbeard
|
import sickbeard
|
||||||
|
|
||||||
from lib.six.moves.html_parser import HTMLParser
|
|
||||||
|
|
||||||
from lib.dateutil.parser import parse
|
from lib.dateutil.parser import parse
|
||||||
from lib.cachecontrol import CacheControl, caches
|
from lib.cachecontrol import CacheControl, caches
|
||||||
|
|
||||||
|
@ -627,13 +625,13 @@ class Tvdb:
|
||||||
v = self.config['url_artworkPrefix'] % v
|
v = self.config['url_artworkPrefix'] % v
|
||||||
elif 'genre' == k:
|
elif 'genre' == k:
|
||||||
keep_data['genre_list'] = v
|
keep_data['genre_list'] = v
|
||||||
v = '|%s|' % '|'.join([self._clean_data(c) for c in v if isinstance(c, basestring)])
|
v = '|%s|' % '|'.join([clean_data(c) for c in v if isinstance(c, basestring)])
|
||||||
elif 'gueststars' == k:
|
elif 'gueststars' == k:
|
||||||
keep_data['gueststars_list'] = v
|
keep_data['gueststars_list'] = v
|
||||||
v = '|%s|' % '|'.join([self._clean_data(c) for c in v if isinstance(c, basestring)])
|
v = '|%s|' % '|'.join([clean_data(c) for c in v if isinstance(c, basestring)])
|
||||||
elif 'writers' == k:
|
elif 'writers' == k:
|
||||||
keep_data[k] = v
|
keep_data[k] = v
|
||||||
v = '|%s|' % '|'.join([self._clean_data(c) for c in v if isinstance(c, basestring)])
|
v = '|%s|' % '|'.join([clean_data(c) for c in v if isinstance(c, basestring)])
|
||||||
elif 'firstaired' == k:
|
elif 'firstaired' == k:
|
||||||
if v:
|
if v:
|
||||||
try:
|
try:
|
||||||
|
@ -645,11 +643,11 @@ class Tvdb:
|
||||||
elif 'imdbid' == k:
|
elif 'imdbid' == k:
|
||||||
if v:
|
if v:
|
||||||
if re.search(r'^(tt)?\d{1,7}$', v, flags=re.I):
|
if re.search(r'^(tt)?\d{1,7}$', v, flags=re.I):
|
||||||
v = self._clean_data(v)
|
v = clean_data(v)
|
||||||
else:
|
else:
|
||||||
v = ''
|
v = ''
|
||||||
else:
|
else:
|
||||||
v = self._clean_data(v)
|
v = clean_data(v)
|
||||||
if k in map_show:
|
if k in map_show:
|
||||||
k = map_show[k]
|
k = map_show[k]
|
||||||
if k_org is not k:
|
if k_org is not k:
|
||||||
|
@ -728,21 +726,6 @@ class Tvdb:
|
||||||
else:
|
else:
|
||||||
self.shows[sid].data[key] = value
|
self.shows[sid].data[key] = value
|
||||||
|
|
||||||
def _clean_data(self, data):
|
|
||||||
"""Cleans up strings, lists, dicts returned
|
|
||||||
|
|
||||||
Issues corrected:
|
|
||||||
- Replaces & with &
|
|
||||||
- Trailing whitespace
|
|
||||||
"""
|
|
||||||
if isinstance(data, list):
|
|
||||||
return [self._clean_data(d) for d in data]
|
|
||||||
if isinstance(data, dict):
|
|
||||||
return {k: self._clean_data(v) for k, v in data.iteritems()}
|
|
||||||
if isinstance(data, basestring):
|
|
||||||
return HTMLParser().unescape(data).strip()
|
|
||||||
return data if not isinstance(data, (str, unicode)) else data.strip().replace(u'&', u'&')
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -868,7 +851,7 @@ class Tvdb:
|
||||||
if 'filename' == k and v:
|
if 'filename' == k and v:
|
||||||
v = self.config['url_artworkPrefix'] % v
|
v = self.config['url_artworkPrefix'] % v
|
||||||
else:
|
else:
|
||||||
v = self._clean_data(v)
|
v = clean_data(v)
|
||||||
data[k] = v
|
data[k] = v
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
@ -992,7 +975,7 @@ class Tvdb:
|
||||||
if 'filename' == k:
|
if 'filename' == k:
|
||||||
v = self.config['url_artworkPrefix'] % v
|
v = self.config['url_artworkPrefix'] % v
|
||||||
else:
|
else:
|
||||||
v = self._clean_data(v)
|
v = clean_data(v)
|
||||||
|
|
||||||
if k in ep_map_keys:
|
if k in ep_map_keys:
|
||||||
k = ep_map_keys[k]
|
k = ep_map_keys[k]
|
||||||
|
|
|
@ -29,7 +29,6 @@ except ImportError:
|
||||||
|
|
||||||
from lib.dateutil.parser import parse
|
from lib.dateutil.parser import parse
|
||||||
from lib.cachecontrol import CacheControl, caches
|
from lib.cachecontrol import CacheControl, caches
|
||||||
from lib.six.moves.html_parser import HTMLParser
|
|
||||||
|
|
||||||
from lib.etreetodict import ConvertXmlToDict
|
from lib.etreetodict import ConvertXmlToDict
|
||||||
from tvdb_ui import BaseUI, ConsoleUI
|
from tvdb_ui import BaseUI, ConsoleUI
|
||||||
|
@ -37,6 +36,7 @@ from tvdb_exceptions import (tvdb_error_v1, tvdb_shownotfound_v1,
|
||||||
tvdb_seasonnotfound_v1, tvdb_episodenotfound_v1, tvdb_attributenotfound_v1)
|
tvdb_seasonnotfound_v1, tvdb_episodenotfound_v1, tvdb_attributenotfound_v1)
|
||||||
|
|
||||||
from sickbeard import logger
|
from sickbeard import logger
|
||||||
|
from sickbeard.helpers import clean_data
|
||||||
|
|
||||||
|
|
||||||
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logr=None):
|
def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logr=None):
|
||||||
|
@ -630,18 +630,6 @@ class TvdbV1:
|
||||||
self.shows[sid] = Show()
|
self.shows[sid] = Show()
|
||||||
self.shows[sid].data[key] = value
|
self.shows[sid].data[key] = value
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def _clean_data(data):
|
|
||||||
"""Cleans up strings returned by TheTVDB.com
|
|
||||||
|
|
||||||
Issues corrected:
|
|
||||||
- Replaces & with &
|
|
||||||
- Trailing whitespace
|
|
||||||
"""
|
|
||||||
if isinstance(data, basestring):
|
|
||||||
return HTMLParser().unescape(data).strip()
|
|
||||||
return data if not isinstance(data, basestring) else data.strip().replace(u'&', u'&')
|
|
||||||
|
|
||||||
def _get_url_artwork(self, image):
|
def _get_url_artwork(self, image):
|
||||||
return image and (self.config['url_artworkPrefix'] % image) or image
|
return image and (self.config['url_artworkPrefix'] % image) or image
|
||||||
|
|
||||||
|
@ -826,7 +814,7 @@ class TvdbV1:
|
||||||
if k in ['banner', 'fanart', 'poster']:
|
if k in ['banner', 'fanart', 'poster']:
|
||||||
v = self._get_url_artwork(v)
|
v = self._get_url_artwork(v)
|
||||||
else:
|
else:
|
||||||
v = self._clean_data(v)
|
v = self.clean_data(v)
|
||||||
|
|
||||||
self._set_show_data(sid, k.lower(), v)
|
self._set_show_data(sid, k.lower(), v)
|
||||||
|
|
||||||
|
@ -881,7 +869,7 @@ class TvdbV1:
|
||||||
if 'filename' == k:
|
if 'filename' == k:
|
||||||
v = self._get_url_artwork(v)
|
v = self._get_url_artwork(v)
|
||||||
else:
|
else:
|
||||||
v = self._clean_data(v)
|
v = self.clean_data(v)
|
||||||
|
|
||||||
self._set_item(sid, seas_no, ep_no, k, v)
|
self._set_item(sid, seas_no, ep_no, k, v)
|
||||||
|
|
||||||
|
|
|
@ -1778,3 +1778,22 @@ def write_file(filepath, data, raw=False, xmltree=False, utf8=False, raise_excep
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
def clean_data(data):
|
||||||
|
"""Cleans up strings, lists, dicts returned
|
||||||
|
|
||||||
|
Issues corrected:
|
||||||
|
- Replaces & with &
|
||||||
|
- Trailing whitespace
|
||||||
|
- Decode html entities
|
||||||
|
"""
|
||||||
|
|
||||||
|
if isinstance(data, list):
|
||||||
|
return [clean_data(d) for d in data]
|
||||||
|
if isinstance(data, dict):
|
||||||
|
return {k: clean_data(v) for k, v in data.iteritems()}
|
||||||
|
if isinstance(data, basestring):
|
||||||
|
from lib.six.moves.html_parser import HTMLParser
|
||||||
|
return HTMLParser().unescape(data).strip().replace(u'&', u'&')
|
||||||
|
return data
|
||||||
|
|
Loading…
Reference in a new issue