From dc4cd6e2a6f20c5ee55bb23be7b3cf595d95ca52 Mon Sep 17 00:00:00 2001 From: JackDandy Date: Sat, 1 Sep 2018 02:10:44 +0100 Subject: [PATCH] Fix issue with tvdb response data. Change move data cleaner to helpers. --- CHANGES.md | 7 +++++- lib/libtrakt/indexerapiinterface.py | 16 ++------------ lib/tvdb_api/tvdb_api.py | 33 +++++++---------------------- lib/tvdb_api_v1/tvdb_api.py | 18 +++------------- sickbeard/helpers.py | 19 +++++++++++++++++ 5 files changed, 38 insertions(+), 55 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 931f3bd9..99b4a602 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/lib/libtrakt/indexerapiinterface.py b/lib/libtrakt/indexerapiinterface.py index 4c98cb90..76198b94 100644 --- a/lib/libtrakt/indexerapiinterface.py +++ b/lib/libtrakt/indexerapiinterface.py @@ -125,19 +125,6 @@ class TraktIndexer: def __repr__(self): 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 def _dict_prevent_none(d, key, default): v = None @@ -156,12 +143,13 @@ class TraktIndexer: if None is not self.config['sleep_retry']: kwargs['sleep_retry'] = self.config['sleep_retry'] try: + from sickbeard.helpers import clean_data resp = TraktAPI().trakt_request(url, **kwargs) if len(resp): for d in resp: if isinstance(d, dict) and 'type' in d and d['type'] in self.config['result_types']: 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']: d.update(d['show']) del d['show'] diff --git a/lib/tvdb_api/tvdb_api.py b/lib/tvdb_api/tvdb_api.py index 1e5f31d4..4b9690d2 100644 --- a/lib/tvdb_api/tvdb_api.py +++ b/lib/tvdb_api/tvdb_api.py @@ -22,11 +22,9 @@ import requests.exceptions import datetime import re -from sickbeard.helpers import getURL, tryInt +from sickbeard.helpers import getURL, tryInt, clean_data import sickbeard -from lib.six.moves.html_parser import HTMLParser - from lib.dateutil.parser import parse from lib.cachecontrol import CacheControl, caches @@ -627,13 +625,13 @@ class Tvdb: v = self.config['url_artworkPrefix'] % v elif 'genre' == k: 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: 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: 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: if v: try: @@ -645,11 +643,11 @@ class Tvdb: elif 'imdbid' == k: if v: if re.search(r'^(tt)?\d{1,7}$', v, flags=re.I): - v = self._clean_data(v) + v = clean_data(v) else: v = '' else: - v = self._clean_data(v) + v = clean_data(v) if k in map_show: k = map_show[k] if k_org is not k: @@ -728,21 +726,6 @@ class Tvdb: else: 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): """This searches TheTVDB.com for the series name and returns the result list @@ -868,7 +851,7 @@ class Tvdb: if 'filename' == k and v: v = self.config['url_artworkPrefix'] % v else: - v = self._clean_data(v) + v = clean_data(v) data[k] = v return data @@ -992,7 +975,7 @@ class Tvdb: if 'filename' == k: v = self.config['url_artworkPrefix'] % v else: - v = self._clean_data(v) + v = clean_data(v) if k in ep_map_keys: k = ep_map_keys[k] diff --git a/lib/tvdb_api_v1/tvdb_api.py b/lib/tvdb_api_v1/tvdb_api.py index 5057a769..32e0c49b 100644 --- a/lib/tvdb_api_v1/tvdb_api.py +++ b/lib/tvdb_api_v1/tvdb_api.py @@ -29,7 +29,6 @@ except ImportError: from lib.dateutil.parser import parse from lib.cachecontrol import CacheControl, caches -from lib.six.moves.html_parser import HTMLParser from lib.etreetodict import ConvertXmlToDict 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) from sickbeard import logger +from sickbeard.helpers import clean_data def retry(ExceptionToCheck, tries=4, delay=3, backoff=2, logr=None): @@ -630,18 +630,6 @@ class TvdbV1: self.shows[sid] = Show() 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): return image and (self.config['url_artworkPrefix'] % image) or image @@ -826,7 +814,7 @@ class TvdbV1: if k in ['banner', 'fanart', 'poster']: v = self._get_url_artwork(v) else: - v = self._clean_data(v) + v = self.clean_data(v) self._set_show_data(sid, k.lower(), v) @@ -881,7 +869,7 @@ class TvdbV1: if 'filename' == k: v = self._get_url_artwork(v) else: - v = self._clean_data(v) + v = self.clean_data(v) self._set_item(sid, seas_no, ep_no, k, v) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index 375fa402..2ff81260 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1778,3 +1778,22 @@ def write_file(filepath, data, raw=False, xmltree=False, utf8=False, raise_excep raise e 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