예제 #1
0
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']
예제 #2
0
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']
예제 #3
0
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 []
예제 #4
0
def get_muted():
    res = _kodi_rpc({
        "jsonrpc": "2.0",
        "method": "Application.GetProperties",
        "params": {
            "properties": ["muted"],
        },
        "id": 1,
    })

    return _get(res, 'result', 'muted')
예제 #5
0
def set_mute(mute):
    res = _kodi_rpc({
        "jsonrpc": "2.0",
        "method": "Application.SetMute",
        "params": {
            "mute": mute,
        },
        "id": 1,
    })

    return _get(res, 'result')
예제 #6
0
def get_volume():
    res = _kodi_rpc({
        "jsonrpc": "2.0",
        "method": "Application.GetProperties",
        "params": {
            "properties": ["volume"],
        },
        "id": 1,
    })

    return _get(res, 'result', 'volume')
예제 #7
0
def set_volume(volume):
    res = _kodi_rpc({
        "jsonrpc": "2.0",
        "method": "Application.SetVolume",
        "params": {
            "volume": volume,
        },
        "id": 1,
    })

    return _get(res, 'result')
예제 #8
0
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')
예제 #9
0
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')
예제 #10
0
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')
예제 #11
0
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')
예제 #12
0
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')
예제 #13
0
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')
예제 #14
0
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
예제 #15
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