Skip to content

Commit e1009e3

Browse files
author
scrapy@qq.com
committed
ts视频aes加密m3u8
ts视频aes加密m3u8加密破解
1 parent 4a248be commit e1009e3

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import requests
2+
from Crypto.Cipher import AES
3+
4+
5+
HEADERS = {
6+
'Origin': 'http://tts.tmooc.cn',
7+
'Referer': 'http://tts.tmooc.cn/video/showVideo?menuId=582783&version=CGB_A_V02',
8+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
9+
}
10+
11+
12+
def download_key(url_key):
13+
14+
response_key = requests.get(url_key, headers=HEADERS).content # 下载key
15+
return response_key
16+
17+
18+
def download_ts(url_ts):
19+
20+
response_ts = requests.get(url_ts, headers=HEADERS).content # 下载key
21+
return response_ts
22+
23+
def aes_key_and_ts(key, ts):
24+
25+
data = AES.new(key, AES.MODE_CBC, ts[0:16]).decrypt(ts[16:])
26+
return data
27+
28+
def save_mp4(file_name, data):
29+
30+
with open(file_name+'.mp4', 'ab') as fp:
31+
fp.write(data)
32+
33+
if __name__ == '__main__':
34+
url_key = 'http://c.it211.com.cn/cgb19020226pm/static.key'
35+
key = download_key(url_key)
36+
for page in range(0, 199):
37+
url_ts = f'http://c.it211.com.cn/cgb19020226pm/cgb19020226pm-{page}.ts'
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import re, os
2+
import requests
3+
from parsel import Selector
4+
from tmoockey import download_key, download_ts, aes_key_and_ts, save_mp4
5+
6+
7+
headers = {
8+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
9+
'Accept-Encoding': 'gzip, deflate',
10+
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
11+
'Cache-Control': 'max-age=0',
12+
'Connection': 'keep-alive',
13+
'Cookie': 'xxxxxxxxxxxxxxxxxxx',
14+
'Host': 'tts.tmooc.cn',
15+
'Referer': 'http://tts.tmooc.cn/studentCenter/toMyttsPage?versionCode=CGB_A_V02',
16+
'Upgrade-Insecure-Requests': '1',
17+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
18+
}
19+
20+
headers2 = {
21+
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
22+
'Accept-Encoding': 'gzip, deflate',
23+
'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8',
24+
'Cache-Control': 'max-age=0',
25+
'Connection': 'keep-alive',
26+
'Cookie': 'xxxxxxxxxxxx',
27+
'Host': 'tts.tmooc.cn',
28+
'Upgrade-Insecure-Requests': '1',
29+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
30+
31+
}
32+
33+
headers3 = {
34+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
35+
}
36+
37+
def get_menuId(url):
38+
39+
response = requests.get(url, headers=headers)
40+
selectors = Selector(text=response.text).xpath('//div[@class="course-menu"]/ul/li[@class="opened"]')
41+
for selector in selectors:
42+
video_name = selector.xpath('./p/text()').get().strip()
43+
video_href = selector.xpath('./ul/li[@class="sp"]/a/@href').get()
44+
video_name = ''.join(video_name.split())
45+
video_href = video_href
46+
yield video_name, video_href
47+
48+
49+
def get_m3u8(m3u8_url):
50+
# m3u8_url = 'https://hls.videocc.net/01b768ec8c/0/01b768ec8c4739f79cec9964836b5800_2.m3u8?pid=1580626301758X1133587&device=desktop'
51+
# m3u8_url = 'https://hls.videocc.net/01b768ec8c/e/01b768ec8c3d4e068ad411ccc0b9342e_2.m3u8?pid=1580632138310X1619848&device=desktop'
52+
response_m3u8 = requests.get(m3u8_url, headers=headers3)
53+
print(response_m3u8.text)
54+
# 提取key的url
55+
url_key = re.search('URI="(.*?)"', response_m3u8.text).group(1)
56+
#'http://c.it211.com.cn/cgb19020226pm/static.key'
57+
key = download_key(url_key)
58+
url_ts = re.findall(r'https://.*?\.ts\?pid=.*?&device=desktop', response_m3u8.text)
59+
print(url_ts)
60+
for ts_url in url_ts:
61+
print(ts_url)
62+
ts = download_ts(ts_url)
63+
data = aes_key_and_ts(key, ts)
64+
video_path = '第6讲 【作】写人篇·我的好朋友'
65+
save_mp4(video_path, data)
66+
67+
68+
if __name__ == '__main__':
69+
m3u8_url = 'https://hls.videocc.net/01b768ec8c/7/01b768ec8c751c7b09232998c15b6837_2.m3u8?pid=1580646548553X1389651&device=desktop'
70+
get_m3u8(m3u8_url)

0 commit comments

Comments
 (0)