• python:m3u8转mp4


    import re,requests,time,os
    
    import threadpool
    
    
    
    res = requests.get(url="http://pili-vod.tebaobao.vip/recordings/z1.tebaobao.tbb_dev5_4706464/f1610716867.m3u8").text
    
    # print(res)
    m3u8_res = re.findall('/fragments(.*?)ts',res)
    m_res = re.findall('fragments/z1.tebaobao.tbb_dev5_4706464/(.*?)ts',res)
    li = []
    # print(m3u8_res)
    for i in range(len(m3u8_res)):
        m3_res = "http://pili-vod.tebaobao.vip/fragments" +m3u8_res[i] + "ts"
        li.append(m3_res)
    
    print(li)
    print(len(li))
    
    w_li = []
    for i in range(len(m3u8_res)):
        m3u_res = m_res[i] + "ts"
        w_li.append(m3u_res)
    
    print(w_li)
    
    
    
    r = requests.get(url='http://pili-vod.tebaobao.vip/fragments/z1.tebaobao.tbb_dev5_4706464/1610711419540-1610711423167.ts')
    print(r.content)
    c = 0
    def download(c):
    
    
        for i in range(len(li)):
            with open("/Users/apple/Desktop/test/" + str(c) + ".ts","wb")as f:
                try:
                    r = requests.get(url = li[i])
    
                    f.write(r.content)
                    print("下载成功!,第%d次"%c)
                except:
                    print('请求失败!')
            c=c+1
    
    
    
    def get_video():
        files = os.listdir("/Users/apple/Desktop/test/")
        # print(files)
        aa = 0
        for file in range(len(li)):
    
            with open("/Users/apple/Desktop/test/" + str(aa) + ".ts", 'rb') as f1:
                with open("1.mp4", 'ab') as f2:
                    f2.write(f1.read())
    
            aa = aa+1
    
    get_video()
    
    # if __name__ == '__main__':
    #
    #     start_time = time.time()
    #     pool = threadpool.ThreadPool(1000)
    #     results = threadpool.makeRequests(download,args_list=range(1))
    #     [pool.putRequest(req) for req in results]  # 多线程一块执行
    #     pool.wait()  # 线程挂起,直到结束
  • 相关阅读:
    Codeforces Round #665 (Div. 2) C. Mere Array 数论,思维
    Codeforces Round #665 (Div. 2) B
    ZOJ
    HDU-2158 最短区间版大家来找茬 模拟 尺取
    HDU-1082 排列组合 普通生成函数 细节
    HDU
    poj-1651 multiplication puzzle(区间dp)
    hdu-1231 连续最大子序列(动态规划)
    poj-2488 a knight's journey(搜索题)
    hdu-2063 过山车(二分图)
  • 原文地址:https://www.cnblogs.com/xuezhihao/p/14303489.html
Copyright © 2020-2023  润新知