def __init__( self, api_key='a07324c669cac4d96789197134ce272b', language=get_language(), mpaa_prefix=get_mpaa_prefix()): super(TMDb, self).__init__( req_api_name='TMDb', req_api_url=API_URL, req_api_key='api_key={}'.format(api_key)) self.language = language self.iso_language = language[:2] self.iso_country = language[-2:] self.req_language = '{0}-{1}&include_image_language={0},null'.format(self.iso_language, self.iso_country) self.mpaa_prefix = mpaa_prefix self.append_to_response = APPEND_TO_RESPONSE self.mapper = ItemMapper(self.language, self.mpaa_prefix)
def __init__(self, language=None, mpaa_prefix=None): self.language = language or get_language() self.mpaa_prefix = mpaa_prefix or get_mpaa_prefix() self.iso_language = language[:2] self.iso_country = language[-2:] self.blacklist = [] """ Mapping dictionary keys: list of tuples containing parent and child key to add value. [('parent', 'child')] parent keys: art, unique_ids, infolabels, infoproperties, params use UPDATE_BASEKEY for child key to update parent with a dict func: function to call to manipulate values (omit to skip and pass value directly) (kw)args: list/dict of args/kwargs to pass to func. func is also always passed v as first argument type: int, float, str - convert v to type using try_type(v, type) extend: set True to add to existing list - leave blank to overwrite exiting list subkeys: list of sub keys to get for v - i.e. v.get(subkeys[0], {}).get(subkeys[1]) etc. note that getting subkeys sticks for entire loop so do other ops on base first if needed use standard_map for direct one-to-one mapping of v onto single property tuple """ self.advanced_map = { 'poster_path': [{ 'keys': [('art', 'poster')], 'func': get_imagepath_poster }], 'profile_path': [{ 'keys': [('art', 'poster')], 'func': get_imagepath_poster }], 'file_path': [{ 'keys': [('art', 'poster')], 'func': get_imagepath_fanart }], 'still_path': [{ 'keys': [('art', 'thumb')], 'func': get_imagepath_fanart }], 'backdrop_path': [{ 'keys': [('art', 'fanart')], 'func': get_imagepath_fanart }], 'content_ratings': [{ 'keys': [('infolabels', 'mpaa')], 'subkeys': ['results'], 'func': get_mpaa_rating, 'args': [self.mpaa_prefix, self.iso_country, False] }], 'release_dates': [{ 'keys': [('infolabels', 'mpaa')], 'subkeys': ['results'], 'func': get_mpaa_rating, 'args': [self.mpaa_prefix, self.iso_country, True] }], 'release_date': [{ 'keys': [('infolabels', 'premiered')] }, { 'keys': [('infolabels', 'year')], 'func': lambda v: v[0:4] }], 'first_air_date': [{ 'keys': [('infolabels', 'premiered')] }, { 'keys': [('infolabels', 'year')], 'func': lambda v: v[0:4] }], 'air_date': [{ 'keys': [('infolabels', 'premiered')] }, { 'keys': [('infolabels', 'year')], 'func': lambda v: v[0:4] }], 'genre_ids': [{ 'keys': [('infolabels', 'genre')], 'func': get_genres_by_id }], 'videos': [{ 'keys': [('infolabels', 'trailer')], 'func': get_trailer }], 'popularity': [{ 'keys': [('infoproperties', 'popularity')], 'type': str }], 'vote_count': [{ 'keys': [('infolabels', 'votes'), ('infoproperties', 'tmdb_votes')], 'type': float, 'func': lambda v: u'{:0,.0f}'.format(v) }], 'vote_average': [{ 'keys': [('infolabels', 'rating'), ('infoproperties', 'tmdb_rating')], 'type': float, 'func': lambda v: u'{:.1f}'.format(v) }], 'budget': [{ 'keys': [('infoproperties', 'budget')], 'type': float, 'func': lambda v: u'${:0,.0f}'.format(v) }], 'revenue': [{ 'keys': [('infoproperties', 'revenue')], 'type': float, 'func': lambda v: u'${:0,.0f}'.format(v) }], 'spoken_languages': [{ 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': iter_props, 'args': ['language'], 'kwargs': { 'name': 'name', 'iso': 'iso_639_1' } }], 'keywords': [{ 'keys': [('infoproperties', UPDATE_BASEKEY)], 'subkeys': ['keywords'], 'func': iter_props, 'args': ['keyword'], 'kwargs': { 'name': 'name', 'tmdb_id': 'id' } }], 'reviews': [{ 'keys': [('infoproperties', UPDATE_BASEKEY)], 'subkeys': ['results'], 'func': iter_props, 'args': ['review'], 'kwargs': { 'content': 'content', 'author': 'author', 'tmdb_id': 'id' } }], 'created_by': [ { 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': get_iter_props, 'args': ['creator'], 'kwargs': { 'basic_keys': { 'name': 'name', 'tmdb_id': 'id' }, 'image_keys': { 'thumb': 'profile_path' } } }, { # --- 'keys': [('infoproperties', 'creator')], 'func': lambda v: ' / '.join( [x['name'] for x in v or [] if x.get('name')]) } ], 'also_known_as': [{ 'keys': [('infoproperties', 'aliases')], 'func': lambda v: ' / '.join([x for x in v or [] if x]) }], 'known_for': [ { 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': iter_props, 'args': ['known_for'], 'kwargs': { 'title': 'title', 'tmdb_id': 'id', 'rating': 'vote_average', 'tmdb_type': 'media_type' } }, { # --- 'keys': [('infoproperties', 'known_for')], 'func': lambda v: ' / '.join( [x['title'] for x in v or [] if x.get('title')]) } ], 'external_ids': [{ 'keys': [('unique_ids', UPDATE_BASEKEY)], 'func': get_external_ids }], 'credits': [ { 'keys': [('infolabels', UPDATE_BASEKEY)], 'func': get_credits }, { # --- 'keys': [('infoproperties', UPDATE_BASEKEY)], 'subkeys': ['crew'], 'func': get_crew_properties } ], 'parts': [{ 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': get_collection_properties }], 'movie_credits': [ { 'keys': [('infoproperties', 'numitems.tmdb.movies.cast')], 'func': lambda v: len(v.get('cast') or []) }, { # --- 'keys': [('infoproperties', 'numitems.tmdb.movies.crew')], 'func': lambda v: len(v.get('crew') or []) }, { # --- 'keys': [('infoproperties', 'numitems.tmdb.movies.total')], 'func': lambda v: len(v.get('cast') or []) + len( v.get('crew') or []) } ], 'tv_credits': [ { 'keys': [('infoproperties', 'numitems.tmdb.tvshows.cast')], 'func': lambda v: len(v.get('cast') or []) }, { # --- 'keys': [('infoproperties', 'numitems.tmdb.tvshows.crew')], 'func': lambda v: len(v.get('crew') or []) }, { # --- 'keys': [('infoproperties', 'numitems.tmdb.tvshows.total')], 'func': lambda v: len(v.get('cast') or []) + len( v.get('crew') or []) } ], 'belongs_to_collection': [ { 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': get_collection }, { # --- 'keys': [('infolabels', 'set')], 'subkeys': ['name'] } ], 'episode_run_time': [{ 'keys': [('infolabels', 'duration')], 'func': get_runtime }], 'runtime': [{ 'keys': [('infolabels', 'duration')], 'func': get_runtime }], 'genres': [ { 'keys': [('infolabels', 'genre')], 'func': dict_to_list, 'args': ['name'] }, { # --- 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': iter_props, 'args': ['genre'], 'kwargs': { 'name': 'name', 'tmdb_id': 'id' } } ], 'production_countries': [ { 'keys': [('infolabels', 'country')], 'extend': True, 'func': dict_to_list, 'args': ['name'] }, { # --- 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': iter_props, 'args': ['country'], 'kwargs': { 'name': 'name', 'tmdb_id': 'id' } } ], 'networks': [ { 'keys': [('infolabels', 'studio')], 'extend': True, 'func': dict_to_list, 'args': ['name'] }, { # --- 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': get_iter_props, 'args': ['studio'], 'kwargs': { 'basic_keys': { 'name': 'name', 'tmdb_id': 'id' }, 'image_keys': { 'icon': 'logo_path' } } } ], 'production_companies': [ { 'keys': [('infolabels', 'studio')], 'extend': True, 'func': dict_to_list, 'args': ['name'] }, { # --- 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': get_iter_props, 'args': ['studio'], 'kwargs': { 'basic_keys': { 'name': 'name', 'tmdb_id': 'id' }, 'image_keys': { 'icon': 'logo_path' } } } ], 'watch/providers': [{ 'keys': [('infoproperties', UPDATE_BASEKEY)], 'subkeys': ['results', self.iso_country], 'func': get_providers }], 'last_episode_to_air': [{ 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': get_episode_to_air, 'args': ['last_aired'] }], 'next_episode_to_air': [{ 'keys': [('infoproperties', UPDATE_BASEKEY)], 'func': get_episode_to_air, 'args': ['next_aired'] }], 'imdb_id': [{ 'keys': [('infolabels', 'imdbnumber'), ('unique_ids', 'imdb')] }], 'character': [{ 'keys': [('infoproperties', 'role'), ('infoproperties', 'character'), ('label2', None)] }], 'job': [{ 'keys': [('infoproperties', 'role'), ('infoproperties', 'job'), ('label2', None)] }], 'biography': [{ 'keys': [('infoproperties', 'biography'), ('infolabels', 'plot')] }], 'gender': [{ 'keys': [('infoproperties', 'gender')], 'func': lambda v, d: d.get(v), 'args': [{ 1: ADDON.getLocalizedString(32071), 2: ADDON.getLocalizedString(32070) }] }] } self.standard_map = { 'overview': ('infolabels', 'plot'), 'content': ('infolabels', 'plot'), 'tagline': ('infolabels', 'tagline'), 'id': ('unique_ids', 'tmdb'), 'original_title': ('infolabels', 'originaltitle'), 'original_name': ('infolabels', 'originaltitle'), 'title': ('infolabels', 'title'), 'name': ('infolabels', 'title'), 'author': ('infolabels', 'title'), 'origin_country': ('infolabels', 'country'), 'status': ('infolabels', 'status'), 'season_number': ('infolabels', 'season'), 'episode_number': ('infolabels', 'episode'), 'season_count': ('infolabels', 'season'), 'episode_count': ('infolabels', 'episode'), 'department': ('infoproperties', 'department'), 'place_of_birth': ('infoproperties', 'born'), 'birthday': ('infoproperties', 'birthday'), 'deathday': ('infoproperties', 'deathday'), 'width': ('infoproperties', 'width'), 'height': ('infoproperties', 'height'), 'aspect_ratio': ('infoproperties', 'aspect_ratio') }