当前位置: 首页>>代码示例>>Python>>正文


Python m3u8.load方法代码示例

本文整理汇总了Python中m3u8.load方法的典型用法代码示例。如果您正苦于以下问题:Python m3u8.load方法的具体用法?Python m3u8.load怎么用?Python m3u8.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在m3u8的用法示例。


在下文中一共展示了m3u8.load方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def __init__(self, uri, timeout=None, headers=None,
                 ffmpeg_path='ffmpeg', ffmpeg_loglevel='quiet'):
        """Initialize a M3U8 Downloader.

        Args:
            uri (:obj:`str`): The URI of the m3u8 file.
            timeout (:obj:`int`, optional): The timeout used when loading
                from uri. Defaults to ``None``.
            headers (:obj:`list` of :obj:`str`, optional): The headers used
                when loading from uri. Defaults to ``None``.
            ffmpeg_path (:obj:`str`, optional): The path to ffmpeg executable.
                Defaults to ``ffmpeg``.
            ffmpeg_loglevel (:obj:`str`, optional): The logging level of
                ffmpeg. Defaults to ``quiet``.
        """
        if not headers:
            headers = {}

        self.uri = uri
        self.ffmpeg_path = ffmpeg_path
        self.ffmpeg_loglevel = ffmpeg_loglevel
        self.m3u8 = m3u8.load(uri=uri, timeout=timeout, headers=headers) 
开发者ID:lcy0321,项目名称:m3u8-downloader,代码行数:24,代码来源:m3u8_downloader.py

示例2: __init__

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def __init__(self, uri, timeout=None, headers=None,
                 ffmpeg_path=r'C:\Program Files (x86)\ffmpeg-4.0.2\bin\ffmpeg.exe', ffmpeg_loglevel='quiet'):
        """Initialize a M3U8 Downloader.

        Args:
            uri (:obj:`str`): The URI of the m3u8 file.
            timeout (:obj:`int`, optional): The timeout used when loading
                from uri. Defaults to ``None``.
            headers (:obj:`list` of :obj:`str`, optional): The headers used
                when loading from uri. Defaults to ``None``.
            ffmpeg_path (:obj:`str`, optional): The path to ffmpeg executable.
                Defaults to ``ffmpeg``.
            ffmpeg_loglevel (:obj:`str`, optional): The logging level of
                ffmpeg. Defaults to ``quiet``.
        """
        if not headers:
            headers = {}

        self.uri = uri
        self.ffmpeg_path = ffmpeg_path
        self.ffmpeg_loglevel = ffmpeg_loglevel
        self.m3u8 = m3u8.load(uri=uri, timeout=timeout, headers=headers) 
开发者ID:zachMelody,项目名称:bilibili-live-recorder,代码行数:24,代码来源:m3u8_downloader.py

示例3: main

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def main(url):
    m = m3u8.load(url)
    #
    print('请输入序号,你想看哪个清晰度:')
    for i, pl in enumerate(m.playlists):
        print(f"{i}:{pl.stream_info.resolution}")
    indexs: str = input('请输入序号,你想看哪个清晰度(默认720p-2):')
    indexs = '2' if indexs == '' else indexs
    if indexs.isnumeric():
        idx = int(indexs)
        pl = m.playlists[idx]
        m2 = m3u8.load(pl.absolute_uri)
        print('开始下载 ts列表...')
        for sm in m2.segments:
            url2 = sm.absolute_uri
            print(url2)
            urlretrieve(url2, sm.uri)
        print('下载完毕')

        # 合并ts片段,存为与文件夹同名的ts文件
        print('开始合并文件:')
        fn = input('输入文件名:')
        fn = f"{randint(1000, 9999)}" if fn == '' else fn
        fn = fn + '.mp4'

        with open(fn, 'wb') as f:
            for sm in m2.segments:
                # file_path = os.path.join(directory, f'{n}.ts')
                with open(sm.uri, 'rb') as g:
                    f.write(g.read())
        print('合并文件完毕。。。')

        #
        cmds = f'/Applications/IINA.app/Contents/MacOS/iina-cli ' + fn
        input(f'打开?{cmds}')  # TODO
        system(cmds)

    pass 
开发者ID:makelove,项目名称:Python_Master_Courses,代码行数:40,代码来源:download_m3u8.py

示例4: load_m3u8_playlist

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def load_m3u8_playlist(url):
        stream_types = []
        streams = {}
        m = m3u8.load(url, headers=fake_headers).playlists
        for l in m:
            stream_types.append(str(l.stream_info.bandwidth))
            streams[str(l.stream_info.bandwidth)] = {'container': 'm3u8', 'video_profile': str(l.stream_info.bandwidth), 'src' : [l.absolute_uri], 'size': 0}
        stream_types.sort()
        return stream_types, streams 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:11,代码来源:m3u8_wrap.py

