时间:2021-05-22
代码如下所示:
import osimport requestsimport datetimefrom Crypto.Cipher import AESdef decode_key_file(key_file_name): with open(key_file_name,"r") as f: data=f.read() return datadef decode_m_file(m_file_name): with open(m_file_name,"r") as f: data=f.read() return data.split("\n")[6::2]def decode_video(filename): data_list=[[],[],[]] file_list=os.listdir(filename) for one_file_name in file_list: if "m3u8" in one_file_name: data_list[0].append(filename+"/"+one_file_name) elif "key" in one_file_name: data_list[1].append(filename + "/" + one_file_name) else: data_list[2].append(filename + "/" + one_file_name) key=decode_key_file(data_list[1][0]) name_list=decode_m_file(data_list[0][0]) for one_name in name_list: for path_name in data_list[2]: if one_name in path_name: with open(path_name,"rb") as f: data_name=f.read() if len(key): # AES 解密 cryptor = AES.new(key, AES.MODE_CBC, key) with open(key + ".mp4", 'ab') as f: f.write(cryptor.decrypt(data_name))if __name__ == '__main__': decode_video("./data")视频下载下来如下图所示
https://ngmov.me/?channelCode=ngdl50
这个应用下载下来的视频就是这样的解法
改进版本
def decode_key_file(key_file_name): with open(key_file_name, "r") as f: data = f.read() return datadef decode_m_file(m_file_name): with open(m_file_name, "r") as f: data = f.read() return data.split("\n")[6::2]def decode_video(filename): data_list = [[], [], []] file_list = os.listdir(filename) for one_file_name in file_list: if "m3u8" in one_file_name: data_list[0].append(filename + "/" + one_file_name) elif "key" in one_file_name: data_list[1].append(filename + "/" + one_file_name) else: data_list[2].append(filename + "/" + one_file_name) try: key = decode_key_file(data_list[1][0]) except: key = one_file_name name_list = decode_m_file(data_list[0][0]) for one_name in name_list: for path_name in data_list[2]: if one_name in path_name: with open(path_name, "rb") as f: data_name = f.read() if len(key): # AES 解密 cryptor = AES.new(key, AES.MODE_CBC, key) with open(key + ".mp4", 'ab') as f: f.write(cryptor.decrypt(data_name)) else: with open(key + ".mp4", 'ab') as f: f.write(data_name) f.flush()if __name__ == '__main__': data_list = os.listdir("/home/dfy/Videos/Download") index=0 for path_one in data_list: index+=1 if index<18: continue decode_video("/home/dfy/Videos/Download" + "/" + path_one)到此这篇关于python将下载到本地m3u8视频合成MP4的代码详解的文章就介绍到这了,更多相关python把m3u8视频合成MP4内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
TBS视频播放TBS视频播放器可以支持市面上几乎所有的视频格式,包括mp4,flv,avi,3gp,webm,ts,ogv,m3u8,asf,wmv,rm,rm
电影之类的长视频好像都用m3u8格式了,这就导致了多线程下载视频的意义不是很大,都是短视频,线不线程就没什么意义了嘛。我们知道,m3u8的链接会下载一个文档,相
本文为大家分享了python爬取m3u8连接的视频方法,供大家参考,具体内容如下要求:输入m3u8所在url,且ts视频与其在同一路径下#!/usr/bin/e
前言今天被这个关于m3u8视频播放不了搞了一下午,这个项目所有的视频流都是m3u8格式的,后台给我们返回的都是m3u8格式的视频流,解决了好长时间,看了好多博客
一、关于m3u8:m3u8是苹果公司推出一种视频播放标准,是m3u的一种,不过编码方式是utf-8,是一种文件检索格式,将视频切割成一小段一小段的ts格式的视频