main.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:plugin.video.areena 作者: hirsivaja 项目源码 文件源码
def play_stream(path):
    """
    Play a stream by the provided path.
    :param path: stream id
    :return: None
    """
    data = get_item(path)
    report_url = None
    subtitle_list = []
    for publication in data['publicationEvent']:
        if publication['temporalStatus'] == 'currently' and publication['type'] == 'OnDemandPublication':
            log("Found correct publication, media id: " + publication['media']['id'])
            media_id = publication['media']['id']
            report_url = get_report_url(path, media_id)
            protocol = 'HLS'
            media_is_audio = publication['media']['type'] == 'AudioObject'
            if media_is_audio:
                protocol = 'PMD'
            playout_data = get_playout(path, media_id, protocol)
            encrypted_url = playout_data[0]['url']
            subtitles = playout_data[0]['subtitles']
            for subtitle in subtitles:
                subtitle_list.append(subtitle['uri'])
            path = decrypt_url(encrypted_url)
            log("decrypted path: " + path)
            if int(_addon.getSetting("maxResolution")) > 0 and not media_is_audio:
                path = get_resolution_specific_url(path)
                log("modified path: " + path)
            break
    # Create a playable item with a path to play.
    play_item = xbmcgui.ListItem(path=path)
    play_item.setSubtitles(subtitle_list)
    # Report usage to YLE
    response = get_url_response(report_url)
    if response.getcode() != 200:
        log("Could not report usage. Got code {0}".format(response.getcode()), xbmc.LOGWARNING)
    if _addon.getSetting("noSubtitlesForDefaultLangAudio") == 'true':
        disable_subtitles = False
        if 'audio' in data:
            for audio in data['audio']:
                if 'language' in audio:
                    for language in audio['language']:
                        if language == get_language_codes()[0]:
                            disable_subtitles = True
        if disable_subtitles:
            xbmcplugin.endOfDirectory(_handle, True, False, False)
            player = xbmc.Player()
            player.play(item=path, listitem=play_item)
            tries = 10
            while tries > 0:
                time.sleep(1)
                tries -= 1
                if player.isPlaying():
                    break
            player.showSubtitles(False)
            return
    # Pass the item to the Kodi player.
    xbmcplugin.setResolvedUrl(_handle, True, listitem=play_item)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号