示例5: load_m3u8

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def load_m3u8(url):
        urls = []
        m =  m3u8.load(url, headers=fake_headers)
        for seg in m.segments:
            urls.append(seg.absolute_uri)
        return urls 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:8,代码来源:m3u8_wrap.py

示例6: load_live_m3u8

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def load_live_m3u8(url):
        """
        the stream is live stream. so we use sleep to simulate player. but not perfact!
        """
        global __lenth__
        m =  m3u8.load(url, headers=fake_headers)
        __lenth__ = now = d = 0
        i = 0
        m3u8_live_stopper()
        while True:
            if stop:
                print('stopped!!')
                raise StopIteration
            if i < len(m.segments):
                delta = d -( time.time() - now)
                if (delta) > 0:
                    time.sleep(delta)
                segurl = m.segments[i].absolute_uri
                now = time.time()
                d = m.segments[i].duration
                i += 1
                __lenth__ += 1
                yield segurl
            else:
                i = 0
                delta = d -( time.time() - now)
                if (delta) > 0:
                    time.sleep(d - (time.time() - now))
                m = m3u8.load(url, headers=fake_headers)
                now = time.time()
                d = 0 
开发者ID:ForgQi,项目名称:bilibiliupload,代码行数:33,代码来源:m3u8_wrap.py

示例7: find_best_video

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def find_best_video(uri):
    playlist = m3u8.load(uri)
    if not playlist.is_variant:
        return playlist
    best_stream = playlist.playlists[0]
    for stream in playlist.playlists:
        if stream.stream_info.bandwidth == 'max' or stream.stream_info.bandwidth > best_stream.stream_info.bandwidth:
            best_stream = stream
    return find_best_video(best_stream.absolute_uri) 
开发者ID:einstein95,项目名称:crunchy-xml-decoder,代码行数:11,代码来源:hls.py

示例8: __init__

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def __init__(self, index_url: str):
        self.playlist = m3u8.load(index_url)
        if len(self.playlist.playlists) > 0:
            bw_uri = sorted(
                [
                    (
                        p.absolute_uri,
                        int(p.stream_info.bandwidth)
                    )
                    for p in self.playlist.playlists
                ],
                key=lambda bu: -bu[1]
            )
            log.info(f"Multi playlists found, loading the video which bandwidth={bw_uri[0][1]} uri={bw_uri[0][0]}")
            self.playlist = m3u8.load(bw_uri[0][0])
        if len(self.playlist.keys) == 1:
            key = self.playlist.keys[0]
            if not key.method.startswith("AES"):
                raise Exception(f"Unsupported crypt method: {key.method}")
            else:
                log.info(f"Key found, method={key.method}")
            _aes = AES.new(http_get(key.absolute_uri), AES.MODE_CBC)
            self._crypto_func = lambda data: _aes.decrypt(data)
        elif len(self.playlist.keys) == 0:
            log.info("No keys found in index file.")
            self._crypto_func = lambda data: data
        else:
            raise Exception(f"Too much ({len(self.playlist.keys)}) keys found.") 
开发者ID:TsingJyujing,项目名称:DataSpider,代码行数:30,代码来源:hls.py

示例9: test_create_iframe_playlist

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def test_create_iframe_playlist(self):
        iframe_playlist_uri = 'bigbuckbunny-400k-iframes.m3u8'
        iframe_playlist_content = IFRAME_PLAYLIST_400K
        master_playlist = m3u8.load(
            SAMPLES_PATH + 'original_video/bigbuckbunny.m3u8'
        )
        _, results = create_iframe_playlist(master_playlist.playlists[0])
        self.assertEqual(iframe_playlist_uri, results['uri'])
        self.assertEqual(iframe_playlist_content, results['content']) 
开发者ID:pbs,项目名称:iframe-playlist-generator,代码行数:11,代码来源:test_iframeplaylistgenerator.py

示例10: update_for_iframes

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def update_for_iframes(url):
    """
    Returns an updated master playlist and new I-frame playlists
    """
    try:
        master_playlist = m3u8.load(url)
    except IOError:
        raise PlaylistLoadError('Invalid url')

    if not master_playlist or not master_playlist.is_variant:
        raise BadPlaylistError('Not a variant playlist')

    master_playlist.iframe_playlists[:] = []

    uri = url.split('/')[-1]
    result = {'master_uri': uri,
              'master_content': None,
              'iframe_playlists': []}

    for playlist in master_playlist.playlists:
        iframe_playlist, data = create_iframe_playlist(playlist)
        if iframe_playlist is None or data is None:
            continue
        master_playlist.add_iframe_playlist(iframe_playlist)
        result['iframe_playlists'].append(data)

    result['master_content'] = master_playlist.dumps()
    return result 
开发者ID:pbs,项目名称:iframe-playlist-generator,代码行数:30,代码来源:generator.py

