def get_item_details(tmdb_type, tmdb_id, season=None, episode=None, language=None): tmdb_api = TMDb(language=language) if language else TMDb() details = tmdb_api.get_details(tmdb_type, tmdb_id, season, episode) del tmdb_api if not details: return details = ListItem(**details) details.infolabels['mediatype'] == 'movie' if tmdb_type == 'movie' else 'episode' details.set_details(details=get_external_ids(details, season=season, episode=episode)) return details
def _translate_discover_params(tmdb_type, params): lookup_keyword = None if params.get('with_id') and params.get('with_id') != 'False' else 'keyword' lookup_company = None if params.get('with_id') and params.get('with_id') != 'False' else 'company' lookup_person = None if params.get('with_id') and params.get('with_id') != 'False' else 'person' lookup_genre = None if params.get('with_id') and params.get('with_id') != 'False' else 'genre' with_separator = params.get('with_separator') if params.get('with_genres'): params['with_genres'] = TMDb().get_translated_list( split_items(params.get('with_genres')), lookup_genre, separator=with_separator) if params.get('without_genres'): params['without_genres'] = TMDb().get_translated_list( split_items(params.get('without_genres')), lookup_genre, separator=with_separator) if params.get('with_keywords'): params['with_keywords'] = TMDb().get_translated_list( split_items(params.get('with_keywords')), lookup_keyword, separator=with_separator) if params.get('without_keywords'): params['without_keywords'] = TMDb().get_translated_list( split_items(params.get('without_keywords')), lookup_keyword, separator=with_separator) if params.get('with_companies'): params['with_companies'] = TMDb().get_translated_list( split_items(params.get('with_companies')), lookup_company, separator='NONE') if params.get('with_people'): params['with_people'] = TMDb().get_translated_list( split_items(params.get('with_people')), lookup_person, separator=with_separator) if params.get('with_cast'): params['with_cast'] = TMDb().get_translated_list( split_items(params.get('with_cast')), lookup_person, separator=with_separator) if params.get('with_crew'): params['with_crew'] = TMDb().get_translated_list( split_items(params.get('with_crew')), lookup_person, separator=with_separator) if params.get('with_release_type'): params['with_release_type'] = TMDb().get_translated_list( split_items(params.get('with_release_type')), None, separator='OR') # Translate relative dates based upon today's date for i in RELATIVE_DATES: datecode = params.get(i, '') datecode = datecode.lower() if not datecode or all(x not in datecode for x in ['t-', 't+']): continue # No value or not a relative date so skip elif 't-' in datecode: days = try_int(datecode.replace('t-', '')) date = get_datetime_now() - get_timedelta(days=days) elif 't+' in datecode: days = try_int(datecode.replace('t+', '')) date = get_datetime_now() + get_timedelta(days=days) params[i] = date.strftime("%Y-%m-%d") return params
def add_movie(self, tmdb_id=None, **kwargs): if not tmdb_id: return # Get movie details details = TMDb().get_request_sc('movie', tmdb_id, append_to_response='external_ids') if not details or not details.get('title'): return imdb_id = details.get('external_ids', {}).get('imdb_id') name = u'{} ({})'.format(details['title'], details['release_date'][:4]) if details.get( 'release_date') else details['title'] # Only add strm if not in library file = self.kodi_db_movies.get_info(info='file', imdb_id=imdb_id, tmdb_id=tmdb_id) if not file: file = create_file(STRM_MOVIE.format(tmdb_id), name, name, basedir=BASEDIR_MOVIE) create_nfo('movie', tmdb_id, name, basedir=BASEDIR_MOVIE) self._log._add('movie', tmdb_id, 'added strm file', path=file) else: self._log._add('movie', tmdb_id, 'item in library', path=file) # Return our playlist rule return ('filename', file.replace('\\', '/').split('/')[-1])
def get_details(self): self.details = TMDb().get_request_sc('tv', self.tmdb_id, append_to_response='external_ids') if not self.details: return self.tvdb_id = self.details.get('external_ids', {}).get('tvdb_id') self.imdb_id = self.details.get('external_ids', {}).get('imdb_id') return self.details
def list_discover(self, tmdb_type, **kwargs): kwargs.pop('info', None) items = TMDb().get_discover_list(tmdb_type, **_translate_discover_params(tmdb_type, kwargs)) self.kodi_db = self.get_kodi_database(tmdb_type) self.library = convert_type(tmdb_type, 'library') self.container_content = convert_type(tmdb_type, 'container') return items
def __init__(self): self.handle = int(sys.argv[1]) self.paramstring = try_decode(sys.argv[2][1:]) self.params = parse_paramstring(self.paramstring) self.parent_params = self.params # self.container_path = u'{}?{}'.format(sys.argv[0], self.paramstring) self.update_listing = False self.plugin_category = '' self.container_content = '' self.container_update = None self.container_refresh = False self.item_type = None self.kodi_db = None self.kodi_db_tv = {} self.library = None self.tmdb_cache_only = True self.tmdb_api = TMDb() self.trakt_watchedindicators = ADDON.getSettingBool('trakt_watchedindicators') self.trakt_api = TraktAPI() self.is_widget = True if self.params.pop('widget', '').lower() == 'true' else False self.hide_watched = ADDON.getSettingBool('widgets_hidewatched') if self.is_widget else False self.flatten_seasons = ADDON.getSettingBool('flatten_seasons') self.ftv_forced_lookup = self.params.pop('fanarttv', '').lower() self.ftv_api = FanartTV(cache_only=self.ftv_is_cache_only()) self.filter_key = self.params.pop('filter_key', None) self.filter_value = split_items(self.params.pop('filter_value', None))[0] self.exclude_key = self.params.pop('exclude_key', None) self.exclude_value = split_items(self.params.pop('exclude_value', None))[0] self.pagination = self.pagination_is_allowed() self.params = reconfigure_legacy_params(**self.params)
def log_request(**kwargs): with busy_dialog(): kwargs['response'] = None if not kwargs.get('url'): kwargs['url'] = xbmcgui.Dialog().input('URL') if not kwargs['url']: return if kwargs.get('log_request').lower() == 'trakt': kwargs['response'] = TraktAPI().get_response_json(kwargs['url']) else: kwargs['response'] = TMDb().get_response_json(kwargs['url']) if not kwargs['response']: xbmcgui.Dialog().ok(kwargs['log_request'].capitalize(), u'{}\nNo Response!'.format(kwargs['url'])) return filename = validify_filename(u'{}_{}.json'.format( kwargs['log_request'], kwargs['url'])) dumps_to_file(kwargs, 'log_request', filename) xbmcgui.Dialog().ok( kwargs['log_request'].capitalize(), u'[B]{}[/B]\n\n{}\n{}\n{}'.format( kwargs['url'], xbmc.translatePath('special://profile/addon_data/'), 'plugin.video.themoviedb.helper/log_request', filename)) xbmcgui.Dialog().textviewer(filename, dumps(kwargs['response'], indent=2))
def get_episodes(self, season): self.e_total = 0 self.season_details = TMDb().get_request('tv', self.tmdb_id, 'season', season, cache_refresh=True) if not self.season_details: return [] self.episodes = [i for i in self.season_details.get('episodes', []) if i.get('episode_number', 0) != 0] self.e_total = len(self.episodes) return self.episodes
def get_item_details(tmdb_type, tmdb_id, season=None, episode=None): details = TMDb().get_details(tmdb_type, tmdb_id, season, episode) if not details: return details = ListItem(**details) details.infolabels['mediatype'] == 'movie' if tmdb_type == 'movie' else 'episode' details.set_details(details=get_external_ids(details, season=season, episode=episode)) return details
def __init__(self): self.properties = set() self.index_properties = set() self.trakt_api = TraktAPI() self.tmdb_api = TMDb() self.fanarttv = FanartTV() self.omdb_api = OMDb() if ADDON.getSettingString('omdb_apikey') else None self.imdb_top250 = {} self.property_prefix = 'ListItem'
def _get_query(tmdb_type, method, query=None, header=None, use_details=False): item = TMDb().get_tmdb_id_from_query( tmdb_type=tmdb_type, query=query or try_decode(xbmcgui.Dialog().input(header)), header=header or u'{} {}'.format(ADDON.getLocalizedString(32276), tmdb_type), use_details=use_details, get_listitem=True) if item and item.getUniqueID('tmdb'): return {'label': item.getLabel(), 'value': item.getUniqueID('tmdb'), 'method': method}
def add_query(self, query, tmdb_type): with busy_dialog(): query = try_decode(query) tmdb_id = TMDb().get_tmdb_id_from_query(tmdb_type, query, header=query, use_details=True, auto_single=True) if not tmdb_id: xbmcgui.Dialog().notification('TMDbHelper', ADDON.getLocalizedString(32310).format(query)) return url = 'plugin://plugin.video.themoviedb.helper/?info=details&tmdb_type={}&tmdb_id={}' url = url.format(tmdb_type, tmdb_id) return self.add_path(url)
def _get_language_details(tmdb_type, tmdb_id, season=None, episode=None, language=None): details = TMDb().get_request_lc(tmdb_type, tmdb_id, 'translations') if not details or not details.get('translations'): return item = {} for i in details['translations']: if i.get('iso_639_1') == language: item['title'] = i.get('data', {}).get('title') or i.get('data', {}).get('name') item['plot'] = i.get('data', {}).get('overview') return item
def _legacy_conversion(self, folder, tmdb_id): # Get details details = TMDb().get_request_sc('tv', tmdb_id, append_to_response='external_ids') if not details or not details.get('first_air_date'): return # Skip shows without details/year # Get new name and compare to old name name = u'{} ({})'.format(details.get('name'), details['first_air_date'][:4]) if folder == name: return # Skip if already converted # Convert name basedir = BASEDIR_TV.replace('\\', '/') old_folder = u'{}{}/'.format(basedir, validify_filename(folder)) new_folder = u'{}{}/'.format(basedir, validify_filename(name)) xbmcvfs.rename(old_folder, new_folder)
def refresh_details(tmdb_id=None, tmdb_type=None, season=None, episode=None, confirm=True, **kwargs): if not tmdb_id or not tmdb_type: return with busy_dialog(): details = TMDb().get_details(tmdb_type, tmdb_id, season, episode, cache_refresh=True) if details and confirm: xbmcgui.Dialog().ok( 'TMDbHelper', ADDON.getLocalizedString(32234).format(tmdb_type, tmdb_id)) container_refresh() return details
def refresh_details(tmdb_id=None, tmdb_type=None, season=None, episode=None, **kwargs): if not tmdb_id or not tmdb_type: return with busy_dialog(): details = TMDb().get_details(tmdb_type, tmdb_id, season, episode, cache_refresh=True) if details: xbmcgui.Dialog().ok( 'TMDbHelper', ADDON.getLocalizedString(32234).format(tmdb_type, tmdb_id)) xbmc.executebuiltin('Container.Refresh') xbmc.executebuiltin( 'UpdateLibrary(video,/fake/path/to/force/refresh/on/home)')
def _get_genre(tmdb_type, method): data_list = TMDb().get_request_lc('genre', tmdb_type, 'list') if data_list and data_list.get('genres'): return _select_properties(data_list['genres'], method, header=ADDON.getLocalizedString(32112))
def wrapper(*args, **kwargs): with busy_dialog(): if not kwargs.get('tmdb_id'): kwargs['tmdb_id'] = TMDb().get_tmdb_id(**kwargs) return func(*args, **kwargs)