1、首先使用 https://jx.618g.com/?url=URL :
URL:为所要播放的电影或者电视剧的url,即各大网站的播放地址;
2、利用https://jx.618g.com/?url=URL ,requests.get(https://jx.618g.com/?url=URL)会返回一个html代码,代码里包含m3u8的链接,这个链接很重要!!!
3、即https://cn7.7639616.com/hls/20191019/8d845d5a33f8471b25380a4ba9f75557/1571473871/index.m3u8
4、然后用requests.get("https://cn7.7639616.com/hls/20191019/8d845d5a33f8471b25380a4ba9f75557/1571473871/index.m3u8")来请求到ts文件列表;
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-ALLOW-CACHE:YES
#EXT-X-TARGETDURATION:7
#EXT-X-MEDIA-SEQUENCE:0
#EXTINF:6.000000,
/hls/20191019/8d845d5a33f8471b25380a4ba9f75557/1571473871/film_00000.ts
#EXTINF:5.160000,
/hls/20191019/8d845d5a33f8471b25380a4ba9f75557/1571473871/film_00001.ts
#EXTINF:4.000000,
/hls/20191019/8d845d5a33f8471b25380a4ba9f75557/1571473871/film_00002.ts
#EXTINF:6.600000,
/hls/20191019/8d845d5a33f8471b25380a4ba9f75557/1571473871/film_00003.ts
#EXTINF:3.680000,
......
/hls/20191019/8d845d5a33f8471b25380a4ba9f75557/1571473871/film_00050.ts
#EXTINF:4.000000,
/hls/20191019/8d845d5a33f8471b25380a4ba9f75557/1571473871/film_00051.ts
5、用re模块进行过滤出ts文件名:
re.findall(".*?.ts", result_list.text)
6、然后对所获取的ts文件名进行拼接:
https://cn7.7639616.com/hls/20191019/8d845d5a33f8471b25380a4ba9f75557/1571473871/film_00051.ts
https://cn7.7639616.com即为m3u8的地址的主机名。
7、可以用
ffmpeg -i https://cn3.playfeel.cc/hls/20190824/d1cda3b4e14619b923a705e846f7c37f/1566648971/index.m3u8 -vcodec copy -acodec copy demo.mp4
获取所有的ts文件,然后进行合并成mp4文件。
8、也可以用python代码进行下载ts文件并进行合并。
import requests
from lxml.html import etree
import re
import threading
import uuid
def download_ts_file(start, end, name_list):
for i in range(end - start):
with open("D:/resources/ts/" + str(name_list[i]).replace("/", "_").replace(":", ""), "wb") as fp:
ret = requests.get(name_list[i])
print(threading.currentThread().getName() + "------" + name_list[i])
fp.write(ret.content)
if __name__ == "__main__":
url = "https://jx.618g.com/?url=URL"
result = requests.get(url.replace("URL", "https://v.qq.com/x/cover/hzgtowvz90ucvkj.html"))
print(result.text)
document = etree.HTML(result.text)
m3u8_url = str(document.cssselect('iframe')[0].attrib["src"]).split("=")[-1]
print(m3u8_url)
result_list = requests.get(m3u8_url)
print(result_list.text)
ts_list = re.findall(".*?.ts", result_list.text)
length = len(ts_list)
ts_append_list = []
for ts in ts_list:
ts_append_list.append("https://cn7.7639616.com" + ts)
for ts_url in ts_append_list:
with open("D:/resources/ts/" + str(uuid.uuid1()) + ".ts","wb") as fp:
ret = requests.get(ts_url)
print(ts_url.replace("/","_"))
fp.write(ret.content)