ts文件下载如何合并
本帖最后由 YZH1028 于 2023-5-31 13:34 编辑大家请指点下,该如何将ts文件,下载完成后合并为一个mp4文件,这个代码里的merge,我无法合并不知道哪错了,还有一点我在down_m3u8_catalogue()方法里提前创建了放至ts文件的目录,我想知道 down_load_ts() 异步里该如何创,谢谢!
import request
import re
import json
import asyncio
import aiohttp
import aiofiles
import os
import time
import urllib
names = input('为该文件名命名,注意文件名不要重复!\n')
def search_total():
name = input('请输入视频/主演:\n')
name = urllib.parse.quote(name)
url = f"https://www.smmy360.com/index.php?s=search-index-wd-{name}-sid-1-p-1"
payload = {}
headers = {
'authority': 'www.smmy360.com',
'pragma': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Cookie': '_myFavMv=%5B%5D; __51vcke__K1KjP6dTfHXqUvtu=4135a69c-ea00-5d23-9bfd-90344b8b57fc; __51vuft__K1KjP6dTfHXqUvtu=1682048761074; zanpian_vod_v=%u70ED%u8840%u8857%u533A%u7B2C%u4E00%u5B63%7C/a115785.html^%u7B2C09%u96C6%7Chttps%3A//www.smmy360.com/detail/play/115785-0-9.html_$_%u70ED%u8840%u8857%u533A%u7B2C%u4E8C%u5B63%7C/a115786.html^%u7B2C10%u96C6%7Chttps%3A//www.smmy360.com/detail/play/115786-0-10.html_$_%u70ED%u8840%u8857%u533A2016%7C/a66710.html^HD%7Chttps%3A//www.smmy360.com/detail/play/66710-0-1.html_$_%u4E00%u821E%u503E%u57CE%u7CA4%u8BED%7C/a126346.html^%u7B2C07%u96C6%7Chttps%3A//www.smmy360.com/detail/play/126346-0-7.html_$_%u4E00%u821E%u503E%u57CE%u56FD%u8BED%7C/a126346.html^%u7B2C06%u96C6%7Chttps%3A//www.smmy360.com/detail/play/126346-0-6.html_$_%u4ED9%u5251%u5947%u4FA0%u4F20%u4E09%7C/a80370.html^%u7B2C03%u96C6%7Chttps%3A//www.smmy360.com/detail/play/80370-3-3.html_$_|; 8245_2901_222.223.243.26=1; 8246_2700_222.223.243.26=1; Hm_lvt_b3be9102b76d04353398b3b94f4d4858=1684900287,1684979643,1685065633,1685084931; Hm_lvt_879289f649fa4bd235a6fdc54c0c0380=1684900287,1684979643,1685065633,1685084931; 8245_2750_106.114.203.25=1; 8246_2896_106.114.203.25=1; Hm_lvt_351ee051d21890aebd7ad53aa90bf0f7=1684900287,1684979643,1685065633,1685084931; hidden=value; PHPSESSID=5k6fhvic66j8vpbd28cjrilr44; 8246_2856_106.114.203.25=1; 8245_2905_106.114.203.25=1; __51uvsct__K1KjP6dTfHXqUvtu=20; 8245_2897_106.114.203.25=1; 8246_2903_106.114.203.25=1; Hm_lpvt_b3be9102b76d04353398b3b94f4d4858=1685088381; Hm_lpvt_879289f649fa4bd235a6fdc54c0c0380=1685088381; __vtins__K1KjP6dTfHXqUvtu=%7B%22sid%22%3A%20%223eb6756a-78b4-5db8-85a5-6892faaaa5f1%22%2C%20%22vd%22%3A%202%2C%20%22stt%22%3A%20336187%2C%20%22dr%22%3A%20336187%2C%20%22expires%22%3A%201685090181152%2C%20%22ct%22%3A%201685088381152%7D; richviews_8246=EeUUYkcJDC6xsp457rFSR3Sf77DZGn%252BakFIef9XIvaC88WP3ONSOvS5OwPdFQnbCgGo4WBm0msv8BynarVtgJBJv51QNFpNjmDDnJj8Ta%252BZefdyt%252BIYv5gek3aq8pzSwKdEd3k0dLkt4OfOcyNnrtr%252BqC0fhA%252FlSs2rrYFFFkIQ%252FsymTcTjo%252BTiniTVIYkwOlYcNx1A2ucCiVKTHEDpSW2KGDSW%252FpD6vLiHlUqxjsqYRcebVMfXNeI8oOa3TAeSvLlUzBDzWTy5YsUpkY33O25M2dDhz%252BR7CRykpzZvp%252F2T81N5Tx1msVqq95mfEKpaZROKWtMpaeT4EEzeFehrTNw%253D%253D; 8246_2659_106.114.203.25=1; beitouviews_8245=hLNkIEh8%252BBYQSZY9nkZAVdYf4Xnu6Z5S%252F5gNgYiks19wBnXfvjRDpoleXsJDcmhIIirz20zwE1WR2CXNMRfEb4DOVttdn8kd430Jy%252BEPDjtznAKy7gSb2NPbwUYGhT7DH4NvCPrbFSPW9zL2dIhfG%252BY%252FA0o6552%252FX53WUJuZGtUXKQcPWNC7VvayJ4BWcDt8N5OnTEvxBR%252BvMFW7UnoCw%252BO%252BqKapVIitBLVF3ZUzhA898dDM3KXExNUeDEVBFLiPGi4CsorvIw8q7FN2tWxIkHBK%252FQCp4ZwzjhEETSzpGSEfg2miMUlhvpVFb6rsIgV5PL3liNUF2IUZMT5RJ77mXA%253D%253D; 8245_2881_106.114.203.25=1; Hm_lpvt_351ee051d21890aebd7ad53aa90bf0f7=1685088381',
'User-Agent': 'Apifox/1.0.0 (https://www.apifox.cn)'
}
response = requests.request("GET", url, headers=headers, data=payload)
obj_total = re.compile(r'</span>/<span id="totalpages">(?P<num>.*?)</span></div>', re.S)
num = obj_total.findall(response.text)[0]
return name, int(num)
def search():
link = []
title = []
name, num = search_total()
num = int(num)
if num > 15:
print('关键词太少,匹配模糊,搜索页数过多只显示15页!')
num = 20
else:
print(f'列表共{num}页!')
num = num
for t in range(1, int(num) + 1):
url = f"https://www.smmy360.com/index.php?s=search-index-wd-{name}-sid-1-p-{t}"
print(url)
payload = {}
headers = {
'authority': 'www.smmy360.com',
'pragma': 'no-cache',
'x-requested-with': 'XMLHttpRequest',
'Cookie': '_myFavMv=%5B%5D; __51vcke__K1KjP6dTfHXqUvtu=4135a69c-ea00-5d23-9bfd-90344b8b57fc; __51vuft__K1KjP6dTfHXqUvtu=1682048761074; zanpian_vod_v=%u70ED%u8840%u8857%u533A%u7B2C%u4E00%u5B63%7C/a115785.html^%u7B2C09%u96C6%7Chttps%3A//www.smmy360.com/detail/play/115785-0-9.html_$_%u70ED%u8840%u8857%u533A%u7B2C%u4E8C%u5B63%7C/a115786.html^%u7B2C10%u96C6%7Chttps%3A//www.smmy360.com/detail/play/115786-0-10.html_$_%u70ED%u8840%u8857%u533A2016%7C/a66710.html^HD%7Chttps%3A//www.smmy360.com/detail/play/66710-0-1.html_$_%u4E00%u821E%u503E%u57CE%u7CA4%u8BED%7C/a126346.html^%u7B2C07%u96C6%7Chttps%3A//www.smmy360.com/detail/play/126346-0-7.html_$_%u4E00%u821E%u503E%u57CE%u56FD%u8BED%7C/a126346.html^%u7B2C06%u96C6%7Chttps%3A//www.smmy360.com/detail/play/126346-0-6.html_$_%u4ED9%u5251%u5947%u4FA0%u4F20%u4E09%7C/a80370.html^%u7B2C03%u96C6%7Chttps%3A//www.smmy360.com/detail/play/80370-3-3.html_$_|; 8245_2901_222.223.243.26=1; 8246_2700_222.223.243.26=1; Hm_lvt_b3be9102b76d04353398b3b94f4d4858=1684900287,1684979643,1685065633,1685084931; Hm_lvt_879289f649fa4bd235a6fdc54c0c0380=1684900287,1684979643,1685065633,1685084931; 8245_2750_106.114.203.25=1; 8246_2896_106.114.203.25=1; Hm_lvt_351ee051d21890aebd7ad53aa90bf0f7=1684900287,1684979643,1685065633,1685084931; hidden=value; PHPSESSID=5k6fhvic66j8vpbd28cjrilr44; 8246_2856_106.114.203.25=1; 8245_2905_106.114.203.25=1; __51uvsct__K1KjP6dTfHXqUvtu=20; 8245_2897_106.114.203.25=1; 8246_2903_106.114.203.25=1; Hm_lpvt_b3be9102b76d04353398b3b94f4d4858=1685088381; Hm_lpvt_879289f649fa4bd235a6fdc54c0c0380=1685088381; __vtins__K1KjP6dTfHXqUvtu=%7B%22sid%22%3A%20%223eb6756a-78b4-5db8-85a5-6892faaaa5f1%22%2C%20%22vd%22%3A%202%2C%20%22stt%22%3A%20336187%2C%20%22dr%22%3A%20336187%2C%20%22expires%22%3A%201685090181152%2C%20%22ct%22%3A%201685088381152%7D; richviews_8246=EeUUYkcJDC6xsp457rFSR3Sf77DZGn%252BakFIef9XIvaC88WP3ONSOvS5OwPdFQnbCgGo4WBm0msv8BynarVtgJBJv51QNFpNjmDDnJj8Ta%252BZefdyt%252BIYv5gek3aq8pzSwKdEd3k0dLkt4OfOcyNnrtr%252BqC0fhA%252FlSs2rrYFFFkIQ%252FsymTcTjo%252BTiniTVIYkwOlYcNx1A2ucCiVKTHEDpSW2KGDSW%252FpD6vLiHlUqxjsqYRcebVMfXNeI8oOa3TAeSvLlUzBDzWTy5YsUpkY33O25M2dDhz%252BR7CRykpzZvp%252F2T81N5Tx1msVqq95mfEKpaZROKWtMpaeT4EEzeFehrTNw%253D%253D; 8246_2659_106.114.203.25=1; beitouviews_8245=hLNkIEh8%252BBYQSZY9nkZAVdYf4Xnu6Z5S%252F5gNgYiks19wBnXfvjRDpoleXsJDcmhIIirz20zwE1WR2CXNMRfEb4DOVttdn8kd430Jy%252BEPDjtznAKy7gSb2NPbwUYGhT7DH4NvCPrbFSPW9zL2dIhfG%252BY%252FA0o6552%252FX53WUJuZGtUXKQcPWNC7VvayJ4BWcDt8N5OnTEvxBR%252BvMFW7UnoCw%252BO%252BqKapVIitBLVF3ZUzhA898dDM3KXExNUeDEVBFLiPGi4CsorvIw8q7FN2tWxIkHBK%252FQCp4ZwzjhEETSzpGSEfg2miMUlhvpVFb6rsIgV5PL3liNUF2IUZMT5RJ77mXA%253D%253D; 8245_2881_106.114.203.25=1; Hm_lpvt_351ee051d21890aebd7ad53aa90bf0f7=1685088381',
'User-Agent': 'Apifox/1.0.0 (https://www.apifox.cn)'
}
response = requests.request("GET", url, headers=headers, data=payload)
obj = re.compile(r'<a class="list-img" href="(?P<link>.*?)" title="(?P<title>.*?)">', re.S)
for i in obj.finditer(response.text):
link.append(i.group('link'))
title.append(i.group('title'))
return title, link
def get_first_m3u8():
first_url = input('请输入下载的网址:\n')
url = first_url
payload = {}
headers = {
'authority': 'www.smmy360.com',
'pragma': 'no-cache',
'sec-fetch-user': '?1',
'upgrade-insecure-requests': '1',
'Cookie': 'hidden=value; _myFavMv=%5B%5D; __51vcke__K1KjP6dTfHXqUvtu=4135a69c-ea00-5d23-9bfd-90344b8b57fc; __51vuft__K1KjP6dTfHXqUvtu=1682048761074; hidden=value; PHPSESSID=9n92ka589ino2v1ff7t8i8gfg4; 8246_2896_183.198.133.9=1; 8245_2881_183.198.133.9=1; Hm_lvt_b3be9102b76d04353398b3b94f4d4858=1682506748,1684835806,1684900287,1684979643; Hm_lvt_879289f649fa4bd235a6fdc54c0c0380=1684835806,1684900287,1684979643; Hm_lvt_351ee051d21890aebd7ad53aa90bf0f7=1684835807,1684900287,1684979643; 8245_2905_183.198.133.9=1; 8246_2878_183.198.133.9=1; 8246_2856_183.198.133.9=1; 8245_2894_183.198.133.9=1; 8245_2712_183.198.133.9=1; 8246_2877_183.198.133.9=1; 8246_2902_183.198.133.9=1; 8245_2750_183.198.133.9=1; 8245_2662_183.198.133.9=1; 8246_2903_183.198.133.9=1; __51uvsct__K1KjP6dTfHXqUvtu=15; 8246_2659_183.198.133.9=1; 8245_2862_183.198.133.9=1; 8246_2700_183.198.133.9=1; 8245_2901_183.198.133.9=1; 8246_2899_183.198.133.9=1; 8245_2897_183.198.133.9=1; zanpian_vod_v=%u70ED%u8840%u8857%u533A%u7B2C%u4E00%u5B63%7C/a115785.html^%u7B2C09%u96C6%7Chttps%3A//www.smmy360.com/detail/play/115785-0-9.html_$_%u70ED%u8840%u8857%u533A%u7B2C%u4E8C%u5B63%7C/a115786.html^%u7B2C10%u96C6%7Chttps%3A//www.smmy360.com/detail/play/115786-0-10.html_$_%u70ED%u8840%u8857%u533A2016%7C/a66710.html^HD%7Chttps%3A//www.smmy360.com/detail/play/66710-0-1.html_$_%u4ED9%u5251%u5947%u4FA0%u4F20%u4E09%7C/a80370.html^%u7B2C01%u96C6%7Chttps%3A//www.smmy360.com/detail/play/80370-3-1.html_$_|; Hm_lpvt_b3be9102b76d04353398b3b94f4d4858=1685014836; Hm_lpvt_879289f649fa4bd235a6fdc54c0c0380=1685014836; __vtins__K1KjP6dTfHXqUvtu=%7B%22sid%22%3A%20%22d935c55b-fd53-5794-9c86-b71f775b0ec6%22%2C%20%22vd%22%3A%2016%2C%20%22stt%22%3A%203750470%2C%20%22dr%22%3A%20233991%2C%20%22expires%22%3A%201685016635911%2C%20%22ct%22%3A%201685014835911%7D; richviews_8246=CvOr5biTKuqHJhTFYIUPv%252BTuLp%252BP9KMsKxL35xxArykh18myPMaG%252BcOtpaqgQrtPl7M52SfRZ0PM6GY%252Fsn6qeZKtyc%252BWBoVhCprfclyRNRwwoSfsqhh3Cm6zHpuopr4UKWC4j6m4T7XyZQxfUBFImnFG7RDv12c480%252FSFe7iKRGft3MIMMJOdilSJ5DOp2jKwkHZCKeRXn6RVfHHUk494FUMCgGk3kznbeREl8cSb%252B19QF29m1eA20IMWA8mdw7wwH8eq5ouj9VvzXlDKIufM02Mb6t2rmmkEPvN8bMTFd8lKj33n6wFCg56CV3j1jUjDkSEZCiDLkL8c1Oz5RbFAmr3xZkCUr%252Br58vZMdAahdjf7wU6obPvwhmx2xNDglpIkliTazK6lIaG2IQDE4odExc9IFfP3gW1HsWfoWbXNKCUveCLMKDHIhf0JshobRo%252Ff18QmqzXXQsmaevTGLtNqQOJmbH3JV8BmuIoqmVQul76TutCRn%252B1KZAOKxbp13ews%252BXr%252FbSitpLIT0KM3LeKJJwuylg77EuZJX0ezsZweAtgaZXsbldngtArQ7f%252BMtkPK6HCfRtsaHjGPeVr6p%252FUA3l3Wny9omARCwZixlmqRRbsAaTtJu9QRrv%252BV0XicGF7ggCHF3%252F%252B4u%252BibKxewU13QvLRn78Bnym8IxYagg2gS8o%253D; beitouviews_8245=Y7Aw2OX5wLWPtJo%252Bkn57wEXjtCJ3%252FpHEgMAyu0298XfAvjnGntwVMO21UD0nuRQpSLJycRH4FGBIvMeTQfGmvzkTPd1%252F0BJO%252FduEkT23fUpSVwNFSsp6f2KdDSTfjzpeMsr%252FGfY8vCB9nNb0b7gr3Bl6ypNgGunruDsvTuLsFLqhVg1Xq92BAg31d25YRdcz75Jf6dBQs5zce7dQ5y0z6Q12UcRyaDJFxri%252BuaWf%252BQNHDa66BElpi%252FQ%252F%252BhZClHU0aueWY9i0ujag14QYVlvtCxszSgWAxXJsl6MPKRNR%252Bb7r0gdGcDHMTMTthc%252BSzfeCRX8q3AKyq%252FVpmHdpFLssYxZyuLG5Gf1Rco4uKZT9Rb0vSs4nkLCYGKS0ME8ntkzJKbXoJNCWCwPuL%252FPwwB7NNkiH4Ji6Zw1TgZ3s%252Fios4RL%252FFD3Z9uKpeB7uTB%252BIzkAUvxSDbgKjHV2QT%252F%252F5s2I3QE1vGMhEcYlLmpK05bh068ynO5mwk0ihwk7XNhZGtYCKlg%252FUdGlMq4%252FN6n0o85tX4u3bYDQXFFU1ZVrzIWlp2A5FwXRW9nnGBVCmns0ftSZZ4MplytBYiGzpxIMPguTXvq7mIdgvfXSOxCCZjfPMBTu4GOuWeWWZ5VzRfHhU9G7IBjd3oaRkC8LdhxcioyzsXgQJfaNgC1qZJQWmULQs4ZA%253D; Hm_lpvt_351ee051d21890aebd7ad53aa90bf0f7=1685014836',
'User-Agent': 'Apifox/1.0.0 (https://www.apifox.cn)'
}
response = requests.request("GET", url, headers=headers, data=payload)
obj_name = re.compile(
r'<script>var zanpiancms_player = (?P<link>.*?);</script><script src="/player/qdyun.js"></script>', re.S)
link = obj_name.findall(response.text)[0]
a = json.loads(link)['url']
return a
def get_second_m3u8(a):
url = a
payload = {}
headers = {
'authority': 'vip.ffzy-play.com',
'pragma': 'no-cache',
'User-Agent': 'Apifox/1.0.0 (https://www.apifox.cn)'
}
response = requests.request("GET", url, headers=headers, data=payload)
b = ''
for i in response.text.split('\n'):
i.strip()
if i.startswith('#'):
continue
else:
return i
async def down_load_ts(search_ts_url, name, session):# https://vip.ffzy-play.com/20221128/26437_d01e3930/2000k/hls/
async with session.get(search_ts_url) as resp:
async with aiofiles.open(f'video/{names}/{name}', mode='wb') as f:
await f.write(await resp.content.read())
print(f'{name}下载完毕')
async def aio_download(get_ts_url,name):
tasks = []
conn = aiohttp.TCPConnector(ssl=False)
async with aiohttp.ClientSession(connector=conn,trust_env=True) as session:
async with aiofiles.open(f'm3u8目录/{name}/{name}.txt', mode='r', encoding='utf8') as f:
async for line in f:
if line.startswith('#'):
continue
line = line.strip()
ts_url = get_ts_url + line
task = asyncio.create_task(down_load_ts(ts_url, line, session))
tasks.append(task)
await asyncio.wait(tasks)
# def merge_ts():
# lst = []
# with open(f'm3u8目录/{name}/{name}.txt', mode='r', encoding='utf8') as f:
# for line in f:
# if line.startswith('#'):
# continue
# line = line.strip()
# lst.append(line)
# os.chdir("完整视频/")
# s = "+".join(lst)
# os.system(s)
# print('完成!')
def down_m3u8_catalogue(search_ts_url,name):
url = search_ts_url
payload = {}
headers = {
'authority': 'vip.ffzy-play.com',
'pragma': 'no-cache',
'User-Agent': 'Apifox/1.0.0 (https://www.apifox.cn)'
}
response = requests.request("GET", url, headers=headers, data=payload)
if not os.path.exists(f'm3u8目录/{name}/'):
os.makedirs(f'm3u8目录/{name}/')
if not os.path.exists(f'video/{name}'):
os.makedirs(f'video/{name}')
with open(f'm3u8目录/{name}/{name}.txt', 'w',
encoding='utf-8') as f:
f.write(response.text)
def main():
print('使用说明:\n目前仅支持使用网址下载,如下载网址链接为:“https://www.smmy360.com/detail/play/80370-3-25.html”\n仅可在该网站下下载!')
a = get_first_m3u8()
b = get_second_m3u8(a)
get_ts_url = a.replace(a.split('/')[-1], b.replace('mixed.m3u8', ''))
search_ts_url = a.replace(a.split('/')[-1], b)
down_m3u8_catalogue(search_ts_url,names)
# print(get_ts_url)
# print(search_ts_url)
# asyncio.run(aio_download(get_ts_url,name))报错方法
loop = asyncio.get_event_loop()
loop.run_until_complete(aio_download(get_ts_url,names))
# merge_ts()
if __name__ == '__main__':
t1 = time.time()
main()
t2 = time.time()
print(f'该剧集已下载完毕!共耗时:',t2 - t1) FFmpeg_Joiner 没仔细看你的代码,我页不太懂怎么帮你解决,但我知道 https://ffmpeg.bmmmd.com/ 这个网站可能对你有帮助,我上次合并ts用的就是它提供的“命令”,比如:ffmpeg -i "test1.ts" -i "test2.ts" -c copy "output.mp4"就是点哪个“填入命令”得到的 这个有没有直接下载工具的 论坛有m3u8下载器的 论坛有这个软件:M3U8批量下载器 https://vip.ffzy-play.com/20221128/26463_ec69ebce/index.m3u8 可以使用 ffmpeg
之前我是使用的 ffmpeg
后来有部分的 ts 无法合并
就使用 copy /b 了 使用 这个小软件 tsMuxeR 2vgKFg0q 发表于 2023-5-27 18:13
可以使用 ffmpeg
之前我是使用的 ffmpeg
后来有部分的 ts 无法合并
我用ffmpeg有的ts不能合并,copy /b这个命令我失败了,代码里不知道哪块出错了
页:
[1]
2