def get_query(self): if self.get_infolabel('TvShowTitle'): return try_decode(self.get_infolabel('TvShowTitle')) if self.get_infolabel('Title'): return try_decode(self.get_infolabel('Title')) if self.get_infolabel('Label'): return try_decode(self.get_infolabel('Label'))
def get_playingitem(self): if not self.isPlayingVideo(): return # Not a video so don't get info if self.getVideoInfoTag().getMediaType() not in ['movie', 'episode']: return # Not a movie or episode so don't get info TODO Maybe get PVR details also? self.playerstring = get_property('PlayerInfoString') self.playerstring = loads( self.playerstring) if self.playerstring else None self.total_time = self.getTotalTime() self.dbtype = self.getVideoInfoTag().getMediaType() self.dbid = self.getVideoInfoTag().getDbId() self.imdb_id = self.getVideoInfoTag().getIMDBNumber() self.query = self.getVideoInfoTag().getTVShowTitle( ) if self.dbtype == 'episode' else self.getVideoInfoTag().getTitle() self.year = self.getVideoInfoTag().getYear( ) if self.dbtype == 'movie' else None self.epyear = self.getVideoInfoTag().getYear( ) if self.dbtype == 'episodes' else None self.season = self.getVideoInfoTag().getSeason( ) if self.dbtype == 'episodes' else None self.episode = self.getVideoInfoTag().getEpisode( ) if self.dbtype == 'episodes' else None self.query = try_decode(self.query) self.tmdb_type = 'movie' if self.dbtype == 'movie' else 'tv' self.tmdb_id = self.get_tmdb_id(self.tmdb_type, self.imdb_id, self.query, self.year, self.epyear) self.details = self.tmdb_api.get_details(self.tmdb_type, self.tmdb_id, self.season, self.episode) # Clear everything if we didn't get details because nothing to compare if not self.details: return self.reset_properties() # Get ratings (no need for threading since we're only getting one item in player ever) if xbmc.getCondVisibility( "!Skin.HasSetting(TMDbHelper.DisableRatings)"): self.details = self.get_omdb_ratings(self.details) if self.tmdb_type == 'movie': self.details = self.get_imdb_top250_rank(self.details) if self.tmdb_type in ['movie', 'tv']: self.details = self.get_trakt_ratings( self.details, 'movie' if self.tmdb_type == 'movie' else 'show', season=self.season, episode=self.episode) self.set_iter_properties(self.details.get('infoproperties', {}), SETPROP_RATINGS) # Get artwork (no need for threading since we're only getting one item in player ever) # No need for merging Kodi DB artwork as we should have access to that via normal player properties if xbmc.getCondVisibility( "!Skin.HasSetting(TMDbHelper.DisableArtwork)"): if ADDON.getSettingBool('service_fanarttv_lookup'): self.details = self.get_fanarttv_artwork( self.details, self.tmdb_type) self.set_iter_properties(self.details, SETMAIN_ARTWORK) self.set_properties(self.details)
def list_search(self, tmdb_type, query=None, update_listing=False, page=None, **kwargs): original_query = query query = query or set_search_history( query=try_decode(xbmcgui.Dialog().input(ADDON.getLocalizedString(32044), type=xbmcgui.INPUT_ALPHANUM)), tmdb_type=tmdb_type) if not query: return items = self.tmdb_api.get_search_list( tmdb_type=tmdb_type, query=query, page=page, year=kwargs.get('year'), first_air_date_year=kwargs.get('first_air_date_year'), primary_release_year=kwargs.get('primary_release_year')) if not original_query: params = merge_two_dicts(kwargs, { 'info': 'search', 'tmdb_type': tmdb_type, 'page': page, 'query': query, 'update_listing': 'True'}) self.container_update = u'{}?{}'.format(PLUGINPATH, urlencode_params(**params)) # Trigger container update using new path with query after adding items # Prevents onback from re-prompting for user input by re-writing path self.update_listing = True if update_listing else False self.container_content = convert_type(tmdb_type, 'container') self.kodi_db = self.get_kodi_database(tmdb_type) 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 _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 __init__(self): self.params = {} for arg in [try_decode(arg) for arg in sys.argv[1:]]: if '=' in arg: key, value = arg.split('=', 1) self.params[key] = value.strip('\'').strip( '"') if value else True else: self.params[arg] = True self.params = reconfigure_legacy_params(**self.params)
def configure_players(self): filename = try_decode(self.select_player()) if not filename: return player = self.players[filename].copy() player = _ConfigurePlayer(player, filename=filename).configure() if player == -1: # Reset player (i.e. delete player file) self.delete_player(filename) elif player and player != self.players[filename]: self.save_player(player, filename) return self.configure_players()
def get_jsonrpc(method=None, params=None): if not method: return {} query = {"jsonrpc": "2.0", "method": method, "id": 1} if params: query["params"] = params try: jrpc = xbmc.executeJSONRPC(json.dumps(query)) response = json.loads(try_decode(jrpc, errors='ignore')) except Exception as exc: kodi_log(u'TMDbHelper - JSONRPC Error:\n{}'.format(exc), 1) response = {} return response
def configure_action(self, listitem, handle=None): path = try_decode(listitem.getPath()) if listitem.getProperty('is_folder') == 'true': return format_folderpath(path) if not handle or listitem.getProperty('is_resolvable') == 'false': return path if listitem.getProperty( 'is_resolvable') == 'select' and not xbmcgui.Dialog().yesno( '{} - {}'.format(listitem.getProperty('player_name'), ADDON.getLocalizedString(32353)), ADDON.getLocalizedString(32354), yeslabel=u"{} (setResolvedURL)".format( xbmc.getLocalizedString(107)), nolabel=u"{} (PlayMedia)".format( xbmc.getLocalizedString(106))): return path
def configure_action(self, listitem, handle=None): path = try_decode(listitem.getPath()) if listitem.getProperty('is_folder') == 'true': return format_folderpath(path) action = 'run_plugin' if path.startswith('plugin://') else 'play_media' action = u'RunScript(plugin.video.themoviedb.helper,{}={})'.format( action, path) if path.endswith('.strm'): return action if not handle or listitem.getProperty('is_resolvable') == 'false': return action if listitem.getProperty( 'is_resolvable') == 'select' and xbmcgui.Dialog().yesno( '{} - {}'.format(listitem.getProperty('player_name'), ADDON.getLocalizedString(32324)), ADDON.getLocalizedString(32325), yeslabel='PlayMedia', nolabel='setResolvedUrl'): return action
def update_tvshows(self, force=False, **kwargs): nfos = [] # Get TMDb IDs from nfo files in folder nfos_append = nfos.append # For speed since we can't do a list comp easily here for f in xbmcvfs.listdir(BASEDIR_TV)[0]: tmdb_id = get_tmdb_id_nfo(BASEDIR_TV, f) nfos_append({'tmdb_id': tmdb_id, 'folder': f}) if tmdb_id else None # Update each show in folder nfos_total = len(nfos) for x, i in enumerate(nfos): self._update(x, nfos_total, message=u'{} {}...'.format( ADDON.getLocalizedString(32167), try_decode(i['folder']))) self.add_tvshow(tmdb_id=i['tmdb_id'], force=force) # Update last updated stamp ADDON.setSettingString( 'last_autoupdate', u'Last updated {}'.format(get_current_date_time()))
def get_players_from_file(): players = {} basedirs = [PLAYERS_BASEDIR_USER] if ADDON.getSettingBool('bundled_players'): basedirs += [PLAYERS_BASEDIR_BUNDLED] basedirs += [PLAYERS_BASEDIR_SAVE ] # Add saved players last so they overwrite for basedir in basedirs: files = get_files_in_folder(basedir, r'.*\.json') for file in files: meta = loads(read_file(basedir + file)) or {} plugins = meta.get( 'plugin' ) or 'plugin.undefined' # Give dummy name to undefined plugins so that they fail the check plugins = plugins if isinstance( plugins, list) else [plugins] # Listify for simplicity of code for i in plugins: if not xbmc.getCondVisibility( u'System.HasAddon({0})'.format(i)): break # System doesn't have a required plugin so skip this player else: meta['plugin'] = plugins[0] players[try_decode(file)] = meta return players
def play(self, folder_path=None, reset_focus=None, handle=None): # Get some info about current container for container update hack if not folder_path: folder_path = xbmc.getInfoLabel("Container.FolderPath") if not reset_focus and folder_path: containerid = xbmc.getInfoLabel("System.CurrentControlID") current_pos = xbmc.getInfoLabel( "Container({}).CurrentItem".format(containerid)) reset_focus = 'SetFocus({},{},absolute)'.format( containerid, try_int(current_pos) - 1) # Get the resolved path listitem = self.get_resolved_path() # Reset folder hack self._update_listing_hack(folder_path=folder_path, reset_focus=reset_focus) # Check we have an actual path to open if not try_decode(listitem.getPath()) or try_decode( listitem.getPath()) == PLUGINPATH: return action = self.configure_action(listitem, handle) # Kodi launches busy dialog on home screen that needs to be told to close # Otherwise the busy dialog will prevent window activation for folder path xbmc.executebuiltin('Dialog.Close(busydialog)') # If a folder we need to resolve to dummy and then open folder if listitem.getProperty('is_folder') == 'true': resolve_to_dummy(handle, self.dummy_duration, self.dummy_delay) xbmc.executebuiltin(try_encode(action)) kodi_log(['lib.player - finished executing action\n', action], 1) return # Set our playerstring for player monitor to update kodi watched status if self.playerstring: get_property('PlayerInfoString', set_property=self.playerstring) # If PlayMedia method chosen re-route to Player() unless expert settings on if action: resolve_to_dummy( handle, self.dummy_duration, self.dummy_delay ) # If we're calling external we need to resolve to dummy xbmc.Player().play( action, listitem) if self.force_xbmcplayer else xbmc.executebuiltin( u'PlayMedia({})'.format(action)) kodi_log([ 'lib.player - playing path with {}\n'.format( 'xbmc.Player()' if self.force_xbmcplayer else 'PlayMedia'), try_decode(listitem.getPath()) ], 1) return # Otherwise we have a url we can resolve to xbmcplugin.setResolvedUrl(handle, True, listitem) kodi_log([ 'lib.player - finished resolving path to url\n', try_decode(listitem.getPath()) ], 1) # Re-send local files to player due to "bug" (or maybe "feature") of setResolvedUrl # Because setResolvedURL doesn't set id/type (sets None, "unknown" instead) to player for plugins # If id/type not set to Player.GetItem things like Trakt don't work correctly. # Looking for better solution than this hack. if ADDON.getSettingBool('trakt_localhack') and listitem.getProperty( 'is_local') == 'true': xbmc.Player().play( try_decode(listitem.getPath()), listitem) if self.force_xbmcplayer else xbmc.executebuiltin( u'PlayMedia({})'.format(try_decode(listitem.getPath()))) kodi_log([ 'Finished executing {}\n'.format( 'xbmc.Player()' if self.force_xbmcplayer else 'PlayMedia'), try_decode(listitem.getPath()) ], 1)
def set_property(self, key, value): key = u'{}.{}'.format(self.property_prefix, key) if value is None: get_property(key, clear_property=True) else: get_property(key, set_property=u'{0}'.format(try_decode(value)))
def _get_keyboard(method, header=None): value = try_decode(xbmcgui.Dialog().input(header, defaultt=_win_prop(method))) return {'value': value, 'label': value, 'method': method}
def _get_numeric(method, header=None): value = try_decode(xbmcgui.Dialog().input(header, type=xbmcgui.INPUT_NUMERIC, defaultt=_win_prop(method))) return {'value': value, 'label': value, 'method': method}
def __init__(self, player, filename): self.player = player self.filename = try_decode(filename)
def get_mpaa_prefix(): if ADDON.getSettingString('mpaa_prefix'): return u'{} '.format(try_decode(ADDON.getSettingString('mpaa_prefix'))) return u''