mirror of
https://github.com/SickGear/SickGear.git
synced 2024-12-18 08:43:37 +00:00
Add language support.
Add new get_languages TVInfo Interface method that returns a list of dicts by the indexer supported languages and the sg_lang map code [{'id': 'lang code', 'name': 'english name', 'nativeName': 'native name', 'sg_lang': 'sg lang code'}]. Add all returned languages to webserve method. Use new interface parameter language for get_show.
This commit is contained in:
parent
7acddd88b2
commit
0fbf88651d
6 changed files with 85 additions and 23 deletions
|
@ -11,7 +11,7 @@ __author__ = 'dbr/Ben'
|
|||
__version__ = '1.9'
|
||||
|
||||
__all__ = ['TvdbException', 'TvdbError', 'TvdbUserabort', 'TvdbShownotfound',
|
||||
'TvdbSeasonnotfound', 'TvdbEpisodenotfound', 'TvdbAttributenotfound', 'TvdbTokenexpired']
|
||||
'TvdbSeasonnotfound', 'TvdbEpisodenotfound', 'TvdbAttributenotfound', 'TvdbTokenexpired', 'TvdbTokenFailre']
|
||||
|
||||
from lib.tvinfo_base.exceptions import *
|
||||
|
||||
|
@ -64,3 +64,10 @@ class TvdbTokenexpired(BaseTVinfoAuthenticationerror, TvdbError):
|
|||
"""token expired or missing thetvdb.com
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class TvdbTokenFailre(BaseTVinfoAuthenticationerror, TvdbError):
|
||||
"""getting token failed
|
||||
"""
|
||||
pass
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ TVINFO_TWITTER = 250000
|
|||
TVINFO_FACEBOOK = 250001
|
||||
TVINFO_INSTAGRAM = 250002
|
||||
TVINFO_WIKIPEDIA = 250003
|
||||
TVINFO_REDDIT = 250004
|
||||
TVINFO_YOUTUBE = 250005
|
||||
|
||||
tv_src_names = {
|
||||
TVINFO_TVDB: 'tvdb',
|
||||
|
@ -60,7 +62,9 @@ tv_src_names = {
|
|||
TVINFO_TWITTER: 'twitter',
|
||||
TVINFO_FACEBOOK: 'facebook',
|
||||
TVINFO_INSTAGRAM: 'instagram',
|
||||
TVINFO_WIKIPEDIA: 'wikipedia'
|
||||
TVINFO_WIKIPEDIA: 'wikipedia',
|
||||
TVINFO_REDDIT: 'reddit',
|
||||
TVINFO_YOUTUBE: 'youtube'
|
||||
|
||||
}
|
||||
|
||||
|
@ -154,21 +158,25 @@ class TVInfoIDs(object):
|
|||
|
||||
|
||||
class TVInfoSocialIDs(object):
|
||||
def __init__(self, twitter=None, instagram=None, facebook=None, wikipedia=None, ids=None):
|
||||
# type: (str_int, str_int, str_int, str_int, Dict[int, str_int]) -> None
|
||||
def __init__(self, twitter=None, instagram=None, facebook=None, wikipedia=None, ids=None, reddit=None,
|
||||
youtube=None):
|
||||
# type: (str_int, str_int, str_int, str_int, Dict[int, str_int], str_int, str) -> None
|
||||
ids = ids or {}
|
||||
self.twitter = twitter or ids.get(TVINFO_TWITTER)
|
||||
self.instagram = instagram or ids.get(TVINFO_INSTAGRAM)
|
||||
self.facebook = facebook or ids.get(TVINFO_FACEBOOK)
|
||||
self.wikipedia = wikipedia or ids.get(TVINFO_WIKIPEDIA)
|
||||
self.reddit = reddit or ids.get(TVINFO_REDDIT)
|
||||
self.youtube = youtube or ids.get(TVINFO_YOUTUBE)
|
||||
|
||||
def __getitem__(self, key):
|
||||
return {TVINFO_TWITTER: self.twitter, TVINFO_INSTAGRAM: self.instagram, TVINFO_FACEBOOK: self.facebook,
|
||||
TVINFO_WIKIPEDIA: self.wikipedia}.get(key)
|
||||
TVINFO_WIKIPEDIA: self.wikipedia, TVINFO_REDDIT: self.reddit, TVINFO_TWITTER: self.youtube}.get(key)
|
||||
|
||||
def __iter__(self):
|
||||
for s, v in [(TVINFO_TWITTER, self.twitter), (TVINFO_INSTAGRAM, self.instagram),
|
||||
(TVINFO_FACEBOOK, self.facebook), (TVINFO_WIKIPEDIA, self.wikipedia)]:
|
||||
(TVINFO_FACEBOOK, self.facebook), (TVINFO_WIKIPEDIA, self.wikipedia),
|
||||
(TVINFO_REDDIT, self.reddit), (TVINFO_YOUTUBE, self.youtube)]:
|
||||
yield s, v
|
||||
|
||||
def __str__(self):
|
||||
|
@ -726,6 +734,7 @@ class PersonGenders(object):
|
|||
reverse = {v: k for k, v in iteritems(named)}
|
||||
tmdb_map = {0: unknown, 1: female, 2: male}
|
||||
imdb_map = {'female': female, 'male': male}
|
||||
tvdb_map = {0: unknown, 1: male, 2: female, 3: unknown} # 3 is technically: other
|
||||
|
||||
|
||||
class Crew(PersonBase):
|
||||
|
|
|
@ -854,7 +854,7 @@ class GenericMetadata(object):
|
|||
|
||||
t = sickgear.TVInfoAPI(tv_id).setup(**tvinfo_config)
|
||||
return t.get_show((show_obj.ids[tv_id]['id'], show_obj.prodid)[tv_src == show_obj.tvid],
|
||||
load_episodes=False, banners=True, posters=True, fanart=True, language=show_obj.lang)
|
||||
load_episodes=False, banners=True, posters=True, fanart=True, language=show_lang)
|
||||
except (BaseTVinfoError, IOError) as e:
|
||||
logger.warning(f'Unable to look up show on {sickgear.TVInfoAPI(tv_id).name},'
|
||||
f' not downloading images: {ex(e)}')
|
||||
|
|
|
@ -973,11 +973,12 @@ class QueueItemAdd(ShowQueueItem):
|
|||
tvinfo_config = sickgear.TVInfoAPI(self.tvid).api_params.copy()
|
||||
if self.lang:
|
||||
tvinfo_config['language'] = self.lang
|
||||
kw = {'language': self.lang}
|
||||
|
||||
logger.log(f'{sickgear.TVInfoAPI(self.tvid).name}: {repr(tvinfo_config)}')
|
||||
|
||||
t = sickgear.TVInfoAPI(self.tvid).setup(**tvinfo_config)
|
||||
s = t.get_show(self.prodid, load_episodes=False, language=self.lang)
|
||||
s = t.get_show(self.prodid, load_episodes=False, **kw)
|
||||
|
||||
if getattr(t, 'show_not_found', False):
|
||||
logger.error(f'Show {self.show_name} was not found on {sickgear.TVInfoAPI(self.tvid).name},'
|
||||
|
@ -1676,7 +1677,7 @@ class QueueItemSwitchSource(ShowQueueItem):
|
|||
tvinfo_config['dvdorder'] = 0 != self.show_obj._dvdorder
|
||||
t = sickgear.TVInfoAPI(self.new_tvid).setup(**tvinfo_config)
|
||||
try:
|
||||
td = t.get_show(show_id=new_prodid, actors=True)
|
||||
td = t.get_show(show_id=new_prodid, actors=True, language=self.show_obj._lang)
|
||||
except (BaseException, Exception):
|
||||
td = None
|
||||
if not self.force_id:
|
||||
|
@ -1684,7 +1685,7 @@ class QueueItemSwitchSource(ShowQueueItem):
|
|||
if new_prodid != self.show_obj.ids.get(self.new_tvid, {}).get('id') is not None:
|
||||
new_prodid = self.show_obj.ids.get(self.new_tvid, {}).get('id')
|
||||
try:
|
||||
td = t.get_show(show_id=new_prodid, actors=True, language=self.show_obj.lang)
|
||||
td = t.get_show(show_id=new_prodid, actors=True, language=self.show_obj._lang)
|
||||
except (BaseException, Exception):
|
||||
td = None
|
||||
logger.warning(f'Failed to get new tv show id ({new_prodid})'
|
||||
|
|
|
@ -2134,7 +2134,10 @@ class TVShow(TVShowBase):
|
|||
|
||||
logger.log('%s: Updating NFOs for show with new TV info' % self.tvid_prodid)
|
||||
for cur_provider in itervalues(sickgear.metadata_provider_dict):
|
||||
result = cur_provider.update_show_indexer_metadata(self) or result
|
||||
try:
|
||||
result = cur_provider.update_show_indexer_metadata(self) or result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating show nfo: %s' % ex(e))
|
||||
|
||||
return result
|
||||
|
||||
|
@ -2397,14 +2400,40 @@ class TVShow(TVShowBase):
|
|||
# FIXME: Needs to not show this message if the option is not enabled?
|
||||
logger.debug('Running metadata routines for %s' % cur_provider.name)
|
||||
|
||||
fanart_result = cur_provider.create_fanart(self) or fanart_result
|
||||
poster_result = cur_provider.create_poster(self) or poster_result
|
||||
banner_result = cur_provider.create_banner(self) or banner_result
|
||||
try:
|
||||
fanart_result = cur_provider.create_fanart(self) or fanart_result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating show fanart: %s' % ex(e))
|
||||
|
||||
season_posters_result = cur_provider.create_season_posters(self) or season_posters_result
|
||||
season_banners_result = cur_provider.create_season_banners(self) or season_banners_result
|
||||
season_all_poster_result = cur_provider.create_season_all_poster(self) or season_all_poster_result
|
||||
season_all_banner_result = cur_provider.create_season_all_banner(self) or season_all_banner_result
|
||||
try:
|
||||
poster_result = cur_provider.create_poster(self) or poster_result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating show poster: %s' % ex(e))
|
||||
|
||||
try:
|
||||
banner_result = cur_provider.create_banner(self) or banner_result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating show banner: %s' % ex(e))
|
||||
|
||||
try:
|
||||
season_posters_result = cur_provider.create_season_posters(self) or season_posters_result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating show season poster: %s' % ex(e))
|
||||
|
||||
try:
|
||||
season_banners_result = cur_provider.create_season_banners(self) or season_banners_result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating show season banner: %s' % ex(e))
|
||||
|
||||
try:
|
||||
season_all_poster_result = cur_provider.create_season_all_poster(self) or season_all_poster_result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating show season poster: %s' % ex(e))
|
||||
|
||||
try:
|
||||
season_all_banner_result = cur_provider.create_season_all_banner(self) or season_all_banner_result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating show season banner: %s' % ex(e))
|
||||
|
||||
return fanart_result or poster_result or banner_result or season_posters_result or season_banners_result \
|
||||
or season_all_poster_result or season_all_banner_result
|
||||
|
@ -4630,7 +4659,10 @@ class TVEpisode(TVEpisodeBase):
|
|||
result = False
|
||||
|
||||
for cur_provider in itervalues(sickgear.metadata_provider_dict):
|
||||
result = cur_provider.create_episode_metadata(self, force) or result
|
||||
try:
|
||||
result = cur_provider.create_episode_metadata(self, force) or result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating episode nfo: %s' % ex(e))
|
||||
|
||||
return result
|
||||
|
||||
|
@ -4643,7 +4675,10 @@ class TVEpisode(TVEpisodeBase):
|
|||
result = False
|
||||
|
||||
for cur_provider in itervalues(sickgear.metadata_provider_dict):
|
||||
result = cur_provider.create_episode_thumb(self) or result
|
||||
try:
|
||||
result = cur_provider.create_episode_thumb(self) or result
|
||||
except (BaseException, Exception) as e:
|
||||
logger.warning('Error creating episode thumb: %s' % ex(e))
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
@ -3973,7 +3973,7 @@ class AddShows(Home):
|
|||
|
||||
@staticmethod
|
||||
def get_infosrc_languages():
|
||||
result = sickgear.TVInfoAPI().config['valid_languages']
|
||||
result = sickgear.TVInfoAPI().config['valid_languages'].copy()
|
||||
|
||||
# sort list alphabetically with sickgear.ADD_SHOWS_METALANG as the first item
|
||||
if sickgear.ADD_SHOWS_METALANG in result:
|
||||
|
@ -3981,6 +3981,16 @@ class AddShows(Home):
|
|||
result.sort()
|
||||
result.insert(0, sickgear.ADD_SHOWS_METALANG)
|
||||
|
||||
for src in sickgear.TVInfoAPI().search_sources:
|
||||
tvinfo_config = sickgear.TVInfoAPI(src).api_params.copy()
|
||||
t = sickgear.TVInfoAPI(src).setup(**tvinfo_config)
|
||||
try:
|
||||
all_langs = t.get_languages()
|
||||
except (BaseException, Exception):
|
||||
continue
|
||||
if all_langs:
|
||||
result.extend([lang['sg_lang'] for lang in all_langs if lang['sg_lang'] not in result])
|
||||
|
||||
return json_dumps({'results': result})
|
||||
|
||||
@staticmethod
|
||||
|
@ -4160,7 +4170,7 @@ class AddShows(Home):
|
|||
sickgear.TVInfoAPI((tvid, TVINFO_TVDB)[TVINFO_TRAKT == tvid]).config['slug'],
|
||||
(sickgear.TVInfoAPI((tvid, TVINFO_TVDB)[TVINFO_TRAKT == tvid]).config['show_url'] %
|
||||
show['ids'][(tvid, TVINFO_TVDB)[TVINFO_TRAKT == tvid]])
|
||||
+ ('', '&lid=%s' % sickgear.TVInfoAPI().config['langabbv_to_id'][lang])[TVINFO_TVDB == tvid],
|
||||
+ ('', '&lid=%s' % sickgear.TVInfoAPI().config.get('langabbv_to_id', {}).get(lang, lang))[TVINFO_TVDB == tvid],
|
||||
int(show['id']),
|
||||
show['seriesname'], helpers.xhtml_escape(show['seriesname']), show['firstaired'],
|
||||
(isinstance(show['firstaired'], string_types)
|
||||
|
@ -4253,7 +4263,7 @@ class AddShows(Home):
|
|||
if TVINFO_TRAKT == iid:
|
||||
img_url = 'imagecache?path=browse/thumb/trakt&filename=%s&trans=0&tmdbid=%s&tvdbid=%s' % \
|
||||
('%s.jpg' % show_info['ids'].trakt, show_info.get('tmdb_id'), show_info['ids'].tvdb)
|
||||
elif TVINFO_TVDB == iid:
|
||||
elif TVINFO_TVDB == iid and 'poster' in show_info and show_info['poster']:
|
||||
img_url = 'imagecache?path=browse/thumb/tvdb&filename=%s&trans=0&source=%s' % \
|
||||
('%s.jpg' % show_info['id'], show_info['poster'])
|
||||
sickgear.CACHE_IMAGE_URL_LIST.add_url(show_info['poster'])
|
||||
|
|
Loading…
Reference in a new issue