#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()