Example #1
0
def play(source, player=True):
    if player == 'remote':
        remote_play(source)
    else:
        if source['content_type'] == 'image':
            command = {'jsonrpc': '2.0', 'id': 1, 'method': 'Player.Open', 'params': {'item': {'file': source['url']}}}
            log_utils.log('Play using jsonrpc method Player.Open: |{0!s}|'.format(source['url']), log_utils.LOGDEBUG)
            response = kodi.execute_jsonrpc(command)
        else:
            playback_item = kodi.ListItem(label=source['info']['title'], path=source['url'])
            playback_item.setProperty('IsPlayable', 'true')
            playback_item.setArt(source['art'])
            playback_item.addStreamInfo(source['content_type'], {})
            if source['is_dash']:
                playback_item.setContentLookup(False)
                playback_item.setMimeType('application/xml+dash')
                playback_item.setProperty('inputstreamaddon', 'inputstream.adaptive')
                playback_item.setProperty('inputstream.adaptive.manifest_type', 'mpd')
            elif (source['url'].startswith('rtmp')) and (inputstream_rtmp):
                if kodi.addon_enabled('inputstream.rtmp'):
                    playback_item.setProperty('inputstreamaddon', 'inputstream.rtmp')
            elif ('.m3u8' in source['url']) and (hls_supported):
                    playback_item.setProperty('inputstreamaddon', 'inputstream.adaptive')
                    playback_item.setProperty('inputstream.adaptive.manifest_type', 'hls')
            playback_item.setInfo(source['content_type'], source['info'])
            if player:
                log_utils.log('Play using Player(): |{0!s}|'.format(source['url']), log_utils.LOGDEBUG)
                kodi.Player().play(source['url'], playback_item)
            else:
                log_utils.log('Play using set_resolved_url: |{0!s}|'.format(source['url']), log_utils.LOGDEBUG)
                kodi.set_resolved_url(playback_item)
Example #2
0
    def find_episode(show_id, season, episode):
        request = {
            'jsonrpc': '2.0',
            'params': {
                'tvshowid': int(show_id),
                'season': int(season),
                'sort': {
                    'method': 'label',
                    'order': 'ascending',
                    'ignorearticle': True
                },
                'filter': {
                    'operator': 'is',
                    'field': 'episode',
                    'value': str(episode)
                },
                'properties': ['file'],
                'limits': {
                    'start': 0,
                    'end': 1
                }
            },
            'method': 'VideoLibrary.GetEpisodes',
            'id': 'libTVShows'
        }

        response = kodi.execute_jsonrpc(request)
        log_utils.log('GetEpisodes Response |%s|' %
                      json.dumps(response, indent=4))

        result = response.get('result', {})
        episode = result.get('episodes', [{'file': None}])[0]
        file_path = episode.get('file', None)

        return file_path
Example #3
0
    def season_exists(show_id, season):
        request = {
            'jsonrpc': '2.0',
            'params': {
                'tvshowid': int(show_id),
                'sort': {
                    'method': 'label',
                    'order': 'ascending',
                    'ignorearticle': True
                },
                'properties': ['season']
            },
            'method': 'VideoLibrary.GetSeasons',
            'id': 'libTVShows'
        }

        response = kodi.execute_jsonrpc(request)
        log_utils.log('GetSeasons Response |%s|' %
                      json.dumps(response, indent=4))

        result = response.get('result', {})
        seasons = result.get('seasons', [])

        exists = False
        for s in seasons:
            if s.get('season') == int(season):
                exists = True
                break

        return exists
Example #4
0
def _is_debugging():
    command = {'jsonrpc': '2.0', 'id': 1, 'method': 'Settings.getSettings', 'params': {'filter': {'section': 'system', 'category': 'logging'}}}
    js_data = kodi.execute_jsonrpc(command)
    for item in js_data.get('result', {}).get('settings', {}):
        if item['id'] == 'debug.showloginfo':
            return item['value']
    
    return False
def _is_debugging():
    command = {'jsonrpc': '2.0', 'id': 1, 'method': 'Settings.getSettings', 'params': {'filter': {'section': 'system', 'category': 'logging'}}}
    js_data = kodi.execute_jsonrpc(command)
    for item in js_data.get('result', {}).get('settings', {}):
        if item['id'] == 'debug.showloginfo':
            return item['value']
    
    return False
Example #6
0
def __get_show_year(title):
    filter_params = {'field': 'title', 'operator': 'contains', 'value': title}
    properties = ['title', 'year']
    sort = {'order': 'ascending', 'method': 'label', 'ignorearticle': True}
    limits = {'start': 0, 'end': 25}
    params = {'filter': filter_params, 'properties': properties, 'sort': sort, 'limits': limits}
    cmd = {'jsonrpc': '2.0', 'method': 'VideoLibrary.GetTVShows', 'params': params, 'id': 'libTvShows'}
    meta = kodi.execute_jsonrpc(cmd)
    logger.log('Search Meta: %s' % (meta), log_utils.LOGDEBUG)
    try: return meta['result']['tvshows'][0]['year']
    except (KeyError, IndexError): return None
