首页 > 其他 > 详细

m3u8文件下载合并的一种方法

时间:2019-02-07 21:37:46      阅读:441      评论:0      收藏:0      [点我收藏+]
# -*- coding: utf-8 -*-
"""
Created on Wed Mar 14 15:09:14 2018
@author: Y
"""
 
 
import requests
import json
 
 
#m3u8的文件路径
path = input("Enter m3u8 file path:").replace(‘\\‘,‘/‘)
print(path)
file = open(path,‘r‘)
operation = input("是否要加上前缀?y/n\n").strip()
pre_link = ‘‘
if operation == ‘y‘:
    pre_link = input("请输入前缀:").strip()
links = []
for i in file:
    if ‘#‘ not in i:
        i = i.strip()
        links.append(pre_link+i)
file.close()
l = len(links)
print("总共有%d个片段..."%l)
length = len(str(len(links)))
n = 0
txt = ""
for link in links:
    n = n + 1
    print("还剩%d个片段未下载..."%(l-n))
    if len(str(n)) < length:
        name = ‘0‘*(length-len(str(n))) + str(n) + ".ts"
    else:
        name = str(n)+".ts"
    txt = txt + "file \‘" + name + "\‘\n"
    jsonreq = json.dumps({‘jsonrpc‘:‘2.0‘, ‘id‘:1,
               ‘method‘:‘aria2.addUri‘,
               ‘params‘:[[link],{"out":name,"split":"5","max-connection-per-server":"16","seed-ratio":"0"}]})
    c = requests.post(‘http://localhost:6800/jsonrpc‘, jsonreq)
file = open("E:\\aria2data\\filelist.txt","w")
file.write(txt)
file.close()

  

 

生成的ts文件用 ffmpeg 合并,命令行输入:ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.ts

 

https://xyne.archlinux.ca/projects/python3-aria2jsonrpc/

https://aur.archlinux.org/packages/python3-aria2jsonrpc/

https://xyne.archlinux.ca/projects/python3-aria2jsonrpc/src/

 

m3u8文件下载合并的一种方法

原文:https://www.cnblogs.com/pythonClub/p/10355570.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!