php 分段mp4合并,python爬取分段电影m3u8,并自动合并成mp4及删除原始片段

#8090sd.com/dianying/33341/2-1.html

import requests

url='https://youku.cdn7-okzy.com/20200517/19513_caa698df/index.m3u8'

headers={

'user-agent':'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36'

}

res=requests.get(url,headers=headers,verify=False)

with open('index.m3u8','wb') as f:

f.write(res.content)

fs=open('index.m3u8','r',encoding='utf-8')

text=fs.readlines()

file=[]

for i in text:

d1=i

d2=i.find('#EX')

d3=i.replace('\n','')

if i.find('#EX')==-1:

file.append(i.replace('\n',''))

fs.close()

#重构路由

import os

for i in file[:5]:

url1='https://youku.cnd7-okzy.com/20200517/19513_caa698df/1000k/hls/'

urls=url1+i

#print(urls)

import time

time.sleep(1)

if os.path.exists('tv') is False:#若不存在

os.mkdir('tv')

res=requests.get(urls,verify=False)

with open('./tv{}'.format(i),'wb') as f:

f.write(res.content)

print(i+'下载成功')

#另一个新文件,实现合并

import os

path=r'C:\豆腐\pythcar\tv'

f_list=os.listdir(path)

shell="+".join(f_list)

shell='copy /b '+shell+' movie.mp4'+'\n'+'del *.ts'#复制二进制,注意空格

#生成一键合成

c=os.getcwd()

re=open(c+'/tv'+'/auto.cmd','w')

re.write(shell)

re.close()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值