当前位置:   article > 正文

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

用python将php文件转为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()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/246102
推荐阅读
相关标签
  

闽ICP备14008679号