获取视频链接
image.png
使用python进行视频分段获取
import re
import requests
url="http://pl-ali.youku.com/playlist/m3u8?vid=XMzUyODA5NTM0MA%3D%3D&type=flv&ups_client_netip=da1c8942&utid=7B6EE3ZcwRICAdociUJ6j5lV&ccode=0502&psid=c10f6f849c7d2971077d4d1e8b8a7bb2&duration=3532&expire=18000&drm_type=1&drm_device=7&ups_ts=1528804902&onOff=0&encr=0&ups_key=bcbd638f0609541d69a81f77de4103ad"
headers={
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.79 Safari/537.36'
}
def get_ts(url):
response=requests.get(url)
item=response.text
prttern=re.compile(r'http://(.*?)#',re.S)
item=re.findall(prttern,item)
a=1
for i in item:
s="http://"+i
s=s.replace('\r\n', '')
url=s
response=requests.get(url)
content=response.content
with open("/Users/Desktop/here/"+str(a)+'.ts','wb') as f:
f.write(content)
f.close()
a=a+1
if __name__ == '__main__':
get_ts(url)
然后再使用ffmpeg将视频进行合成,下面是python代码
import os
dirs ="/Users/Desktop/here"
listts=os.listdir(dirs)
for root,dirs,files in os.walk(dirs):
for i in range(len(files)):
files[i]=files[i].split('.')
files[i][0]=int(files[i][0])
files.sort()
for i in range(len(files)):
files[i][0]=str(files[i][0])
files[i]=files[i][0]+'.'+files[i][1]
with open('/Users/Desktop/here/list.txt','w+') as f:
for i in files:
f.write('file '+i+'\n')
f.close()
os.system('ffmpeg -f concat -i %s/list.txt -c copy output.mp4' % dirs)
网友评论