视频的起始和结束url如何获取会在json教学课中解释。
#只需要输入视频开始的url和视频结束时候的url,即可开始下载
urlstart=''
urlend=''
def leningxiazai(urlstart,urlend):
startinfo=urlstart.split('/')[-1]
startnumber=startinfo.split('.')[0]
starti=int(startnumber.split('_')[0])
startn=int(startnumber.split('_')[-1])
endinfo=urlend.split('/')[-1]
endnumber=endinfo.split('.')[0]
endi=int(endnumber.split('_')[0])
endn=int(endnumber.split('_')[-1])
import requests
import time
kv={'user-agent':'Mozilla/5.0'}
path='D://video//'
urlhead=urlstart.rsplit('/', 1)[0]
urlend=urlstart.rsplit('.', 1)[-1]
n=startn
i=starti
print(n,i)
while n<=endn:
url=urlhead+'/'+str(i)+'_'+str(n)+'.'+urlend
r=requests.get(url,headers=kv)
path1=path+str(n)+'.ts'
if r.headers['Content-Type']== 'video/MP2T':
with open(path1,'wb') as f:
f.write(r.content)
f.close()
else:
for j in range(13):
i+=1
url1=urlhead+'/'+str(i)+'_'+str(n)+'.'+urlend
r1=requests.get(url1,headers=kv)
if r1.headers['Content-Type']== 'video/MP2T':
with open(path1,'wb') as f:
f.write(r1.content)
f.close()
break
n+=1
i+=5
time.sleep(2)
def hebingshipin(directory): #存放所有ts文件的文件夹地址:'D:\\video'
import os
os.chdir(directory)
cmd = "copy /b * new.mp4"
os.system(cmd) #合并文件夹中所有文件
os.system('del /Q *.ts') #合并后删除所有的ts文件