From 97a1693abfaa998e4e019cf0fffc787f6c8a1110 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 7 Jun 2014 17:43:58 -0700 Subject: [PATCH] Fixes for TVDB and TVRage API search issues. --- lib/tvdb_api/tvdb_api.py | 12 ++++++++++-- lib/tvrage_api/tvrage_api.py | 17 ++++++++++++----- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/tvdb_api/tvdb_api.py b/lib/tvdb_api/tvdb_api.py index 0edd1ca0..eedf5610 100644 --- a/lib/tvdb_api/tvdb_api.py +++ b/lib/tvdb_api/tvdb_api.py @@ -602,7 +602,11 @@ class Tvdb: except zipfile.BadZipfile: raise tvdb_error("Bad zip file received from thetvdb.com, could not read it") else: - return xmltodict.parse(resp.content.strip().encode('utf-8'), postprocessor=process) + try: + return xmltodict.parse(resp.content.strip().encode('utf-8'), postprocessor=process) + except: + return xmltodict.parse(resp.content.strip(), postprocessor=process) + def _getetsrc(self, url, params=None, language=None): """Loads a URL using caching, returns an ElementTree of the source @@ -855,7 +859,11 @@ class Tvdb: epsEt = self._getetsrc(url, language=language) - for cur_ep in epsEt["episode"]: + episodes = epsEt["episode"] + if not isinstance(episodes, list): + episodes = [episodes] + + for cur_ep in episodes: if self.config['dvdorder']: log().debug('Using DVD ordering.') use_dvd = cur_ep['dvd_season'] != None and cur_ep['dvd_episodenumber'] != None diff --git a/lib/tvrage_api/tvrage_api.py b/lib/tvrage_api/tvrage_api.py index 4d47e088..e1661627 100644 --- a/lib/tvrage_api/tvrage_api.py +++ b/lib/tvrage_api/tvrage_api.py @@ -390,7 +390,7 @@ class TVRage: return os.path.join(tempfile.gettempdir(), "tvrage_api-%s" % (uid)) - @retry(tvrage_error) + #@retry(tvrage_error) def _loadUrl(self, url, params=None): try: log().debug("Retrieving URL %s" % url) @@ -462,7 +462,10 @@ class TVRage: return (key, value) if resp.ok: - return xmltodict.parse(resp.content.strip().encode('utf-8'), postprocessor=remap_keys) + try: + return xmltodict.parse(resp.content.strip().encode('utf-8'), postprocessor=remap_keys) + except: + return xmltodict.parse(resp.content.strip(), postprocessor=remap_keys) def _getetsrc(self, url, params=None): """Loads a URL using caching, returns an ElementTree of the source @@ -598,13 +601,17 @@ class TVRage: self.config['params_epInfo']['sid'] = sid epsEt = self._getetsrc(self.config['url_epInfo'], self.config['params_epInfo']) - for season in epsEt['episodelist'].values(): - episodes = season['episode'] + 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: - seas_no = int(season['@no']) ep_no = int(episode['episodenumber']) self._setItem(sid, seas_no, ep_no, 'seasonnumber', seas_no)