Video file formats ts turn on m3u8 mp4 download encryption and key issues

First, use a web browser F12 key, use Google browser plug-in to find .m3u8 video file, and open it.

 

 

Second, open the file m3u8, there are many .ts link, and the link key.

 

 

Third, save it as a html file, download ts file, the code is as follows: can Cadogan threads may need to use a proxy.

 1 # 爬虫 123.html就是打开m3u8文件右键保存为html格式。
 2 htmlf=open('./123.html','r',encoding="utf-8")
 3 htmlcont=htmlf.read()
 4 # print(htmlcont)
 5 import requests
 6 from lxml import etree
 7 tree = etree.HTML(htmlcont)
 8 href = tree.xpath("//a//@href")
 9 # print(href)
10 ts = href[2273:]
11 print(len(ts))
12 # print(ts)
13 for i in ts:
14     a = i.split("/")[-1]
15     # print(a)
16     headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.87 Safari/537.36"}
17     try:
18         rest = requests.get(i,headers=headers)
19         if rest.status_code == 200:
20             with open(a,"wb") as fp:
21                 fp.write(rest.content)
22                 fp.close()
23     except Exception as e:
24          print(e)

Fourth, the method of Reference 1:

Reference Links: https://gist.github.com/larvata/95df619df7109d8b74d2b965a3266354#ffmpeg-cheatsheet

First m3u8 to download key and 
then modify the key path m3u8
finally download ffmpeg
ffmpeg -i <source.m3u8> -c copy < target.ts>

Fourth, Reference 2:

About m3u8 file, ts file decryption, hls decryption. Some records

 Use openssl decrypt

openssl aes-128-cbc -d -in 原.ts -out 解密后.ts -nosalt -iv 偏移量 -K key16进制
Wherein the key offset and iv usually in  m3u8 the. Yaoan download address key, IV offset is optional, if there are no m3u8 iv, iv can easily be set to 0.
还可以直接使用 ffmpeg 直接合并文件。

 V. m3u8 for encrypted files:

Another way to download video m3u8
as the image above download link directly down by ts ts video file is encrypted (encrypted under Why? Although encryption but was quick download speeds).

# EXT-X-KEY  field already stated the encryption is AES-128, key acquired by URI, IV, too.

 

How then decrypt it?
1. Copy the URI address to a Web page, you will get a second download speed automatic 16-byte file
2. Open a terminal, open the file hexadecimal view:

 

Sixth, get key value:

 Download m3u8 in the key file, download winhex.exe application, after installation, the key file into winhex, the automatic generation of hexadecimal.

 

 

 Seven synthetic downloaded .ts file:

Click the lower left corner Run: cmd

copy / b file where the disk: \ subfolder \ * ts storage folder: \ subfolder \ new.ts

Chinese characters into the top of the file and the folder where the letter.

 

Eight, after the synthesis of a ts file can not be opened because ts is encrypted.

 Here, there is no value iv, substituting 0. ts files after decryption so you can play.

Nine, Note: The order ts file must be orderly, indispensable.

Reference website: Jane book: https://www.jianshu.com/p/1b0adcc7b426

 

Published 49 original articles · won praise 32 · views 310 000 +

Guess you like

Origin blog.csdn.net/dianliang01/article/details/105269826