hs-m3u8 0.1.6__py3-none-any.whl → 0.1.7__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
hs_m3u8/main.py
CHANGED
|
@@ -17,6 +17,7 @@ from zipfile import ZipFile
|
|
|
17
17
|
import m3u8
|
|
18
18
|
from hssp import Net
|
|
19
19
|
from hssp.models.net import RequestModel
|
|
20
|
+
from hssp.network.response import Response
|
|
20
21
|
from hssp.utils import crypto
|
|
21
22
|
from loguru import logger
|
|
22
23
|
|
|
@@ -82,8 +83,11 @@ class M3u8Downloader:
|
|
|
82
83
|
key: M3u8Key = None,
|
|
83
84
|
get_m3u8_func: Callable = None,
|
|
84
85
|
m3u8_request_before: Callable[[RequestModel], RequestModel] = None,
|
|
86
|
+
m3u8_response_after: Callable[[Response], Response] = None,
|
|
85
87
|
key_request_before: Callable[[RequestModel], RequestModel] = None,
|
|
88
|
+
key_response_after: Callable[[Response], Response] = None,
|
|
86
89
|
ts_request_before: Callable[[RequestModel], RequestModel] = None,
|
|
90
|
+
ts_response_after: Callable[[Response], Response] = None,
|
|
87
91
|
):
|
|
88
92
|
"""
|
|
89
93
|
|
|
@@ -96,8 +100,11 @@ class M3u8Downloader:
|
|
|
96
100
|
get_m3u8_func: 处理m3u8情求的回调函数。适用于m3u8地址不是真正的地址,
|
|
97
101
|
而是包含m3u8内容的情求,会把m3u8_url的响应传递给get_m3u8_func,要求返回真正的m3u8内容
|
|
98
102
|
m3u8_request_before: m3u8请求前的回调函数
|
|
103
|
+
m3u8_response_after: m3u8响应后的回调函数
|
|
99
104
|
key_request_before: key请求前的回调函数
|
|
100
|
-
|
|
105
|
+
key_response_after: key响应后的回调函数
|
|
106
|
+
ts_request_before: ts请求前的回调函数
|
|
107
|
+
ts_response_after: ts响应后的回调函数
|
|
101
108
|
"""
|
|
102
109
|
|
|
103
110
|
sem = asyncio.Semaphore(max_workers) if max_workers else None
|
|
@@ -107,16 +114,22 @@ class M3u8Downloader:
|
|
|
107
114
|
self.m3u8_net = Net(sem=sem)
|
|
108
115
|
if m3u8_request_before:
|
|
109
116
|
self.m3u8_net.request_before_signal.connect(m3u8_request_before)
|
|
117
|
+
if m3u8_response_after:
|
|
118
|
+
self.m3u8_net.response_after_signal.connect(m3u8_response_after)
|
|
110
119
|
|
|
111
120
|
# 加密key的请求器
|
|
112
121
|
self.key_net = Net()
|
|
113
122
|
if key_request_before:
|
|
114
123
|
self.key_net.request_before_signal.connect(key_request_before)
|
|
124
|
+
if key_response_after:
|
|
125
|
+
self.key_net.response_after_signal.connect(key_response_after)
|
|
115
126
|
|
|
116
127
|
# ts内容的请求器
|
|
117
128
|
self.ts_net = Net()
|
|
118
129
|
if ts_request_before:
|
|
119
130
|
self.ts_net.request_before_signal.connect(ts_request_before)
|
|
131
|
+
if ts_response_after:
|
|
132
|
+
self.ts_net.response_after_signal.connect(ts_response_after)
|
|
120
133
|
|
|
121
134
|
self.decrypt = decrypt
|
|
122
135
|
self.m3u8_url = urlparse(m3u8_url)
|
|
@@ -146,6 +159,7 @@ class M3u8Downloader:
|
|
|
146
159
|
:return:
|
|
147
160
|
"""
|
|
148
161
|
mp4_path = self.save_dir.parent / f"{self.save_name}.mp4"
|
|
162
|
+
mp4_path = mp4_path.absolute()
|
|
149
163
|
if Path(mp4_path).exists():
|
|
150
164
|
self.logger.info(f"{mp4_path}已存在")
|
|
151
165
|
if del_hls:
|
|
@@ -155,7 +169,7 @@ class M3u8Downloader:
|
|
|
155
169
|
self.logger.info(
|
|
156
170
|
f"开始下载: 合并ts为mp4={merge}, "
|
|
157
171
|
f"删除hls信息={del_hls}, "
|
|
158
|
-
f"下载地址为:{self.m3u8_url.geturl()}. 保存路径为:{self.save_dir}"
|
|
172
|
+
f"下载地址为:{self.m3u8_url.geturl()}. 保存路径为:{self.save_dir.absolute()}"
|
|
159
173
|
)
|
|
160
174
|
|
|
161
175
|
await self._download()
|
|
@@ -165,7 +179,7 @@ class M3u8Downloader:
|
|
|
165
179
|
self.logger.info(f"TS应下载数量为:{count_1}, 实际下载数量为:{count_2}")
|
|
166
180
|
if count_1 == 0 or count_2 == 0:
|
|
167
181
|
self.logger.error("ts数量为0,请检查!!!")
|
|
168
|
-
return
|
|
182
|
+
return None
|
|
169
183
|
|
|
170
184
|
if count_2 != count_1:
|
|
171
185
|
self.logger.error(f"ts下载数量与实际数量不符合!!!应该下载数量为:{count_1}, 实际下载数量为:{count_2}")
|
|
@@ -282,7 +296,7 @@ class M3u8Downloader:
|
|
|
282
296
|
return
|
|
283
297
|
|
|
284
298
|
if self.ts_key and self.decrypt:
|
|
285
|
-
ts_content = crypto.
|
|
299
|
+
ts_content = crypto.decrypt_aes_256_cbc(ts_content, self.ts_key.key, self.ts_key.iv)
|
|
286
300
|
|
|
287
301
|
self.save_file(ts_content, ts_path)
|
|
288
302
|
self.logger.info(f"{ts_uri}下载成功")
|
|
@@ -321,7 +335,7 @@ class M3u8Downloader:
|
|
|
321
335
|
with open(path, "rb") as ts_file:
|
|
322
336
|
data = ts_file.read()
|
|
323
337
|
if self.ts_key:
|
|
324
|
-
data = crypto.
|
|
338
|
+
data = crypto.decrypt_aes_256_cbc(data, self.ts_key.key, self.ts_key.iv)
|
|
325
339
|
big_ts_file.write(data)
|
|
326
340
|
big_ts_file.close()
|
|
327
341
|
self.logger.info("ts文件整合完毕")
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hs-m3u8
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Summary: m3u8 下载器
|
|
5
5
|
Project-URL: homepage, https://github.com/x-haose/hs-m3u8
|
|
6
6
|
Project-URL: repository, https://github.com/x-haose/hs-m3u8
|
|
@@ -20,7 +20,7 @@ Classifier: Programming Language :: Python :: 3.12
|
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
21
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
22
|
Requires-Python: >=3.10
|
|
23
|
-
Requires-Dist: hssp>=0.4.
|
|
23
|
+
Requires-Dist: hssp>=0.4.18
|
|
24
24
|
Requires-Dist: m3u8>=6.0.0
|
|
25
25
|
Description-Content-Type: text/markdown
|
|
26
26
|
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
hs_m3u8/__init__.py,sha256=_AhYioHAgwPXE10FXGZ3ZKj1urwFYR0L9xzBn8pQPJw,72
|
|
2
|
+
hs_m3u8/main.py,sha256=dyRy7ciRMbvrrjAE01mhjuw1Wj4mHG_DZiJNHHVtJ9Y,13403
|
|
3
|
+
hs_m3u8/res/ffmpeg_win.exe.zip,sha256=x_7Fa9N3hzN1d7Ph9ZwOiwpuRfLEVnhNL8tPjuZZMe0,60131319
|
|
4
|
+
hs_m3u8-0.1.7.dist-info/METADATA,sha256=w3wygMm94rIns6-RxhisG85tS7myzNSconLpH7sJPus,2205
|
|
5
|
+
hs_m3u8-0.1.7.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
+
hs_m3u8-0.1.7.dist-info/RECORD,,
|
hs_m3u8-0.1.6.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
hs_m3u8/__init__.py,sha256=_AhYioHAgwPXE10FXGZ3ZKj1urwFYR0L9xzBn8pQPJw,72
|
|
2
|
-
hs_m3u8/main.py,sha256=dickli-bmyAoNB7N3pmx2UU_VUDGSISU913BB-VwMbk,12620
|
|
3
|
-
hs_m3u8/res/ffmpeg_win.exe.zip,sha256=x_7Fa9N3hzN1d7Ph9ZwOiwpuRfLEVnhNL8tPjuZZMe0,60131319
|
|
4
|
-
hs_m3u8-0.1.6.dist-info/METADATA,sha256=ujcGSSJnM5o_uWCgXDnfmweC0t4iWwqqCaMNvticSzI,2204
|
|
5
|
-
hs_m3u8-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
-
hs_m3u8-0.1.6.dist-info/RECORD,,
|
|
File without changes
|