def get_active_playerid(): res = _kodi_rpc({ "jsonrpc": "2.0", "method": "Player.GetActivePlayers", "id": 1 }) players = _get(res, 'result') if not players: return None players = [player for player in players if _get(player, 'type') == 'video'] if not players: return None return players[0]['playerid']
def get_next_unwatched_episode(tvshow_id): res = _kodi_rpc({ "jsonrpc": "2.0", "method": 'VideoLibrary.GetEpisodes', "id": 1, 'params': { 'tvshowid': tvshow_id, 'filter': { "operator": "lessthan", "field": "playcount", "value": "1" }, 'sort': { "method": "episode", "order": "ascending" }, 'properties': ['playcount'], 'limits': { 'start': 0, 'end': 1 }, } }) episodes = _get(res, 'result', 'episodes') if not episodes: return None return episodes[0]['episodeid']
def get_tv_shows(): res = _kodi_rpc({ "jsonrpc": "2.0", "method": 'VideoLibrary.GetTVShows', "id": 1, 'params': { 'properties': ['title', 'genre', 'cast'] } }) return _get(res, 'result', 'tvshows') or []
def get_muted(): res = _kodi_rpc({ "jsonrpc": "2.0", "method": "Application.GetProperties", "params": { "properties": ["muted"], }, "id": 1, }) return _get(res, 'result', 'muted')
def set_mute(mute): res = _kodi_rpc({ "jsonrpc": "2.0", "method": "Application.SetMute", "params": { "mute": mute, }, "id": 1, }) return _get(res, 'result')
def get_volume(): res = _kodi_rpc({ "jsonrpc": "2.0", "method": "Application.GetProperties", "params": { "properties": ["volume"], }, "id": 1, }) return _get(res, 'result', 'volume')
def set_volume(volume): res = _kodi_rpc({ "jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": volume, }, "id": 1, }) return _get(res, 'result')
def seek_to_percentage(playerid, percentage): res = _kodi_rpc({ "jsonrpc": "2.0", "method": "Player.Seek", "params": { "percentage": percentage, "playerid": playerid, }, "id": 1, }) return _get(res, 'result')
def get_tvshow_details(tvshowid): res = _kodi_rpc({ "jsonrpc": "2.0", "method": "VideoLibrary.GetTVShowDetails", "id": 1, "params": { "tvshowid": int(tvshowid), "properties": ["title", "genre", "fanart", "art", "thumbnail", "file", "plot"] } }) return _get(res, 'result', 'tvshowdetails')
def get_movie_details(movieid): res = _kodi_rpc({ "jsonrpc": "2.0", "method": "VideoLibrary.GetMovieDetails", "id": 1, "params": { "movieid": int(movieid), "properties": ["title", "genre", "fanart", "art", "thumbnail", "file", "plot"] } }) return _get(res, 'result', 'moviedetails')
def get_episodes_for_season(tvshow_id, season_num): res = _kodi_rpc({ "jsonrpc": "2.0", "method": 'VideoLibrary.GetEpisodes', "id": 1, 'params': { 'tvshowid': tvshow_id, 'season': season_num, 'properties': ['episode'], } }) return _get(res, 'result', 'episodes')
def get_current_item(playerid): res = _kodi_rpc({ "jsonrpc": "2.0", "method": "Player.GetItem", "params": { "properties": ["title", "season", "episode", "duration", "tvshowid", "set"], "playerid": playerid }, "id": "VideoGetItem", }) return _get(res, 'result', 'item')
def get_player_time(playerid): if not playerid: return None res = _kodi_rpc({ "jsonrpc": "2.0", "method": "Player.GetProperties", "id": 1, 'params': { 'playerid': playerid, "properties": ["time"], }, }) return _get(res, 'result', 'time')
def is_player_playing(playerid): if not playerid: return None res = _kodi_rpc({ "jsonrpc": "2.0", "method": "Player.GetProperties", "id": 1, 'params': { 'playerid': playerid, 'properties': ['speed'] } }) speed = _get(res, 'result', 'speed') if speed is None: return None return speed != 0
def get_current_item(): player_id = kodi_rpc.get_active_playerid() if not player_id: return None item = kodi_rpc.get_current_item(player_id) logger.debug('Current item: {}'.format(str(item))) item_type = _get(item, 'type') if item_type == 'movie': return { 'type': item_type, 'movieid': item['id'], } elif item_type == 'episode': return { 'type': item_type, 'episodeid': item['id'], 'tvshowid': item['tvshowid'], 'season': item['season'], 'episode': item['episode'], } return None