示例11: get_video_url

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def get_video_url(self, video_id, maxHeight=-1):
        oldSessionId = self.session_id
        self.session_id = self.http_video_session_id
        maxVideoHeight = maxHeight if maxHeight > 0 else self._config.maxVideoHeight
        media = None
        try:
            if self._config.forceHttpVideo:
                quality = 'LOW' if self._config.maxVideoHeight < 480 else 'MEDIUM' if self._config.maxVideoHeight < 720 else 'HIGH'
                media = Session.get_video_url(self, video_id, quality=quality)
        except requests.HTTPError as e:
            r = e.response
            msg = _T(30505)
            try:
                msg = r.reason
                msg = r.json().get('userMessage')
            except:
                pass
            log('HTTP-Error: ' + msg, xbmc.LOGERROR)
            log('Got no HTTP Stream for Video ID %s, using HLS Stream ...' % video_id, xbmc.LOGERROR)
            xbmcgui.Dialog().notification(plugin.name, _T(30510), xbmcgui.NOTIFICATION_WARNING)
        if not media:
            # Using HLS-Stream 
            self.session_id = self.stream_session_id
            media = Session.get_video_url(self, video_id, quality=None)
        if maxVideoHeight <> 9999 and media.url.lower().find('.m3u8') > 0:
            log('Parsing M3U8 Playlist: %s' % media.url)
            m3u8obj = m3u8_load(media.url)
            if m3u8obj.is_variant and not m3u8obj.cookies:
                # Variant Streams with Cookies have to be played without stream selection.
                # You can change the Bandwidth Limit in Kodi Settings to select other streams !
                # Select stream with highest resolution <= maxVideoHeight
                selected_height = 0
                selected_bandwidth = -1
                for playlist in m3u8obj.playlists:
                    try:
                        width, height = playlist.stream_info.resolution
                        bandwidth = playlist.stream_info.average_bandwidth
                        if not bandwidth:
                            bandwidth = playlist.stream_info.bandwidth
                        if not bandwidth:
                            bandwidth = 0
                        if (height > selected_height or (height == selected_height and bandwidth > selected_bandwidth)) and height <= maxVideoHeight:
                            if re.match(r'https?://', playlist.uri):
                                media.url = playlist.uri
                            else:
                                media.url = m3u8obj.base_uri + playlist.uri
                            if height == selected_height and bandwidth > selected_bandwidth:
                                log('Bandwidth %s > %s' % (bandwidth, selected_bandwidth))
                            log('Selected %sx%s %s: %s' % (width, height, bandwidth, playlist.uri.split('?')[0].split('/')[-1]))
                            selected_height = height
                            selected_bandwidth = bandwidth
                            media.width = width
                            media.height = height
                            media.bandwidth = bandwidth
                        elif height > maxVideoHeight:
                            log('Skipped %sx%s %s: %s' % (width, height, bandwidth, playlist.uri.split('?')[0].split('/')[-1]))
                    except:
                        pass
        self.session_id = oldSessionId
        return media 
开发者ID:arnesongit,项目名称:plugin.audio.tidal2,代码行数:62,代码来源:koditidal.py

示例12: create_iframe_playlist

# 需要导入模块: import m3u8 [as 别名]
# 或者: from m3u8 import load [as 别名]
def create_iframe_playlist(playlist):
    """
    Creates a new I-frame playlist.
    """
    try:
        subprocess.check_output('ffprobe -version', stderr=subprocess.STDOUT,
                                shell=True)
    except subprocess.CalledProcessError:
        raise DependencyError('FFmpeg not installed correctly')

    iframe_playlist = generate_m3u8_for_iframes()

    total_bytes = 0
    total_duration = 0

    try:
        stream = m3u8.load(playlist.absolute_uri)
    except IOError:
        raise PlaylistLoadError('Invalid stream url')
    except AttributeError:
        raise BadPlaylistError('Invalid playlist - no absolute uri')

    for segment in stream.segments:

        iframe_segments, s_bytes, s_duration = create_iframe_segments(segment)

        for iframe_segment in iframe_segments:
            iframe_playlist.add_segment(iframe_segment)

        total_bytes += s_bytes
        total_duration += s_duration

    if total_bytes != 0 and total_duration != 0:
        iframe_bandwidth = str(int(total_bytes / total_duration * 8))
    else:
        return (None, None)

    iframe_codecs = convert_codecs_for_iframes(playlist.stream_info.codecs)
    stream_info = {'bandwidth': iframe_bandwidth,
                   'codecs': iframe_codecs}
    iframe_playlist_uri = playlist.uri.replace('.m3u8', '-iframes.m3u8')

    new_iframe_playlist = m3u8.IFramePlaylist(base_uri=playlist.base_uri,
                                              uri=iframe_playlist_uri,
                                              iframe_stream_info=stream_info)

    return (new_iframe_playlist, {'uri': iframe_playlist_uri,
                                  'content': iframe_playlist.dumps()}) 
开发者ID:pbs,项目名称:iframe-playlist-generator,代码行数:50,代码来源:generator.py


注:本文中的m3u8.load方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。