common.py 文件源码

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

项目:repository.midraal 作者: midraal 项目源码 文件源码
def dl_stream(url):
    html = koding.Open_URL(url)
    match = re.findall("hls:.*?'(.*?)'", html)
    dp = xbmcgui.DialogProgressBG()
    dp.create(addon_name, "Downloading")
    for stream in match:
        if "bumper" in stream:
            continue
        stream_ext = stream.split("/")[-1]
        base_stream = stream.replace(stream_ext, "")
        m3u8 = koding.Open_URL(stream)
        lines = m3u8.splitlines()
        num_lines = len(lines)
        for index, line in enumerate(lines):
            percent = int((index * 100) / num_lines)
            dp.update(percent, addon_name, "Downloading")
            if not line.endswith(".m3u8"):
                continue
            sub_m3u8 = koding.Open_URL(base_stream + line)
            for sub_line in sub_m3u8.splitlines():
                if not sub_line.endswith(".ts"):
                    continue
                ts = requests.get(base_stream + sub_line.strip()).content
                path = "test.avi"
                if os.path.isfile(path):
                    mode = "ab"
                else:
                    mode = "wb"
                with open(path, mode) as outfile:
                    outfile.write(ts)
    koding.Text_Box(addon_name, "Finished Downloading")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号