def main(): contextMenuSource = sys.listitem.getfilename() # see if the user selected a directory. display an error and exit if the # user selected anything other than a directory jsonRequest = pykodi.get_base_json_request('Files.GetDirectory') jsonRequest['params'] = {'directory': contextMenuSource} jsonResponse = pykodi.execute_jsonrpc(jsonRequest) if 'error' in jsonResponse: xbmcgui.Dialog().notification(addon.getLocalizedString(32400), \ addon.getLocalizedString(32406), \ xbmcgui.NOTIFICATION_WARNING) pykodi.log(str(jsonResponse), xbmc.LOGNOTICE) sys.exit(1) # these parameters do not apply if the user chose the "Run Cinder from here" # context menu option # Changing these variables will not change how Cinder behaves additionalSourceList = [] additionalSourceWeightList = [] maximumSourceWeight = 100 cinderRandomPlayer = CinderRandomPlayer.CinderRandomPlayer( additionalSourceList, additionalSourceWeightList, maximumSourceWeight, contextMenuSource) cinderRandomPlayer.playRandomEpisodes()
def main(): contextMenuSource = sys.listitem.getfilename() # see if the user selected a directory. display an error and exit if the # user selected anything other than a directory jsonRequest = pykodi.get_base_json_request('Files.GetDirectory') jsonRequest['params'] = {'directory': contextMenuSource} jsonResponse = pykodi.execute_jsonrpc(jsonRequest) if 'error' in jsonResponse: xbmcgui.Dialog().notification(addon.getLocalizedString(32400), \ addon.getLocalizedString(32406), \ xbmcgui.NOTIFICATION_WARNING) pykodi.log(str(jsonResponse), xbmc.LOGNOTICE) sys.exit(1) # these parameters do not apply if the user chose the "Run Cinder from here" # context menu option # Changing these variables will not change how Cinder behaves additionalSourceList = [] additionalSourceWeightList = [] maximumSourceWeight = 100 cinderRandomPlayer = CinderRandomPlayer.CinderRandomPlayer(additionalSourceList, additionalSourceWeightList, maximumSourceWeight, contextMenuSource) cinderRandomPlayer.playRandomEpisodes()
def set_season_details(season_id, **season_details): json_request = get_base_json_request('VideoLibrary.SetSeasonDetails') json_request['params'] = season_details json_request['params']['seasonid'] = season_id json_result = pykodi.execute_jsonrpc(json_request) if not _check_json_result(json_result, 'OK', json_request): log(json_result)
def set_tvshow_details(tvshow_id, **tvshow_details): json_request = get_base_json_request('VideoLibrary.SetTVShowDetails') json_request['params'] = tvshow_details json_request['params']['tvshowid'] = tvshow_id json_result = pykodi.execute_jsonrpc(json_request) if not _check_json_result(json_result, 'OK', json_request): log(json_result)
def set_movie_details(movie_id, **movie_details): json_request = get_base_json_request('VideoLibrary.SetMovieDetails') json_request['params'] = movie_details json_request['params']['movieid'] = movie_id json_result = pykodi.execute_jsonrpc(json_request) if not _check_json_result(json_result, 'OK', json_request): log(json_result)
def remove_from_playlist(index, playlistid=xbmc.PLAYLIST_VIDEO): json_request = get_base_json_request('Playlist.Remove') json_request['params']['position'] = index json_request['params']['playlistid'] = playlistid json_result = pykodi.execute_jsonrpc(json_request) if not _check_json_result(json_result, 'OK', json_request): log(json_result, xbmc.LOGWARNING)
def set_episode_details(episode_id, **episode_details): json_request = get_base_json_request('VideoLibrary.SetEpisodeDetails') json_request['params'] = episode_details json_request['params']['episodeid'] = episode_id json_result = pykodi.execute_jsonrpc(json_request) if not _check_json_result(json_result, 'OK', json_request): log(json_result)
def get_sources(media='video'): json_request = get_base_json_request('Files.GetSources') json_request['params']['media'] = media json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'sources', json_request): return json_result['result']['sources'] else: return []
def get_tvshow_details(tvshow_id, properties=None): json_request = get_base_json_request('VideoLibrary.GetTVShowDetails') json_request['params']['tvshowid'] = tvshow_id json_request['params']['properties'] = properties if properties is not None else tvshow_properties json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'tvshowdetails', json_request): return json_result['result']['tvshowdetails']
def get_episode_details(episode_id, properties=None): json_request = get_base_json_request('VideoLibrary.GetEpisodeDetails') json_request['params']['episodeid'] = episode_id json_request['params']['properties'] = properties if properties is not None else episode_properties json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'episodedetails', json_request): return json_result['result']['episodedetails']
def get_tvshows(seriesfilter=None): json_request = get_base_json_request('VideoLibrary.GetTVShows') if seriesfilter: json_request['params']['filter'] = seriesfilter json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'tvshows', json_request): return json_result['result']['tvshows'] else: return []
def get_first_unplayed_episode(tvshow_id): json_request = get_base_json_request('VideoLibrary.GetEpisodes') json_request['params']['tvshowid'] = tvshow_id json_request['params']['properties'] = episode_properties json_request['params']['sort'] = {'method': 'episode'} json_request['params']['filter'] = unplayed_filter json_request['params']['limits'] = {'end': 1} json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'episodes', json_request): return json_result['result']['episodes'][0]
def get_musicvideos(sort_method='sorttitle', ascending=True, limit=None, properties=None): json_request = get_base_json_request('VideoLibrary.GetMusicVideos') json_request['params']['properties'] = properties if properties is not None else musicvideos_properties json_request['params']['sort'] = {'method': sort_method, 'order': 'ascending' if ascending else 'descending'} if limit: json_request['params']['limits'] = {'end': limit} json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'musicvideos', json_request): return json_result['result']['musicvideos'] else: return []
def get_seasons(tvshow_id=-1): json_request = get_base_json_request('VideoLibrary.GetSeasons') if tvshow_id != -1: json_request['params']['tvshowid'] = tvshow_id json_request['params']['properties'] = ['season', 'art'] json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'seasons', json_request): return json_result['result']['seasons'] else: return []
def get_directory(path, limit=None): json_request = get_base_json_request('Files.GetDirectory') json_request['params'] = {'directory': path} json_request['params']['media'] = 'video' json_request['params']['sort'] = {'method': 'random'} json_request['params']['properties'] = ['file', 'playcount', 'lastplayed', 'mimetype'] if limit: json_request['params']['limits'] = {'end': limit} json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'files', json_request): return json_result['result']['files'] else: return []
def get_tvshows(sort_method='sorttitle', ascending=True, limit=None, properties=None, seriesfilter=None): json_request = get_base_json_request('VideoLibrary.GetTVShows') json_request['params']['properties'] = properties if properties is not None else tvshow_properties json_request['params']['sort'] = {'method': sort_method, 'order': 'ascending' if ascending else 'descending'} if limit: json_request['params']['limits'] = {'end': limit} if seriesfilter: json_request['params']['filter'] = seriesfilter json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'tvshows', json_request): return json_result['result']['tvshows'] else: return []
def getRandomEpisodeRecusive(self, fullpath): jsonRequest = pykodi.get_base_json_request('Files.GetDirectory') jsonRequest['params'] = {'directory': fullpath, 'media': 'video'} jsonRequest['params']['properties'] = ['playcount'] jsonResponse = pykodi.execute_jsonrpc(jsonRequest) # pykodi.log(str(jsonResponse), xbmc.LOGDEBUG) if 'result' in jsonResponse and 'files' in jsonResponse['result']: # leverage pythons random library to shuffle a list of indicies # to get a random file / directory fileEntryList = list(jsonResponse['result']['files']) fileEntryIndexList = range(0, len(fileEntryList)) random.shuffle(fileEntryIndexList) random.shuffle(fileEntryIndexList) random.shuffle(fileEntryIndexList) for index in fileEntryIndexList: fileEntry = fileEntryList[index] # recurse down directories if self.isDirectory(fileEntry): if fileEntry['label'] in ('extrafanart', 'extrathumbs'): continue subdirectoryResult = self.getRandomEpisodeRecusive(fileEntry['file']) if len(subdirectoryResult) == 0: # didn't find anything in the subdirectory continue else: # found something in the subdirectory return subdirectoryResult # this is a file see if we can play it if self.shouldPlayFile(fileEntry): # yes it can be played return [ fileEntry ] else: # no it can't be played continue # we have walked off of the end of the 'files' list so return an empty list elif 'error' in jsonResponse: xbmcgui.Dialog().notification(self.addon.getLocalizedString(32400), self.addon.getLocalizedString(32402) + fullpath, xbmcgui.NOTIFICATION_WARNING) pykodi.log(jsonResponse, xbmc.LOGDEBUG) xbmc.executebuiltin('Dialog.Close(busydialog)') sys.exit(1) return []
def get_random_musicvideos(filters=None, limit=None): json_request = get_base_json_request('VideoLibrary.GetMusicVideos') json_request['params']['sort'] = {'method': 'random'} json_request['params']['properties'] = ['file'] if limit: json_request['params']['limits'] = {'end': limit} if filters: json_request['params']['filter'] = filter_and(*filters) json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'musicvideos', json_request): return json_result['result']['musicvideos'] else: return []
def get_episodes(tvshow_id=None, sort_method='episode', ascending=True, limit=None, properties=None, episodefilter=None): json_request = get_base_json_request('VideoLibrary.GetEpisodes') if tvshow_id: json_request['params']['tvshowid'] = tvshow_id json_request['params']['properties'] = properties if properties is not None else episode_properties json_request['params']['sort'] = {'method': sort_method, 'order': 'ascending' if ascending else 'descending'} if limit: json_request['params']['limits'] = {'end': limit} if episodefilter: json_request['params']['filter'] = episodefilter json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'episodes', json_request): return json_result['result']['episodes'] else: return []
def get_random_episodes(tvshow_id=None, season=None, filters=None, limit=None): json_request = get_base_json_request('VideoLibrary.GetEpisodes') if tvshow_id: json_request['params']['tvshowid'] = tvshow_id if season is not None: json_request['params']['season'] = season json_request['params']['sort'] = {'method': 'random'} json_request['params']['properties'] = ['file'] if limit: json_request['params']['limits'] = {'end': limit} if filters: json_request['params']['filter'] = filter_and(*filters) json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, 'episodes', json_request): return json_result['result']['episodes'] else: return []
def jsonrpc_introspect(): json_request = get_base_json_request('JSONRPC.Introspect') json_result = pykodi.execute_jsonrpc(json_request) log(json_result)
def get_application_properties(properties): json_request = get_base_json_request('Application.GetProperties') json_request['params']['properties'] = properties json_result = pykodi.execute_jsonrpc(json_request) if _check_json_result(json_result, None, json_request): return json_result['result']