hs-m3u8 0.1.3__py3-none-any.whl → 0.1.5__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/__init__.py
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
from hs_m3u8.main import M3u8Downloader
|
|
1
|
+
from hs_m3u8.main import M3u8Downloader, M3u8Key
|
|
2
2
|
|
|
3
|
-
__version__ = "0.1.
|
|
3
|
+
__version__ = "0.1.5"
|
hs_m3u8/main.py
CHANGED
|
@@ -9,6 +9,7 @@ import shutil
|
|
|
9
9
|
import subprocess
|
|
10
10
|
from collections.abc import Callable
|
|
11
11
|
from hashlib import md5
|
|
12
|
+
from importlib import resources
|
|
12
13
|
from pathlib import Path
|
|
13
14
|
from urllib.parse import urljoin, urlparse
|
|
14
15
|
from zipfile import ZipFile
|
|
@@ -28,20 +29,18 @@ def get_ffmpeg():
|
|
|
28
29
|
if current_os != "Windows":
|
|
29
30
|
return "ffmpeg"
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
with resources.as_file(resources.files("hs_m3u8.res")) as package_dir:
|
|
33
|
+
ffmpeg_bin = package_dir / "ffmpeg_win.exe"
|
|
34
|
+
if ffmpeg_bin.exists():
|
|
35
|
+
return str(ffmpeg_bin)
|
|
33
36
|
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
# ZIP 文件
|
|
38
|
+
ffmpeg_bin_zip = package_dir / "ffmpeg_win.exe.zip"
|
|
39
|
+
if ffmpeg_bin_zip.exists():
|
|
40
|
+
with ZipFile(ffmpeg_bin_zip, "r") as zip_ref:
|
|
41
|
+
zip_ref.extractall(ffmpeg_bin.parent)
|
|
36
42
|
|
|
37
|
-
|
|
38
|
-
ffmpeg_bin_zip = Path(ffmpeg_bin.parent) / f"{ffmpeg_bin.name}.zip"
|
|
39
|
-
if ffmpeg_bin_zip.exists():
|
|
40
|
-
# 解压缩到同一目录
|
|
41
|
-
with ZipFile(ffmpeg_bin_zip, "r") as zip_ref:
|
|
42
|
-
zip_ref.extractall(ffmpeg_bin.parent)
|
|
43
|
-
|
|
44
|
-
return ffmpeg_bin
|
|
43
|
+
return ffmpeg_bin
|
|
45
44
|
|
|
46
45
|
|
|
47
46
|
class M3u8Key:
|
|
@@ -54,8 +53,9 @@ class M3u8Key:
|
|
|
54
53
|
:param key: 密钥
|
|
55
54
|
:param iv: 偏移
|
|
56
55
|
"""
|
|
56
|
+
iv = bytes.fromhex(iv[2:]) if iv and iv.startswith("0x") else iv
|
|
57
57
|
self.key = key
|
|
58
|
-
self.iv = iv
|
|
58
|
+
self.iv = iv
|
|
59
59
|
|
|
60
60
|
|
|
61
61
|
class M3u8Downloader:
|
|
@@ -78,6 +78,7 @@ class M3u8Downloader:
|
|
|
78
78
|
decrypt=False,
|
|
79
79
|
max_workers=None,
|
|
80
80
|
headers=None,
|
|
81
|
+
key: M3u8Key = None,
|
|
81
82
|
get_m3u8_func: Callable = None,
|
|
82
83
|
):
|
|
83
84
|
"""
|
|
@@ -101,6 +102,7 @@ class M3u8Downloader:
|
|
|
101
102
|
self.save_dir = Path(save_path) / "hls"
|
|
102
103
|
self.save_name = Path(save_path).name
|
|
103
104
|
self.key_path = self.save_dir / "key.key"
|
|
105
|
+
self.custom_key = key
|
|
104
106
|
|
|
105
107
|
if not self.save_dir.exists():
|
|
106
108
|
self.save_dir.mkdir(parents=True)
|
|
@@ -216,10 +218,16 @@ class M3u8Downloader:
|
|
|
216
218
|
|
|
217
219
|
# 保存解密key
|
|
218
220
|
if len(m3u8_obj.keys) > 0 and m3u8_obj.keys[0]:
|
|
219
|
-
|
|
220
|
-
|
|
221
|
+
iv = m3u8_obj.keys[0].iv
|
|
222
|
+
if not self.custom_key:
|
|
223
|
+
resp = await self.net.get(m3u8_obj.keys[0].absolute_uri, headers=self.headers)
|
|
224
|
+
key_data = resp.content
|
|
225
|
+
else:
|
|
226
|
+
key_data = self.custom_key.key
|
|
227
|
+
iv = self.custom_key.iv or iv
|
|
228
|
+
|
|
221
229
|
self.save_file(key_data, self.key_path)
|
|
222
|
-
self.ts_key = M3u8Key(key=key_data, iv=
|
|
230
|
+
self.ts_key = M3u8Key(key=key_data, iv=iv)
|
|
223
231
|
key = m3u8_obj.segments[0].key
|
|
224
232
|
key.uri = "key.key"
|
|
225
233
|
m3u8_obj.segments[0].key = key
|
|
@@ -244,7 +252,7 @@ class M3u8Downloader:
|
|
|
244
252
|
if Path(ts_path).exists():
|
|
245
253
|
self.ts_path_list[index] = str(ts_path)
|
|
246
254
|
return
|
|
247
|
-
resp = await self.net.get(ts_item["uri"])
|
|
255
|
+
resp = await self.net.get(ts_item["uri"], self.headers)
|
|
248
256
|
ts_content = resp.content
|
|
249
257
|
if ts_content is None:
|
|
250
258
|
return
|
|
Binary file
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
hs_m3u8/__init__.py,sha256=HINaNDvyRMsgqg9VY_AsV9ierd8KhdtNyJRdQ8BcFg8,72
|
|
2
|
+
hs_m3u8/main.py,sha256=jZ0650qosfrhiS1r3-UGhjp8shx6TvcElXAEls7f3jQ,11609
|
|
3
|
+
hs_m3u8/res/ffmpeg_win.exe.zip,sha256=x_7Fa9N3hzN1d7Ph9ZwOiwpuRfLEVnhNL8tPjuZZMe0,60131319
|
|
4
|
+
hs_m3u8-0.1.5.dist-info/METADATA,sha256=3htPtN-CKSxXaS3o9oootUP4RMdS_tQSIyn4vBT0B4I,2204
|
|
5
|
+
hs_m3u8-0.1.5.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
6
|
+
hs_m3u8-0.1.5.dist-info/RECORD,,
|
hs_m3u8-0.1.3.dist-info/RECORD
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
hs_m3u8/__init__.py,sha256=t0R3Q2zVnUtOiJ8e2sL29N4QkkBHXKgC54n6OqMbwJs,63
|
|
2
|
-
hs_m3u8/main.py,sha256=kJ4HV1eISz80ttxsr2E9K-tfTKK79URiEJviPcc5tfg,11259
|
|
3
|
-
hs_m3u8-0.1.3.dist-info/METADATA,sha256=nskQSk_KjDfVtGPhdr6cYXdJbfrbHJXnf7JnvtxIcjg,2204
|
|
4
|
-
hs_m3u8-0.1.3.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
5
|
-
hs_m3u8-0.1.3.dist-info/RECORD,,
|
|
File without changes
|