Example #7
0
    def get_tvshow_id(title, year, imdb):
        request = {
            'jsonrpc': '2.0',
            'params': {
                'sort': {
                    'method': 'title',
                    'order': 'ascending',
                    'ignorearticle': True
                },
                'filter': {
                    'and': [{
                        'operator': 'contains',
                        'field': 'title',
                        'value': title
                    }, {
                        'operator': 'is',
                        'field': 'year',
                        'value': year
                    }]
                },
                'properties': ['imdbnumber'],
                'limits': {
                    'start': 0,
                    'end': 25
                }
            },
            'method': 'VideoLibrary.GetTVShows',
            'id': 'libTVShows'
        }
        response = kodi.execute_jsonrpc(request)
        log_utils.log('GetTVShows Response |%s|' %
                      json.dumps(response, indent=4))

        result = response.get('result', {})
        tvshows = result.get('tvshows', [{
            'tvshowid': None,
            'imdbnumber': None
        }])
        tvshow_id = None
        for show in tvshows:
            if imdb == show.get('imdbnumber', None):
                tvshow_id = show.get('tvshowid', None)
                break

        return tvshow_id
Example #8
0
    def find_movie(title, year, imdb):
        request = {
            'jsonrpc': '2.0',
            'params': {
                'sort': {
                    'method': 'title',
                    'order': 'ascending',
                    'ignorearticle': True
                },
                'filter': {
                    'and': [{
                        'operator': 'contains',
                        'field': 'title',
                        'value': title
                    }, {
                        'operator': 'is',
                        'field': 'year',
                        'value': year
                    }]
                },
                'properties': ['file', 'imdbnumber'],
                'limits': {
                    'start': 0,
                    'end': 25
                }
            },
            'method': 'VideoLibrary.GetMovies',
            'id': 'libMovies'
        }
        response = kodi.execute_jsonrpc(request)
        log_utils.log('GetMovies Response |%s|' %
                      json.dumps(response, indent=4))

        result = response.get('result', {})
        movies = result.get('movies', [{'file': None, 'imdbnumber': None}])
        file_path = None
        for movie in movies:
            if imdb == movie.get('imdbnumber', None):
                file_path = movie.get('file', None)
                break

        return file_path
Example #9
0
def __get_widget_details(filename, title, year):
    if not isinstance(title, unicode): title = title.decode('utf-8')
    path = ''
    media_type = None

    try:
        _filename, extra = filename.split('?')
    except:
        _filename, extra = filename.split('?')[0], ''
    tokens = _filename.split('/')
    queries = kodi.parse_query(extra)
    for value in queries.itervalues():
        try:
            js_data = json.loads(value)
        except:
            js_data = {}
        js_type = js_data.get('type')
        if js_type == 'tvshows':
            media_type = VIDEO_TYPES.TVSHOW
            break
        elif js_type == 'episodes':
            media_type = VIDEO_TYPES.EPISODE
            break
        elif js_type == 'movies':
            media_type = VIDEO_TYPES.MOVIE
            break
    else:
        for token in tokens:
            if 'movie' in token:
                media_type = VIDEO_TYPES.MOVIE
                break
            elif 'tvshow' in token:
                media_type = VIDEO_TYPES.TVSHOW
                break
            elif 'episode' in token:
                media_type = VIDEO_TYPES.EPISODE
                break

    if media_type == VIDEO_TYPES.MOVIE:
        lib_id = 'libMovies'
        method = 'VideoLibrary.GetMovieDetails'
        id_type = 'movieid'
        details = 'moviedetails'
        properties = ['file', 'title', 'year']
    elif media_type == VIDEO_TYPES.TVSHOW:
        lib_id = 'libTvShows'
        method = 'VideoLibrary.GetTVShowDetails'
        id_type = 'tvshowid'
        details = 'tvshowdetails'
        properties = ['file', 'title', 'year']
    elif media_type == VIDEO_TYPES.EPISODE:
        lib_id = 'libTvShows'
        method = 'VideoLibrary.GetEpisodeDetails'
        id_type = 'episodeid'
        details = 'episodedetails'
        properties = ['file', 'title']

    if media_type is not None:
        for token in tokens:
            if token.isdigit():
                cmd = {
                    'jsonrpc': '2.0',
                    'method': method,
                    'params': {
                        id_type: int(token),
                        'properties': properties
                    },
                    'id': lib_id
                }
                response = kodi.execute_jsonrpc(cmd)
                logger.log('Details Result: %s' % (response),
                           log_utils.LOGDEBUG)
                if 'result' in response and details in response['result']:
                    details = response['result'][details]
                    if details['title'] == title and ('year' not in details or
                                                      details['year'] == year):
                        path = details['file']

    logger.log('Widget ID: |%s| -> (%s): |%s|' % (filename, media_type, path))
    return media_type, path