m3u8文件下载合并的一种方法
# -*- 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/