m3u8文件下载合并的一种方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # -*- 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/
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步