diff --git a/lib/imdb_api/imdb_api.py b/lib/imdb_api/imdb_api.py index 8c86514..52f45c4 100644 --- a/lib/imdb_api/imdb_api.py +++ b/lib/imdb_api/imdb_api.py @@ -80,7 +80,7 @@ class IMDbIndexer(TVInfoBase): is_none, shows = self._get_cache_entry(cache_id_key) if not self.config.get('cache_search') or (None is shows and not is_none): try: - show = imdbpie.Imdb().get_title_auxiliary('tt%07d' % p) + show = imdbpie.Imdb().get_title_auxiliary('tt%08d' % p) except (BaseException, Exception): continue self._set_cache_entry(cache_id_key, show, expire=self.search_cache_expire) diff --git a/lib/libtrakt/indexerapiinterface.py b/lib/libtrakt/indexerapiinterface.py index b854131..1132356 100644 --- a/lib/libtrakt/indexerapiinterface.py +++ b/lib/libtrakt/indexerapiinterface.py @@ -185,7 +185,7 @@ class TraktIndexer(TVInfoBase): if TraktSearchTypes.trakt_slug == search_type: url = '/shows/%s?extended=full' % series elif TraktSearchTypes.text != search_type: - url = '/search/%s/%s?type=%s&extended=full&limit=100' % (search_type, (series, 'tt%07d' % series)[ + url = '/search/%s/%s?type=%s&extended=full&limit=100' % (search_type, (series, 'tt%08d' % series)[ TraktSearchTypes.imdb_id == search_type and not str(series).startswith('tt')], ','.join(self.config['result_types'])) else: diff --git a/lib/tmdb_api/tmdb_api.py b/lib/tmdb_api/tmdb_api.py index ec7b78f..635ce80 100644 --- a/lib/tmdb_api/tmdb_api.py +++ b/lib/tmdb_api/tmdb_api.py @@ -210,7 +210,7 @@ class TmdbIndexer(TVInfoBase): is_none, shows = self._get_cache_entry(cache_id_key) if not self.config.get('cache_search') or (None is shows and not is_none): try: - show = tmdbsimple.Find(id=(p, 'tt%07d' % p)[t == TVINFO_IMDB]).info( + show = tmdbsimple.Find(id=(p, 'tt%08d' % p)[t == TVINFO_IMDB]).info( external_source=id_map[t]) if show.get('tv_results') and 1 == len(show['tv_results']): show = tmdbsimple.TV(id=show['tv_results'][0]['id']).info( diff --git a/lib/tvmaze_api/tvmaze_api.py b/lib/tvmaze_api/tvmaze_api.py index 59b579c..3ddab81 100644 --- a/lib/tvmaze_api/tvmaze_api.py +++ b/lib/tvmaze_api/tvmaze_api.py @@ -14,7 +14,7 @@ import requests from urllib3.util.retry import Retry from requests.adapters import HTTPAdapter -from six import iteritems +from six import integer_types, iteritems from sg_helpers import get_url, try_int from lib.dateutil.parser import parser # noinspection PyProtectedMember @@ -29,7 +29,6 @@ from lib.pytvmaze import tvmaze # noinspection PyUnreachableCode if False: from typing import Any, AnyStr, Dict, List, Optional - from six import integer_types from lib.pytvmaze.tvmaze import Episode as TVMazeEpisode, Show as TVMazeShow log = logging.getLogger('tvmaze.api') @@ -167,7 +166,7 @@ class TvMaze(TVInfoBase): elif t == TVINFO_IMDB: if not self.config.get('cache_search') or (None is shows and not is_none): try: - show = tvmaze.lookup_imdb((p, 'tt%07d' % p)[not str(p).startswith('tt')]) + show = tvmaze.lookup_imdb((p, 'tt%08d' % p)[not str(p).startswith('tt')]) self._set_cache_entry(cache_id_key, show, expire=self.search_cache_expire) except (BaseException, Exception): continue @@ -564,94 +563,97 @@ class TvMaze(TVInfoBase): """ make out of TVMazeEpisode object and optionally TVMazeShow a TVInfoEpisode """ - tv_s = TVInfoShow() - tv_s.seriesname = show_data.name - tv_s.id = show_data.maze_id - tv_s.seriesid = tv_s.id - tv_s.language = show_data.language - tv_s.overview = show_data.summary - tv_s.firstaired = show_data.premiered - tv_s.runtime = show_data.average_runtime or show_data.runtime - tv_s.vote_average = show_data.rating and show_data.rating.get('average') - tv_s.popularity = show_data.weight - tv_s.genre_list = show_data.genres or [] - tv_s.genre = ', '.join(tv_s.genre_list) - tv_s.official_site = show_data.official_site - tv_s.status = show_data.status - tv_s.show_type = show_data.type - tv_s.lastupdated = show_data.updated - tv_s.poster = show_data.image and show_data.image.get('original') - tv_s.aliases = [a.name for a in show_data.akas] + ti_show = TVInfoShow() + ti_show.seriesname = show_data.name + ti_show.id = show_data.maze_id + ti_show.seriesid = ti_show.id + ti_show.language = show_data.language + ti_show.overview = show_data.summary + ti_show.firstaired = show_data.premiered + ti_show.runtime = show_data.average_runtime or show_data.runtime + ti_show.vote_average = show_data.rating and show_data.rating.get('average') + ti_show.popularity = show_data.weight + ti_show.genre_list = show_data.genres or [] + ti_show.genre = ', '.join(ti_show.genre_list) + ti_show.official_site = show_data.official_site + ti_show.status = show_data.status + ti_show.show_type = show_data.type + ti_show.lastupdated = show_data.updated + ti_show.poster = show_data.image and show_data.image.get('original') + ti_show.aliases = [a.name for a in show_data.akas] if 'days' in show_data.schedule: - tv_s.airs_dayofweek = ', '.join(show_data.schedule['days']) + ti_show.airs_dayofweek = ', '.join(show_data.schedule['days']) network = show_data.network or show_data.web_channel if network: - tv_s.network_is_stream = None is not show_data.web_channel - tv_s.network = network.name - tv_s.network_id = network.maze_id - tv_s.network_country = network.country - tv_s.network_country_code = network.code - tv_s.network_timezone = network.timezone + ti_show.network_is_stream = None is not show_data.web_channel + ti_show.network = network.name + ti_show.network_id = network.maze_id + ti_show.network_country = network.country + ti_show.network_country_code = network.code + ti_show.network_timezone = network.timezone if get_images and show_data.images: b_set, f_set, p_set = False, False, False - for img in show_data.images: - img_type = img_type_map.get(img.type, TVInfoImageType.other) - img_width, img_height = img.resolutions['original'].get('width'), \ - img.resolutions['original'].get('height') + for cur_img in show_data.images: + img_type = img_type_map.get(cur_img.type, TVInfoImageType.other) + img_width, img_height = cur_img.resolutions['original'].get('width'), \ + cur_img.resolutions['original'].get('height') img_ar = img_width and img_height and float(img_width) / float(img_height) img_ar_type = self._which_type(img_width, img_ar) if TVInfoImageType.poster == img_type and img_ar and img_ar_type != img_type and \ - tv_s.poster == img.resolutions.get('original')['url']: + ti_show.poster == cur_img.resolutions.get('original')['url']: p_set = False - tv_s.poster = None - tv_s.poster_thumb = None + ti_show.poster = None + ti_show.poster_thumb = None img_type = (TVInfoImageType.other, img_type)[ not img_ar or img_ar_type == img_type or img_type not in (TVInfoImageType.banner, TVInfoImageType.poster, TVInfoImageType.fanart)] img_src = {} - for res, img_url in iteritems(img.resolutions): - img_size = img_size_map.get(res) + for cur_res, cur_img_url in iteritems(cur_img.resolutions): + img_size = img_size_map.get(cur_res) if img_size: - img_src[img_size] = img_url.get('url') - tv_s.images.setdefault(img_type, []).append( + img_src[img_size] = cur_img_url.get('url') + ti_show.images.setdefault(img_type, []).append( TVInfoImage( - image_type=img_type, sizes=img_src, img_id=img.id, main_image=img.main, - type_str=img.type, width=img_width, height=img_height, aspect_ratio=img_ar)) + image_type=img_type, sizes=img_src, img_id=cur_img.id, main_image=cur_img.main, + type_str=cur_img.type, width=img_width, height=img_height, aspect_ratio=img_ar)) if not p_set and TVInfoImageType.poster == img_type: p_set = True - tv_s.poster = img.resolutions.get('original')['url'] - tv_s.poster_thumb = img.resolutions.get('original')['url'] - elif not b_set and 'banner' == img.type and TVInfoImageType.banner == img_type: + ti_show.poster = cur_img.resolutions.get('original')['url'] + ti_show.poster_thumb = cur_img.resolutions.get('original')['url'] + elif not b_set and 'banner' == cur_img.type and TVInfoImageType.banner == img_type: b_set = True - tv_s.banner = img.resolutions.get('original')['url'] - tv_s.banner_thumb = img.resolutions.get('medium')['url'] - elif not f_set and 'background' == img.type and TVInfoImageType.fanart == img_type: + ti_show.banner = cur_img.resolutions.get('original')['url'] + ti_show.banner_thumb = cur_img.resolutions.get('medium')['url'] + elif not f_set and 'background' == cur_img.type and TVInfoImageType.fanart == img_type: f_set = True - tv_s.fanart = img.resolutions.get('original')['url'] - tv_s.ids = TVInfoIDs( + ti_show.fanart = cur_img.resolutions.get('original')['url'] + ti_show.ids = TVInfoIDs( tvdb=show_data.externals.get('thetvdb'), rage=show_data.externals.get('tvrage'), tvmaze=show_data.id, imdb=show_data.externals.get('imdb') and try_int(show_data.externals.get('imdb').replace('tt', ''), None)) - tv_s.imdb_id = show_data.externals.get('imdb') and try_int(show_data.externals.get('imdb').replace('tt', '')) - ep_obj = TVInfoEpisode() - ep_obj.id = episode_data.maze_id - ep_obj.seasonnumber = episode_data.season_number - ep_obj.episodenumber = episode_data.episode_number - ep_obj.episodename = episode_data.title - ep_obj.airtime = episode_data.airtime - ep_obj.firstaired = episode_data.airdate + ti_show.imdb_id = show_data.externals.get('imdb') + if isinstance(ti_show.imdb_id, integer_types): + ti_show.imdb_id = 'tt%08d' % ti_show.imdb_id + + ti_episode = TVInfoEpisode() + ti_episode.id = episode_data.maze_id + ti_episode.seasonnumber = episode_data.season_number + ti_episode.episodenumber = episode_data.episode_number + ti_episode.episodename = episode_data.title + ti_episode.airtime = episode_data.airtime + ti_episode.firstaired = episode_data.airdate if episode_data.airstamp: try: at = _datetime_to_timestamp(tz_p.parse(episode_data.airstamp)) - ep_obj.timestamp = at + ti_episode.timestamp = at except (BaseException, Exception): pass - ep_obj.filename = episode_data.image and (episode_data.image.get('original') or - episode_data.image.get('medium')) - ep_obj.is_special = episode_data.is_special() - ep_obj.overview = episode_data.summary - ep_obj.runtime = episode_data.runtime - ep_obj.show = tv_s - return ep_obj + ti_episode.filename = episode_data.image and (episode_data.image.get('original') or + episode_data.image.get('medium')) + ti_episode.is_special = episode_data.is_special() + ti_episode.overview = episode_data.summary + ti_episode.runtime = episode_data.runtime + ti_episode.show = ti_show + return ti_episode def _filtered_schedule(self, condition, get_images=False): try: @@ -660,5 +662,5 @@ class TvMaze(TVInfoBase): if condition(e) and (None is e.show.language or re.search('(?i)eng|jap', e.show.language))], key=lambda x: x.show.premiered or x.airstamp) return [self._make_episode(r, r.show, get_images) for r in result] - except(BaseException, Exception) as e: + except(BaseException, Exception): return [] diff --git a/sickbeard/indexers/indexer_config.py b/sickbeard/indexers/indexer_config.py index d55d83b..1aa4ad3 100644 --- a/sickbeard/indexers/indexer_config.py +++ b/sickbeard/indexers/indexer_config.py @@ -176,7 +176,7 @@ tvinfo_config[src].update(dict( src = TVINFO_IMDB tvinfo_config[src].update(dict( base_url=tvinfo_config[src]['main_url'], - show_url='%stitle/tt%%07d' % tvinfo_config[src]['main_url'], + show_url='%stitle/tt%%08d' % tvinfo_config[src]['main_url'], finder='%sfind?q=%s&s=tt&ttype=tv&ref_=fn_tv' % (tvinfo_config[src]['main_url'], '%s'), )) diff --git a/sickbeard/tv.py b/sickbeard/tv.py index e787a69..492093b 100644 --- a/sickbeard/tv.py +++ b/sickbeard/tv.py @@ -2757,7 +2757,7 @@ class TVShow(TVShowBase): old_imdb = self.imdbid if show_info.ids.imdb: - self.imdbid = 'tt%07d' % show_info.ids.imdb + self.imdbid = 'tt%08d' % show_info.ids.imdb else: self.imdbid = self.dict_prevent_nonetype(show_info, 'imdb_id') if old_imdb != self.imdbid: @@ -2977,7 +2977,7 @@ class TVShow(TVShowBase): if not self._imdbid and 0 >= self.ids.get(indexermapper.TVINFO_IMDB, {'id': 0}).get('id', 0): return - imdb_info = {'imdb_id': self._imdbid or 'tt%07d' % self.ids[indexermapper.TVINFO_IMDB]['id'], + imdb_info = {'imdb_id': self._imdbid or 'tt%08d' % self.ids[indexermapper.TVINFO_IMDB]['id'], 'title': '', 'year': '', 'akas': '', @@ -2995,7 +2995,7 @@ class TVShow(TVShowBase): imdb_id = None imdb_certificates = None try: - imdb_id = str(self._imdbid or 'tt%07d' % self.ids[indexermapper.TVINFO_IMDB]['id']) + imdb_id = str(self._imdbid or 'tt%08d' % self.ids[indexermapper.TVINFO_IMDB]['id']) redirect_check = self.check_imdb_redirect(imdb_id) if redirect_check: self._imdbid = redirect_check @@ -3016,15 +3016,15 @@ class TVShow(TVShowBase): }) imdb_certificates = i.get_title_certificates(imdb_id=imdb_id) except LookupError as e: - if 'Title was an episode' in ex(e) and imdb_id == 'tt%07d' % self.ids[indexermapper.TVINFO_IMDB]['id']: + if 'Title was an episode' in ex(e) and imdb_id == 'tt%08d' % self.ids[indexermapper.TVINFO_IMDB]['id']: self.ids[indexermapper.TVINFO_IMDB]['id'] = 0 self.ids[indexermapper.TVINFO_IMDB]['status'] = MapStatus.NOT_FOUND if datetime.date.today() != self.ids[indexermapper.TVINFO_IMDB]['date']: indexermapper.map_indexers_to_show(self, force=True) - if not retry and imdb_id != 'tt%07d' % self.ids[indexermapper.TVINFO_IMDB]['id']: + if not retry and imdb_id != 'tt%08d' % self.ids[indexermapper.TVINFO_IMDB]['id']: # add retry arg to prevent endless loops logger.log('imdbid: %s not found. retrying with newly found id: %s' % - (imdb_id, 'tt%07d' % self.ids[indexermapper.TVINFO_IMDB]['id']), logger.DEBUG) + (imdb_id, 'tt%08d' % self.ids[indexermapper.TVINFO_IMDB]['id']), logger.DEBUG) self._get_imdb_info(retry=True) return logger.log('imdbid: %s not found. Error: %s' % (imdb_id, ex(e)), logger.WARNING) diff --git a/sickbeard/webserve.py b/sickbeard/webserve.py index 16d0f21..526b4bf 100644 --- a/sickbeard/webserve.py +++ b/sickbeard/webserve.py @@ -5191,8 +5191,9 @@ class AddShows(Home): # noinspection PyProtectedMember from lib.dateutil.tz.tz import _datetime_to_timestamp - if (int(_datetime_to_timestamp(datetime.datetime.now())) - < sickbeard.MEMCACHE.get(mem_key, {}).get('last_update', 0)): + now = int(_datetime_to_timestamp(datetime.datetime.now())) + if (sickbeard.MEMCACHE.get(mem_key, {}).get('data') + and (now < sickbeard.MEMCACHE.get(mem_key, {}).get('expire', 0))): return sickbeard.MEMCACHE.get(mem_key).get('data') tvinfo_config = sickbeard.TVInfoAPI(TVINFO_TVMAZE).api_params.copy() @@ -5201,8 +5202,7 @@ class AddShows(Home): data = t.get_premieres() else: data = t.get_returning() - sickbeard.MEMCACHE[mem_key] = dict( - last_update=(30*60) + int(_datetime_to_timestamp(datetime.datetime.now())), data=data) + sickbeard.MEMCACHE[mem_key] = dict(expire=(30*60) + now, data=data) return data if 'New' in browse_title: @@ -5263,13 +5263,10 @@ class AddShows(Home): ids = dict(tvmaze=cur_episode_info.id) imdb_id = cur_episode_info.show.imdb_id if imdb_id: - if isinstance(imdb_id, string_types) and 'tt' in imdb_id: - ids.update(dict(imdb=imdb_id)) - elif isinstance(imdb_id, integer_types): - ids.update(dict(imdb='tt%08d' % imdb_id)) + ids['imdb'] = imdb_id tvdb_id = cur_episode_info.show.ids.get(TVINFO_TVDB) if tvdb_id: - ids.update(dict(tvdb=tvdb_id)) + ids['tvdb'] = tvdb_id network_name = cur_episode_info.show.network cc = 'US'