mirror of
https://github.com/SickGear/SickGear.git
synced 2024-11-15 01:15:05 +00:00
Change support languages in show search.
Add display all id links for persons. Fix ensure overview in search results are type str. Change pickle_protocol to 5 which is supported by 3.8+ Change update mock data to pickle protocol 5. Fix for if mock data files are corrupted. Change add property has_text to Images. Change set has_text from includesText data field (currently unused on API). Fix rebase errors. Change use Walrus for cache keys and get_data.
This commit is contained in:
parent
b55b29732b
commit
7c32dc12e4
5 changed files with 42 additions and 34 deletions
|
@ -186,7 +186,7 @@ def param(visible=True, rid=None, cache_person=None, cache_char=None, person=Non
|
||||||
#end if
|
#end if
|
||||||
|
|
||||||
#set $section_links = False
|
#set $section_links = False
|
||||||
#set $all_sources = $TVInfoAPI().all_sources
|
#set $all_sources = $TVInfoAPI().all_non_fallback_sources
|
||||||
#for $cur_src, $cur_sid in sorted(iteritems($person.ids))
|
#for $cur_src, $cur_sid in sorted(iteritems($person.ids))
|
||||||
#if $cur_src not in $all_sources:
|
#if $cur_src not in $all_sources:
|
||||||
#continue
|
#continue
|
||||||
|
|
|
@ -41,6 +41,7 @@ log.addHandler(logging.NullHandler())
|
||||||
|
|
||||||
TVDB_API_CONFIG = {}
|
TVDB_API_CONFIG = {}
|
||||||
|
|
||||||
|
NoneType = type(None)
|
||||||
|
|
||||||
# always use https in cases of redirects
|
# always use https in cases of redirects
|
||||||
# noinspection PyUnusedLocal,HttpUrlsUsage
|
# noinspection PyUnusedLocal,HttpUrlsUsage
|
||||||
|
@ -248,10 +249,7 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
|
|
||||||
def _get_data(self, endpoint, **kwargs):
|
def _get_data(self, endpoint, **kwargs):
|
||||||
# type: (string_types, Any) -> Any
|
# type: (string_types, Any) -> Any
|
||||||
is_series_info, retry = endpoint.startswith('/series/'), kwargs.pop('token_retry', 1)
|
if is_series_info := endpoint.startswith('/series/'):
|
||||||
if retry > 3:
|
|
||||||
raise TvdbTokenFailure('Failed to get new token')
|
|
||||||
if is_series_info:
|
|
||||||
self.show_not_found = False
|
self.show_not_found = False
|
||||||
try:
|
try:
|
||||||
return tvdb_endpoint_get(url='%s%s' % (self.base_url, endpoint), params=kwargs, parse_json=True,
|
return tvdb_endpoint_get(url='%s%s' % (self.base_url, endpoint), params=kwargs, parse_json=True,
|
||||||
|
@ -368,8 +366,7 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
"""
|
"""
|
||||||
if not p_id:
|
if not p_id:
|
||||||
return
|
return
|
||||||
cache_key_name = 'p-v4-%s' % p_id
|
is_none, people_obj = self._get_cache_entry(cache_key_name := 'p-v4-%s' % p_id)
|
||||||
is_none, people_obj = self._get_cache_entry(cache_key_name)
|
|
||||||
if None is people_obj and not is_none:
|
if None is people_obj and not is_none:
|
||||||
resp = self._get_data('/people/%s/extended' % p_id)
|
resp = self._get_data('/people/%s/extended' % p_id)
|
||||||
self._set_cache_entry(cache_key_name, resp)
|
self._set_cache_entry(cache_key_name, resp)
|
||||||
|
@ -396,8 +393,7 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
result.append(r)
|
result.append(r)
|
||||||
if tv_src in (TVINFO_IMDB, TVINFO_TMDB, TVINFO_TVMAZE):
|
if tv_src in (TVINFO_IMDB, TVINFO_TMDB, TVINFO_TVMAZE):
|
||||||
_src = tv_src
|
_src = tv_src
|
||||||
cache_id_key = 'p-v4-id-%s-%s' % (_src, ids[_src])
|
is_none, shows = self._get_cache_entry(cache_id_key := 'p-v4-id-%s-%s' % (_src, ids[_src]))
|
||||||
is_none, shows = self._get_cache_entry(cache_id_key)
|
|
||||||
d_m = None
|
d_m = None
|
||||||
if not self.config.get('cache_search') or (None is shows and not is_none):
|
if not self.config.get('cache_search') or (None is shows and not is_none):
|
||||||
try:
|
try:
|
||||||
|
@ -426,8 +422,7 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
result.extend(self._convert_person(r['people'], ids))
|
result.extend(self._convert_person(r['people'], ids))
|
||||||
break
|
break
|
||||||
if name:
|
if name:
|
||||||
cache_key_name = 'p-v4-src-text-%s' % name
|
is_none, people_objs = self._get_cache_entry(cache_key_name := 'p-v4-src-text-%s' % name)
|
||||||
is_none, people_objs = self._get_cache_entry(cache_key_name)
|
|
||||||
if None is people_objs and not is_none:
|
if None is people_objs and not is_none:
|
||||||
resp = self._get_data('/search', query=name, type='people')
|
resp = self._get_data('/search', query=name, type='people')
|
||||||
self._set_cache_entry(cache_key_name, resp)
|
self._set_cache_entry(cache_key_name, resp)
|
||||||
|
@ -496,10 +491,13 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
|
|
||||||
def _get_series_name(self, show_data, language=None):
|
def _get_series_name(self, show_data, language=None):
|
||||||
# type: (Dict, AnyStr) -> Tuple[Optional[AnyStr], List]
|
# type: (Dict, AnyStr) -> Tuple[Optional[AnyStr], List]
|
||||||
series_name = clean_data(
|
if 'nameTranslations' in show_data.get('translations', {}):
|
||||||
next(filter(lambda l: language and language == l['language'],
|
series_name = clean_data(
|
||||||
show_data.get('translations', {}).get('nameTranslations', [])),
|
next(filter(lambda l: language and language == l['language'],
|
||||||
{'name': show_data['name']})['name'])
|
show_data.get('translations', {}).get('nameTranslations', [])),
|
||||||
|
{'name': show_data['name']})['name'])
|
||||||
|
else:
|
||||||
|
series_name = clean_data(show_data.get('translations', {}).get(language, show_data['name']))
|
||||||
series_aliases = self._get_aliases(show_data)
|
series_aliases = self._get_aliases(show_data)
|
||||||
if not series_name:
|
if not series_name:
|
||||||
if isinstance(series_aliases, list) and 0 < len(series_aliases):
|
if isinstance(series_aliases, list) and 0 < len(series_aliases):
|
||||||
|
@ -627,11 +625,11 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
elif TVINFO_WIKIDATA == src_type or 'wikidata' in src_name:
|
elif TVINFO_WIKIDATA == src_type or 'wikidata' in src_name:
|
||||||
social_ids['wikidata'] = src_value
|
social_ids['wikidata'] = src_value
|
||||||
elif TVINFO_TIKTOK == src_type or 'tiktok' in src_name:
|
elif TVINFO_TIKTOK == src_type or 'tiktok' in src_name:
|
||||||
social_ids[TVINFO_TIKTOK] = src_value
|
social_ids['tiktok'] = src_value
|
||||||
elif TVINFO_LINKEDIN == src_type:
|
elif TVINFO_LINKEDIN == src_type:
|
||||||
social_ids[TVINFO_LINKEDIN] = src_value
|
social_ids['linkedin'] = src_value
|
||||||
elif TVINFO_FANSITE == src_type:
|
elif TVINFO_FANSITE == src_type:
|
||||||
social_ids[TVINFO_FANSITE] = src_value
|
social_ids['fansite'] = src_value
|
||||||
|
|
||||||
ti_show.ids = TVInfoIDs(tvdb=show_data['id'], **ids)
|
ti_show.ids = TVInfoIDs(tvdb=show_data['id'], **ids)
|
||||||
if social_ids:
|
if social_ids:
|
||||||
|
@ -657,7 +655,8 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
img_id=artwork['id'],
|
img_id=artwork['id'],
|
||||||
lang=artwork['language'],
|
lang=artwork['language'],
|
||||||
rating=artwork['score'],
|
rating=artwork['score'],
|
||||||
updated_at=artwork['updatedAt'] or None
|
updated_at=artwork['updatedAt'] or None,
|
||||||
|
has_text=enforce_type(artwork.get('includesText'), (bool, NoneType), None)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1100,7 +1099,7 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
# noinspection DuplicatedCode
|
# noinspection DuplicatedCode
|
||||||
if not self.config.get('cache_search') or (None is shows and not is_none):
|
if not self.config.get('cache_search') or (None is shows and not is_none):
|
||||||
try:
|
try:
|
||||||
d_m = self._get_show_data(ids.get(TVINFO_TVDB), self.config['language'], direct_data=True)
|
d_m = self._get_show_data(ids.get(TVINFO_TVDB), lang, direct_data=True)
|
||||||
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
||||||
except (BaseException, Exception):
|
except (BaseException, Exception):
|
||||||
d_m = None
|
d_m = None
|
||||||
|
@ -1110,12 +1109,10 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
and isinstance(d_m['data'], dict):
|
and isinstance(d_m['data'], dict):
|
||||||
results.extend(_make_result_dict(d_m['data']))
|
results.extend(_make_result_dict(d_m['data']))
|
||||||
|
|
||||||
if ids.get(TVINFO_IMDB):
|
is_none, shows = self._get_cache_entry(cache_id_key := 's-v4-id-%s-%s' % (cur_tvinfo, ids[cur_tvinfo]))
|
||||||
cache_id_key = 's-v4-id-%s-%s' % (TVINFO_IMDB, ids[TVINFO_IMDB])
|
|
||||||
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):
|
if not self.config.get('cache_search') or (None is shows and not is_none):
|
||||||
try:
|
try:
|
||||||
d_m = self._get_data('search', remote_id='tt%07d' % ids.get(TVINFO_IMDB),
|
d_m = self._get_data('search?meta=translations', remote_id='tt%07d' % ids.get(TVINFO_IMDB),
|
||||||
query='tt%07d' % ids.get(TVINFO_IMDB), type='series')
|
query='tt%07d' % ids.get(TVINFO_IMDB), type='series')
|
||||||
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
||||||
except (BaseException, Exception):
|
except (BaseException, Exception):
|
||||||
|
@ -1139,7 +1136,7 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
is_none, shows = self._get_cache_entry(cache_id_key)
|
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):
|
if not self.config.get('cache_search') or (None is shows and not is_none):
|
||||||
try:
|
try:
|
||||||
d_m = self._get_data('search', remote_id='%s' % ids.get(TVINFO_TMDB),
|
d_m = self._get_data('search?meta=translations', remote_id='%s' % ids.get(TVINFO_TMDB),
|
||||||
query='%s' % ids.get(TVINFO_TMDB), type='series')
|
query='%s' % ids.get(TVINFO_TMDB), type='series')
|
||||||
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
||||||
except (BaseException, Exception):
|
except (BaseException, Exception):
|
||||||
|
@ -1163,7 +1160,7 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
is_none, shows = self._get_cache_entry(cache_id_key)
|
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):
|
if not self.config.get('cache_search') or (None is shows and not is_none):
|
||||||
try:
|
try:
|
||||||
d_m = self._get_data('search', remote_id='%s' % ids.get(TVINFO_TVMAZE),
|
d_m = self._get_data('search?meta=translations', remote_id='%s' % ids.get(TVINFO_TVMAZE),
|
||||||
query='%s' % ids.get(TVINFO_TVMAZE), type='series')
|
query='%s' % ids.get(TVINFO_TVMAZE), type='series')
|
||||||
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
||||||
except (BaseException, Exception):
|
except (BaseException, Exception):
|
||||||
|
@ -1183,11 +1180,11 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if ids.get(TVINFO_TVDB_SLUG) and isinstance(ids.get(TVINFO_TVDB_SLUG), string_types):
|
if ids.get(TVINFO_TVDB_SLUG) and isinstance(ids.get(TVINFO_TVDB_SLUG), string_types):
|
||||||
cache_id_key = 's-id-%s-%s' % (TVINFO_TVDB, ids[TVINFO_TVDB_SLUG])
|
is_none, shows = self._get_cache_entry(cache_id_key :=
|
||||||
is_none, shows = self._get_cache_entry(cache_id_key)
|
's-id-%s-%s' % (TVINFO_TVDB, ids[TVINFO_TVDB_SLUG]))
|
||||||
if not self.config.get('cache_search') or (None is shows and not is_none):
|
if not self.config.get('cache_search') or (None is shows and not is_none):
|
||||||
try:
|
try:
|
||||||
d_m = self._get_data('/series/slug/%s' % ids.get(TVINFO_TVDB_SLUG))
|
d_m = self._get_data('/series/slug/%s?meta=translations' % ids.get(TVINFO_TVDB_SLUG))
|
||||||
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
self._set_cache_entry(cache_id_key, d_m, expire=self.search_cache_expire)
|
||||||
except (BaseException, Exception):
|
except (BaseException, Exception):
|
||||||
d_m = None
|
d_m = None
|
||||||
|
@ -1202,7 +1199,7 @@ class TvdbAPIv4(TVInfoBase):
|
||||||
cache_name_key = 's-v4-name-%s' % n
|
cache_name_key = 's-v4-name-%s' % n
|
||||||
is_none, shows = self._get_cache_entry(cache_name_key)
|
is_none, shows = self._get_cache_entry(cache_name_key)
|
||||||
if not self.config.get('cache_search') or (None is shows and not is_none):
|
if not self.config.get('cache_search') or (None is shows and not is_none):
|
||||||
resp = self._get_data('search', query=n, type='series')
|
resp = self._get_data('search?meta=translations', query=n, type='series')
|
||||||
self._set_cache_entry(cache_name_key, resp, expire=self.search_cache_expire)
|
self._set_cache_entry(cache_name_key, resp, expire=self.search_cache_expire)
|
||||||
else:
|
else:
|
||||||
resp = shows
|
resp = shows
|
||||||
|
|
|
@ -329,7 +329,7 @@ class TVInfoImageSize(object):
|
||||||
|
|
||||||
class TVInfoImage(object):
|
class TVInfoImage(object):
|
||||||
def __init__(self, image_type, sizes, img_id=None, main_image=False, type_str='', rating=None, votes=None,
|
def __init__(self, image_type, sizes, img_id=None, main_image=False, type_str='', rating=None, votes=None,
|
||||||
lang=None, height=None, width=None, aspect_ratio=None, updated_at=None):
|
lang=None, height=None, width=None, aspect_ratio=None, updated_at=None, has_text=None):
|
||||||
self.img_id = img_id # type: Optional[integer_types]
|
self.img_id = img_id # type: Optional[integer_types]
|
||||||
self.image_type = image_type # type: integer_types
|
self.image_type = image_type # type: integer_types
|
||||||
self.sizes = sizes # type: Union[TVInfoImageSize, Dict]
|
self.sizes = sizes # type: Union[TVInfoImageSize, Dict]
|
||||||
|
@ -341,6 +341,7 @@ class TVInfoImage(object):
|
||||||
self.height = height # type: Optional[integer_types]
|
self.height = height # type: Optional[integer_types]
|
||||||
self.width = width # type: Optional[integer_types]
|
self.width = width # type: Optional[integer_types]
|
||||||
self.aspect_ratio = aspect_ratio # type: Optional[Union[float, integer_types]]
|
self.aspect_ratio = aspect_ratio # type: Optional[Union[float, integer_types]]
|
||||||
|
self.has_text = has_text # type: Optional[bool]
|
||||||
self.updated_at = updated_at # type: Optional[integer_types]
|
self.updated_at = updated_at # type: Optional[integer_types]
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
|
@ -1370,7 +1371,7 @@ class TVInfoBase(object):
|
||||||
if None is lang:
|
if None is lang:
|
||||||
if self.config.get('language'):
|
if self.config.get('language'):
|
||||||
lang = self.config['language']
|
lang = self.config['language']
|
||||||
lang = self.map_languages.get(lang, lang)
|
lang = self.map_languages.get(lang, lang)
|
||||||
if not name and not ids:
|
if not name and not ids:
|
||||||
log.debug('Nothing to search')
|
log.debug('Nothing to search')
|
||||||
raise BaseTVinfoShownotfound('Nothing to search')
|
raise BaseTVinfoShownotfound('Nothing to search')
|
||||||
|
|
|
@ -100,11 +100,19 @@ class TVInfoAPI(object):
|
||||||
def all_sources(self):
|
def all_sources(self):
|
||||||
# type: () -> Dict[int, AnyStr]
|
# type: () -> Dict[int, AnyStr]
|
||||||
"""
|
"""
|
||||||
:return: return all indexers including mapped only indexers excluding fallback indexers
|
:return: return all indexers for show data including mapped only indexers excluding fallback indexers
|
||||||
"""
|
"""
|
||||||
return self._filter(lambda x:
|
return self._filter(lambda x:
|
||||||
True is not x.get('fallback') and True is not x.get('people_only'))
|
True is not x.get('fallback') and True is not x.get('people_only'))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def all_non_fallback_sources(self):
|
||||||
|
# type: (...) -> Dict[int, AnyStr]
|
||||||
|
"""
|
||||||
|
return all sources with the exclusion of fallback indexer
|
||||||
|
"""
|
||||||
|
return self._filter(lambda x: True is not x.get('fallback'))
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def fallback_sources(self):
|
def fallback_sources(self):
|
||||||
# type: () -> Dict[int, AnyStr]
|
# type: () -> Dict[int, AnyStr]
|
||||||
|
|
|
@ -52,7 +52,7 @@ only_new_urls_data_creation = True
|
||||||
delete_unused_mock_files = False
|
delete_unused_mock_files = False
|
||||||
|
|
||||||
# other settings
|
# other settings
|
||||||
pickle_protocol = 3 # needed for python 3.7 compatibility
|
pickle_protocol = 5 # needed for python 3.8 compatibility
|
||||||
used_files = {'browse_start_date.data'}
|
used_files = {'browse_start_date.data'}
|
||||||
|
|
||||||
|
|
||||||
|
@ -153,6 +153,8 @@ def _load_pickle_file(f_name):
|
||||||
try:
|
try:
|
||||||
with lzma.open(full_filename, 'rb') as f:
|
with lzma.open(full_filename, 'rb') as f:
|
||||||
return pickle.load(f)
|
return pickle.load(f)
|
||||||
|
except (BaseException, Exception):
|
||||||
|
return
|
||||||
finally:
|
finally:
|
||||||
datetime.date = _FakeDate
|
datetime.date = _FakeDate
|
||||||
datetime.datetime = _FakeDateTime
|
datetime.datetime = _FakeDateTime
|
||||||
|
|
Loading…
Reference in a new issue