Python解析下载1905网免费电影资源
# https://m3u8i.vodfile.m1905.com/202204130337/dcb290af88500f5df01fda9d8bce85ce/movie/2021/12/17/m20211217COB1O9SRFTA2840Y/54C3DA9EAF2B0987C520FDE2D.m3u8 import requests import lib.tools as t import os import shutil import time # 删除列表中包含某字符的元素 def del_list_data(list,del_data): n=len(list) bek=[] for i in range(n): if del_data in list[i]: bek.append(i) list = [list[i] for i in range(n) if (i not in bek)] return list # 执行cmd命令 def merge(t,cmd): time.sleep(t) res=os.popen(cmd) return res.read() # 如果文件夹不存在就创建,如果文件存在就清空! def setDir(filepath): if not os.path.exists(filepath): os.mkdir(filepath) else: shutil.rmtree(filepath) os.mkdir(filepath) if __name__ == "__main__": try: m3u8_url = input("请输入m3u8地址:") ts_url_pre = os.path.dirname(m3u8_url) r = requests.get(m3u8_url) m3u8_txt = r.text ts_list = m3u8_txt.split("\n") ts_list = del_list_data(ts_list,"#") # 创建或者清空文件夹 setDir("video") for ts_url in ts_list: if ts_url != "": t.download(ts_url_pre +"/" + ts_url,"video/"+ts_url) print(f"{ts_url}下载完成") cmd = merge(5,"copy /b video\\*.ts video\\ok.mp4") print(cmd) except Exception: pass
运行:
结果:
过程:
1.找到m3u8文件地址,读取内容
2.解析内容,对每一个ts文件下载
3.Python调用cmd 合并所有ts文件为mp4