vega-cli 0.1.0__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.
- vega_cli/__init__.py +1 -0
- vega_cli/__main__.py +6 -0
- vega_cli/cli.py +247 -0
- vega_cli/config.py +99 -0
- vega_cli/display.py +138 -0
- vega_cli/html.py +540 -0
- vega_cli/interactive.py +220 -0
- vega_cli/player.py +82 -0
- vega_cli/providers/__init__.py +13 -0
- vega_cli/providers/ani_dream.py +1089 -0
- vega_cli/providers/anikoto.py +820 -0
- vega_cli/providers/animesalt.py +649 -0
- vega_cli/providers/animesub.py +1374 -0
- vega_cli/providers/animeworld.py +504 -0
- vega_cli/providers/auto_embed.py +479 -0
- vega_cli/providers/castle.py +497 -0
- vega_cli/providers/cncverse.py +873 -0
- vega_cli/providers/common/__init__.py +51 -0
- vega_cli/providers/common/aes.py +152 -0
- vega_cli/providers/common/aniskip.py +186 -0
- vega_cli/providers/common/base_url.py +102 -0
- vega_cli/providers/common/cinemeta.py +231 -0
- vega_cli/providers/common/errors.py +25 -0
- vega_cli/providers/common/extractors/__init__.py +23 -0
- vega_cli/providers/common/extractors/abbasy.py +247 -0
- vega_cli/providers/common/extractors/buzzheavier.py +72 -0
- vega_cli/providers/common/extractors/cinejoy.py +33 -0
- vega_cli/providers/common/extractors/gdflix.py +170 -0
- vega_cli/providers/common/extractors/gofile.py +167 -0
- vega_cli/providers/common/extractors/hubcloud.py +277 -0
- vega_cli/providers/common/extractors/movy.py +349 -0
- vega_cli/providers/common/extractors/st111477.py +139 -0
- vega_cli/providers/common/extractors/transferit.py +53 -0
- vega_cli/providers/common/extractors/vegadrive.py +161 -0
- vega_cli/providers/common/extractors/vidstuck.py +379 -0
- vega_cli/providers/common/extractors/zcloud.py +158 -0
- vega_cli/providers/common/extractors/zypter.py +72 -0
- vega_cli/providers/common/headers.py +25 -0
- vega_cli/providers/common/http.py +121 -0
- vega_cli/providers/common/net_mirror.py +1494 -0
- vega_cli/providers/common/theintrodb.py +112 -0
- vega_cli/providers/common/unpack.py +54 -0
- vega_cli/providers/disney_mirror.py +31 -0
- vega_cli/providers/dramacool.py +297 -0
- vega_cli/providers/drive.py +695 -0
- vega_cli/providers/durbin_live.py +354 -0
- vega_cli/providers/eon_movies.py +752 -0
- vega_cli/providers/extraflix.py +701 -0
- vega_cli/providers/four_khdhub.py +307 -0
- vega_cli/providers/goku_hd.py +336 -0
- vega_cli/providers/hdhub4u.py +665 -0
- vega_cli/providers/internet_archive.py +552 -0
- vega_cli/providers/kartoons.py +642 -0
- vega_cli/providers/kartoons2.py +395 -0
- vega_cli/providers/katmovies.py +816 -0
- vega_cli/providers/kick_ass_anime.py +445 -0
- vega_cli/providers/kiss_kh.py +490 -0
- vega_cli/providers/live_tg_tv.py +540 -0
- vega_cli/providers/lux_movies.py +650 -0
- vega_cli/providers/mod.py +676 -0
- vega_cli/providers/movie_box_web.py +921 -0
- vega_cli/providers/movielinkdb.py +734 -0
- vega_cli/providers/movies4u.py +580 -0
- vega_cli/providers/moviezwap.py +199 -0
- vega_cli/providers/mxplayer.py +470 -0
- vega_cli/providers/netflix_mirror.py +32 -0
- vega_cli/providers/one_cinevood.py +596 -0
- vega_cli/providers/prime_mirror.py +31 -0
- vega_cli/providers/rareanimes.py +676 -0
- vega_cli/providers/registry.py +124 -0
- vega_cli/providers/showbox.py +245 -0
- vega_cli/providers/topmovies.py +707 -0
- vega_cli/providers/torrentio.py +398 -0
- vega_cli/providers/uhd.py +483 -0
- vega_cli/providers/vega.py +891 -0
- vega_cli/providers/youtube.py +566 -0
- vega_cli/providers/zeefliz.py +563 -0
- vega_cli/store.py +45 -0
- vega_cli/utils.py +90 -0
- vega_cli-0.1.0.dist-info/METADATA +8 -0
- vega_cli-0.1.0.dist-info/RECORD +84 -0
- vega_cli-0.1.0.dist-info/WHEEL +5 -0
- vega_cli-0.1.0.dist-info/entry_points.txt +2 -0
- vega_cli-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,921 @@
|
|
|
1
|
+
"""Pure-Python Vega MovieBox Web provider (ported from movieBoxWeb/)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
8
|
+
from typing import Any
|
|
9
|
+
from urllib.parse import parse_qs, quote, urlencode, urljoin, urlparse, urlunparse
|
|
10
|
+
|
|
11
|
+
from ..html import parse_html
|
|
12
|
+
from .common import BaseProvider, throw_provider_error
|
|
13
|
+
|
|
14
|
+
DEFAULT_BASE_URL = "https://officialmoviebox.com"
|
|
15
|
+
_PAGE_SIZE = 18
|
|
16
|
+
_DEFAULT_USER_AGENT = (
|
|
17
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
|
18
|
+
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
|
|
19
|
+
)
|
|
20
|
+
_REQUEST_HEADERS: dict[str, str] = {
|
|
21
|
+
"Cookie": "token=",
|
|
22
|
+
"Accept": "application/json",
|
|
23
|
+
"User-Agent": _DEFAULT_USER_AGENT,
|
|
24
|
+
"x-client-info": json.dumps({"timezone": "Asia/Colombo"}),
|
|
25
|
+
"x-source": "",
|
|
26
|
+
}
|
|
27
|
+
_CATALOG_HEADERS: dict[str, str] = {
|
|
28
|
+
"Accept": "application/json",
|
|
29
|
+
"x-client-info": json.dumps({"timezone": "Asia/Colombo"}),
|
|
30
|
+
"x-source": "",
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
_DETAIL_PATH_PREFIX_RE = re.compile(r"^https?://[^/]+")
|
|
34
|
+
_TITLE_GO_TO_RE = re.compile(r"^go to ", re.IGNORECASE)
|
|
35
|
+
_TITLE_DETAIL_RE = re.compile(r" detail page$", re.IGNORECASE)
|
|
36
|
+
_VALID_QUALITIES = {360, 480, 720, 1080, 2160}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _detail_path(link: str) -> str:
|
|
40
|
+
stripped = _DETAIL_PATH_PREFIX_RE.sub("", link)
|
|
41
|
+
if stripped.startswith("/moviesDetail/"):
|
|
42
|
+
return stripped[len("/moviesDetail/") :]
|
|
43
|
+
return stripped
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _absolute_url(base_url: str, path: str) -> str:
|
|
47
|
+
return urljoin(f"{base_url.rstrip('/')}/", path)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _poster_url(value: str | None, width: int = 600) -> str:
|
|
51
|
+
if not value:
|
|
52
|
+
return ""
|
|
53
|
+
try:
|
|
54
|
+
parsed = urlparse(value)
|
|
55
|
+
if not parsed.hostname or not parsed.hostname.endswith(".aoneroom.com"):
|
|
56
|
+
return value
|
|
57
|
+
qs = parse_qs(parsed.query, keep_blank_values=True)
|
|
58
|
+
qs["x-oss-process"] = [f"image/resize,w_{width},limit_1"]
|
|
59
|
+
new_query = urlencode(qs, doseq=True)
|
|
60
|
+
return urlunparse(parsed._replace(query=new_query))
|
|
61
|
+
except Exception:
|
|
62
|
+
return value
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def _decode_nuxt_data(values: Any) -> Any:
|
|
66
|
+
if not isinstance(values, list) or not values:
|
|
67
|
+
raise ValueError("Invalid Nuxt data")
|
|
68
|
+
|
|
69
|
+
hydrated: dict[int, Any] = {}
|
|
70
|
+
|
|
71
|
+
def _hydrate(index: Any) -> Any:
|
|
72
|
+
if index in (-1, -2):
|
|
73
|
+
return None
|
|
74
|
+
if index == -3:
|
|
75
|
+
return float("nan")
|
|
76
|
+
if index == -4:
|
|
77
|
+
return float("inf")
|
|
78
|
+
if index == -5:
|
|
79
|
+
return float("-inf")
|
|
80
|
+
if index == -6:
|
|
81
|
+
return -0.0
|
|
82
|
+
if not isinstance(index, int) or isinstance(index, bool) or index < 0 or index >= len(values):
|
|
83
|
+
raise ValueError("Invalid Nuxt data index")
|
|
84
|
+
if index in hydrated:
|
|
85
|
+
return hydrated[index]
|
|
86
|
+
|
|
87
|
+
value = values[index]
|
|
88
|
+
if not isinstance(value, (list, dict)):
|
|
89
|
+
hydrated[index] = value
|
|
90
|
+
return value
|
|
91
|
+
|
|
92
|
+
if isinstance(value, list):
|
|
93
|
+
tag = value[0] if value else None
|
|
94
|
+
if tag in ("Reactive", "ShallowReactive", "Ref", "ShallowRef"):
|
|
95
|
+
res = _hydrate(value[1])
|
|
96
|
+
hydrated[index] = res
|
|
97
|
+
return res
|
|
98
|
+
if tag == "Set":
|
|
99
|
+
res_set: list[Any] = []
|
|
100
|
+
hydrated[index] = res_set
|
|
101
|
+
for item in value[1:]:
|
|
102
|
+
res_set.append(_hydrate(item))
|
|
103
|
+
return res_set
|
|
104
|
+
if isinstance(tag, str):
|
|
105
|
+
raise ValueError(f"Unsupported Nuxt data type: {tag}")
|
|
106
|
+
|
|
107
|
+
res_list: list[Any] = []
|
|
108
|
+
hydrated[index] = res_list
|
|
109
|
+
for item in value:
|
|
110
|
+
res_list.append(None if item == -2 else _hydrate(item))
|
|
111
|
+
return res_list
|
|
112
|
+
|
|
113
|
+
res_dict: dict[str, Any] = {}
|
|
114
|
+
hydrated[index] = res_dict
|
|
115
|
+
for k, v in value.items():
|
|
116
|
+
if k == "__proto__":
|
|
117
|
+
raise ValueError("Invalid Nuxt data key")
|
|
118
|
+
res_dict[k] = _hydrate(v)
|
|
119
|
+
return res_dict
|
|
120
|
+
|
|
121
|
+
return _hydrate(0)
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def _parse_nuxt_data(html: str) -> Any:
|
|
125
|
+
doc = parse_html(html)
|
|
126
|
+
node = doc.select_one("#__NUXT_DATA__")
|
|
127
|
+
serialized = node.text() if node else ""
|
|
128
|
+
if not serialized:
|
|
129
|
+
return None
|
|
130
|
+
return _decode_nuxt_data(json.loads(serialized))
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def _find_detail(value: Any) -> dict[str, Any] | None:
|
|
134
|
+
if isinstance(value, dict):
|
|
135
|
+
if (
|
|
136
|
+
"subject" in value
|
|
137
|
+
and "resource" in value
|
|
138
|
+
and isinstance(value["subject"], dict)
|
|
139
|
+
and isinstance(value["resource"], dict)
|
|
140
|
+
):
|
|
141
|
+
return value
|
|
142
|
+
for child in value.values():
|
|
143
|
+
res = _find_detail(child)
|
|
144
|
+
if res is not None:
|
|
145
|
+
return res
|
|
146
|
+
elif isinstance(value, list):
|
|
147
|
+
for child in value:
|
|
148
|
+
res = _find_detail(child)
|
|
149
|
+
if res is not None:
|
|
150
|
+
return res
|
|
151
|
+
return None
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def _parse_nuxt_detail(html: str) -> dict[str, Any] | None:
|
|
155
|
+
return _find_detail(_parse_nuxt_data(html))
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def _trailer_preview(trailer: Any) -> dict[str, str] | None:
|
|
159
|
+
if not isinstance(trailer, dict):
|
|
160
|
+
return None
|
|
161
|
+
va = trailer.get("videoAddress")
|
|
162
|
+
url = va.get("url") if isinstance(va, dict) else None
|
|
163
|
+
if not isinstance(url, str) or not re.match(r"^https?://", url, re.IGNORECASE):
|
|
164
|
+
return None
|
|
165
|
+
try:
|
|
166
|
+
parsed = urlparse(url)
|
|
167
|
+
if not parsed.username and not parsed.password:
|
|
168
|
+
return {"url": url, "type": "video"}
|
|
169
|
+
except Exception:
|
|
170
|
+
pass
|
|
171
|
+
return None
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def _collect_subject_previews(value: Any) -> dict[str, dict[str, Any]]:
|
|
175
|
+
subjects: dict[str, dict[str, Any]] = {}
|
|
176
|
+
visited: set[int] = set()
|
|
177
|
+
|
|
178
|
+
def _visit(current: Any) -> None:
|
|
179
|
+
if not isinstance(current, (dict, list)):
|
|
180
|
+
return
|
|
181
|
+
oid = id(current)
|
|
182
|
+
if oid in visited:
|
|
183
|
+
return
|
|
184
|
+
visited.add(oid)
|
|
185
|
+
|
|
186
|
+
if isinstance(current, dict):
|
|
187
|
+
dp = current.get("detailPath")
|
|
188
|
+
if isinstance(dp, str):
|
|
189
|
+
cover = current.get("cover")
|
|
190
|
+
cover_url = (
|
|
191
|
+
cover.get("url")
|
|
192
|
+
if isinstance(cover, dict) and isinstance(cover.get("url"), str)
|
|
193
|
+
else None
|
|
194
|
+
)
|
|
195
|
+
subjects[dp] = {
|
|
196
|
+
"preview": _trailer_preview(current.get("trailer")),
|
|
197
|
+
"title": current.get("title") if isinstance(current.get("title"), str) else None,
|
|
198
|
+
"coverUrl": cover_url,
|
|
199
|
+
"hasResource": (
|
|
200
|
+
current.get("hasResource")
|
|
201
|
+
if isinstance(current.get("hasResource"), bool)
|
|
202
|
+
else None
|
|
203
|
+
),
|
|
204
|
+
}
|
|
205
|
+
for child in current.values():
|
|
206
|
+
_visit(child)
|
|
207
|
+
else:
|
|
208
|
+
for child in current:
|
|
209
|
+
_visit(child)
|
|
210
|
+
|
|
211
|
+
_visit(value)
|
|
212
|
+
return subjects
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
def _decode_link(value: Any) -> dict[str, Any]:
|
|
216
|
+
if isinstance(value, dict):
|
|
217
|
+
return value
|
|
218
|
+
try:
|
|
219
|
+
parsed = json.loads(value)
|
|
220
|
+
if isinstance(parsed, dict):
|
|
221
|
+
return parsed
|
|
222
|
+
except Exception:
|
|
223
|
+
pass
|
|
224
|
+
return {
|
|
225
|
+
"subjectId": "",
|
|
226
|
+
"detailPath": _detail_path(str(value or "")),
|
|
227
|
+
"language": "Original",
|
|
228
|
+
"season": 1,
|
|
229
|
+
"episode": 1,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def _get_quality(resolutions: str | None) -> str | None:
|
|
234
|
+
vals = []
|
|
235
|
+
for part in (resolutions or "").split(","):
|
|
236
|
+
part = part.strip()
|
|
237
|
+
if part.isdigit() and int(part) in _VALID_QUALITIES:
|
|
238
|
+
vals.append(int(part))
|
|
239
|
+
return str(max(vals)) if vals else None
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
def _get_stream_type(fmt: str | None, url: str | None) -> str:
|
|
243
|
+
norm = (fmt or "").upper()
|
|
244
|
+
if norm in ("HLS", "M3U8"):
|
|
245
|
+
return "m3u8"
|
|
246
|
+
if norm in ("DASH", "MPD"):
|
|
247
|
+
return "mpd"
|
|
248
|
+
if url:
|
|
249
|
+
clean = url.split("?")[0].lower()
|
|
250
|
+
if clean.endswith(".m3u8"):
|
|
251
|
+
return "m3u8"
|
|
252
|
+
if clean.endswith(".mpd"):
|
|
253
|
+
return "mpd"
|
|
254
|
+
return "mp4"
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _map_captions(captions: list[dict[str, Any]]) -> list[dict[str, str]]:
|
|
258
|
+
out: list[dict[str, str]] = []
|
|
259
|
+
for cap in captions:
|
|
260
|
+
url = cap.get("url")
|
|
261
|
+
if not url:
|
|
262
|
+
continue
|
|
263
|
+
out.append(
|
|
264
|
+
{
|
|
265
|
+
"title": cap.get("lanName") or cap.get("lan") or "Subtitle",
|
|
266
|
+
"language": cap.get("lan") or "und",
|
|
267
|
+
"type": "text/vtt" if ".vtt" in url else "application/x-subrip",
|
|
268
|
+
"uri": url,
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
return out
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def _has_playable_streams(result: Any) -> bool:
|
|
275
|
+
if (
|
|
276
|
+
not isinstance(result, dict)
|
|
277
|
+
or result.get("noContent")
|
|
278
|
+
or result.get("code") != 0
|
|
279
|
+
or (result.get("data") or {}).get("hasResource") is False
|
|
280
|
+
):
|
|
281
|
+
return False
|
|
282
|
+
data = result.get("data") or {}
|
|
283
|
+
sources = [
|
|
284
|
+
*(data.get("streams") or []),
|
|
285
|
+
*(data.get("hls") or []),
|
|
286
|
+
*(data.get("dash") or []),
|
|
287
|
+
]
|
|
288
|
+
return any(isinstance(s, dict) and s.get("url") and not s.get("vipLocked") for s in sources)
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
class MovieBoxWebClient(BaseProvider):
|
|
292
|
+
"""Client for the MovieBox Web provider."""
|
|
293
|
+
|
|
294
|
+
name: str = "movieBoxWeb"
|
|
295
|
+
catalog: list[dict[str, str]] = [
|
|
296
|
+
{"title": "Trending", "filter": "/"},
|
|
297
|
+
{"title": "Movies", "filter": "/newWeb/movie"},
|
|
298
|
+
{"title": "TV Series", "filter": "/newWeb/tv-series"},
|
|
299
|
+
]
|
|
300
|
+
genres: list[dict[str, str]] = []
|
|
301
|
+
settings_schema: list[dict[str, Any]] = [
|
|
302
|
+
{
|
|
303
|
+
"key": "quickDownload",
|
|
304
|
+
"type": "toggle",
|
|
305
|
+
"label": "Quick Download",
|
|
306
|
+
"description": "Turn off to choose download options manually.",
|
|
307
|
+
"defaultValue": True,
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
"key": "downloadSubtitle",
|
|
311
|
+
"type": "select",
|
|
312
|
+
"label": "Quick download subtitle language",
|
|
313
|
+
"description": "Uses the first available subtitle when the selected language is unavailable.",
|
|
314
|
+
"defaultValue": "",
|
|
315
|
+
"options": [
|
|
316
|
+
{"label": "First available", "value": ""},
|
|
317
|
+
{"label": "English", "value": "en"},
|
|
318
|
+
{"label": "Arabic", "value": "ar"},
|
|
319
|
+
{"label": "Bengali", "value": "bn"},
|
|
320
|
+
{"label": "Chinese", "value": "zh"},
|
|
321
|
+
{"label": "Filipino", "value": "fil"},
|
|
322
|
+
{"label": "French", "value": "fr"},
|
|
323
|
+
{"label": "Hausa", "value": "ha"},
|
|
324
|
+
{"label": "Hindi", "value": "hi"},
|
|
325
|
+
{"label": "Indonesian", "value": "in_id"},
|
|
326
|
+
{"label": "Malay", "value": "ms"},
|
|
327
|
+
{"label": "Persian", "value": "fa"},
|
|
328
|
+
{"label": "Portuguese", "value": "pt"},
|
|
329
|
+
{"label": "Punjabi", "value": "pa"},
|
|
330
|
+
{"label": "Russian", "value": "ru"},
|
|
331
|
+
{"label": "Spanish", "value": "es"},
|
|
332
|
+
{"label": "Swahili", "value": "sw"},
|
|
333
|
+
{"label": "Thai", "value": "th"},
|
|
334
|
+
{"label": "Turkish", "value": "tr"},
|
|
335
|
+
{"label": "Urdu", "value": "ur"},
|
|
336
|
+
{"label": "Vietnamese", "value": "vi"},
|
|
337
|
+
],
|
|
338
|
+
},
|
|
339
|
+
{
|
|
340
|
+
"key": "downloadQuality",
|
|
341
|
+
"type": "select",
|
|
342
|
+
"label": "Quick download quality",
|
|
343
|
+
"description": (
|
|
344
|
+
"Uses the nearest available quality if your choice is unavailable. "
|
|
345
|
+
"Equally close qualities prefer the higher resolution."
|
|
346
|
+
),
|
|
347
|
+
"defaultValue": "highest",
|
|
348
|
+
"options": [
|
|
349
|
+
{"label": "Highest available", "value": "highest"},
|
|
350
|
+
*[
|
|
351
|
+
{"label": f"{q}p", "value": str(q)}
|
|
352
|
+
for q in (2160, 1080, 720, 480, 360)
|
|
353
|
+
],
|
|
354
|
+
],
|
|
355
|
+
},
|
|
356
|
+
]
|
|
357
|
+
|
|
358
|
+
def _fetch_html_posts(self, path: str) -> list[dict[str, Any]]:
|
|
359
|
+
url = _absolute_url(DEFAULT_BASE_URL, path)
|
|
360
|
+
html = self.fetch_text(url)
|
|
361
|
+
doc = parse_html(html)
|
|
362
|
+
subjects = _collect_subject_previews(_parse_nuxt_data(html))
|
|
363
|
+
posts: list[dict[str, Any]] = []
|
|
364
|
+
seen: set[str] = set()
|
|
365
|
+
|
|
366
|
+
for card in doc.select('a[href^="/moviesDetail/"]'):
|
|
367
|
+
href = card.attr("href")
|
|
368
|
+
if not href.startswith("/moviesDetail/") or href in seen:
|
|
369
|
+
continue
|
|
370
|
+
subject = subjects.get(href[len("/moviesDetail/") :])
|
|
371
|
+
if path == "/upcoming" and (not subject or subject.get("hasResource") is not True):
|
|
372
|
+
continue
|
|
373
|
+
|
|
374
|
+
img = card.select_one("img")
|
|
375
|
+
heading = card.select_one("h2, h3")
|
|
376
|
+
card_title_attr = card.attr("title")
|
|
377
|
+
if card_title_attr:
|
|
378
|
+
card_title_attr = _TITLE_DETAIL_RE.sub(
|
|
379
|
+
"", _TITLE_GO_TO_RE.sub("", card_title_attr)
|
|
380
|
+
).strip()
|
|
381
|
+
title = (
|
|
382
|
+
(subject.get("title") or "").strip()
|
|
383
|
+
if subject and subject.get("title")
|
|
384
|
+
else ""
|
|
385
|
+
) or (
|
|
386
|
+
heading.attr("title").strip() if heading and heading.attr("title") else ""
|
|
387
|
+
) or (
|
|
388
|
+
img.attr("alt").strip() if img and img.attr("alt") else ""
|
|
389
|
+
) or (
|
|
390
|
+
heading.text().strip() if heading else ""
|
|
391
|
+
) or card_title_attr
|
|
392
|
+
if not title:
|
|
393
|
+
continue
|
|
394
|
+
|
|
395
|
+
seen.add(href)
|
|
396
|
+
raw_img = (
|
|
397
|
+
(img.attr("data-src") if img else "")
|
|
398
|
+
or (subject.get("coverUrl") if subject else "")
|
|
399
|
+
or (img.attr("src") if img else "")
|
|
400
|
+
)
|
|
401
|
+
post: dict[str, Any] = {
|
|
402
|
+
"title": title,
|
|
403
|
+
"link": href,
|
|
404
|
+
"image": _poster_url(raw_img),
|
|
405
|
+
}
|
|
406
|
+
if subject and subject.get("preview"):
|
|
407
|
+
post["preview"] = subject["preview"]
|
|
408
|
+
posts.append(post)
|
|
409
|
+
return posts
|
|
410
|
+
|
|
411
|
+
def _fetch_catalog_page(self, filter_path: str, page: int) -> list[dict[str, Any]]:
|
|
412
|
+
params: dict[str, str] = {
|
|
413
|
+
"page": str(max(1, page)),
|
|
414
|
+
"perPage": str(_PAGE_SIZE),
|
|
415
|
+
}
|
|
416
|
+
if filter_path == "/newWeb/movie":
|
|
417
|
+
params["tabId"] = "ONEROOM_MOVIE"
|
|
418
|
+
url = _absolute_url(
|
|
419
|
+
DEFAULT_BASE_URL,
|
|
420
|
+
f"/wefeed-h5api-bff/subject/trending?{urlencode(params)}",
|
|
421
|
+
)
|
|
422
|
+
payload = self.fetch_json(url, headers=_CATALOG_HEADERS)
|
|
423
|
+
if not isinstance(payload, dict) or payload.get("code") != 0:
|
|
424
|
+
msg = (
|
|
425
|
+
payload.get("message")
|
|
426
|
+
if isinstance(payload, dict)
|
|
427
|
+
else "MovieBox Web catalog request failed"
|
|
428
|
+
)
|
|
429
|
+
raise RuntimeError(msg or "MovieBox Web catalog request failed")
|
|
430
|
+
|
|
431
|
+
posts: list[dict[str, Any]] = []
|
|
432
|
+
for subj in (payload.get("data") or {}).get("subjectList") or []:
|
|
433
|
+
dp = subj.get("detailPath")
|
|
434
|
+
title = subj.get("title")
|
|
435
|
+
if not dp or not title or subj.get("hasResource") is False:
|
|
436
|
+
continue
|
|
437
|
+
cover = subj.get("cover")
|
|
438
|
+
cover_url = cover.get("url") if isinstance(cover, dict) else None
|
|
439
|
+
post: dict[str, Any] = {
|
|
440
|
+
"title": title,
|
|
441
|
+
"link": f"/moviesDetail/{dp}",
|
|
442
|
+
"image": _poster_url(cover_url),
|
|
443
|
+
}
|
|
444
|
+
preview = _trailer_preview(subj.get("trailer"))
|
|
445
|
+
if preview:
|
|
446
|
+
post["preview"] = preview
|
|
447
|
+
posts.append(post)
|
|
448
|
+
return posts
|
|
449
|
+
|
|
450
|
+
def get_posts(self, filter_path: str = "", page: int = 1) -> list[dict[str, Any]]:
|
|
451
|
+
path = filter_path or "/"
|
|
452
|
+
if path in ("/", "/newWeb/movie", "/newWeb/tv-series"):
|
|
453
|
+
return self._fetch_catalog_page(path, page)
|
|
454
|
+
if page > 1:
|
|
455
|
+
return []
|
|
456
|
+
return self._fetch_html_posts(path)
|
|
457
|
+
|
|
458
|
+
def get_search_posts(self, query: str, page: int = 1) -> list[dict[str, Any]]:
|
|
459
|
+
if page > 1 or not query.strip():
|
|
460
|
+
return []
|
|
461
|
+
return self._fetch_html_posts(
|
|
462
|
+
f"/newWeb/searchResult?keyword={quote(query.strip())}"
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
def get_meta(self, link: str) -> dict[str, Any]:
|
|
466
|
+
try:
|
|
467
|
+
page_url = _absolute_url(DEFAULT_BASE_URL, f"/moviesDetail/{_detail_path(link)}")
|
|
468
|
+
html = self.fetch_text(page_url)
|
|
469
|
+
detail = _parse_nuxt_detail(html)
|
|
470
|
+
if not detail:
|
|
471
|
+
raise RuntimeError("MovieBox Web detail data was not found")
|
|
472
|
+
|
|
473
|
+
subject = detail["subject"]
|
|
474
|
+
resource = detail["resource"]
|
|
475
|
+
seasons = resource.get("seasons")
|
|
476
|
+
is_series = subject.get("subjectType") == 2
|
|
477
|
+
|
|
478
|
+
dubs = subject.get("dubs") or [
|
|
479
|
+
{
|
|
480
|
+
"subjectId": subject.get("subjectId"),
|
|
481
|
+
"detailPath": subject.get("detailPath"),
|
|
482
|
+
"lanName": "Original",
|
|
483
|
+
}
|
|
484
|
+
]
|
|
485
|
+
|
|
486
|
+
def _build_playback_link(dub: dict[str, Any]) -> str:
|
|
487
|
+
movie_season = next(
|
|
488
|
+
(s for s in (seasons or []) if s.get("se") == 0),
|
|
489
|
+
(seasons or [None])[0],
|
|
490
|
+
)
|
|
491
|
+
first_series_season = next(
|
|
492
|
+
(s for s in (seasons or []) if (s.get("se") or 0) > 0),
|
|
493
|
+
(seasons or [None])[0],
|
|
494
|
+
)
|
|
495
|
+
movie_res = None
|
|
496
|
+
if movie_season and movie_season.get("resolutions"):
|
|
497
|
+
valid_res = [
|
|
498
|
+
r for r in movie_season["resolutions"] if (r.get("epNum") or 0) >= 1
|
|
499
|
+
]
|
|
500
|
+
valid_res.sort(key=lambda r: r.get("resolution") or 0, reverse=True)
|
|
501
|
+
if valid_res:
|
|
502
|
+
movie_res = valid_res[0].get("resolution")
|
|
503
|
+
|
|
504
|
+
target_sid = dub.get("subjectId") or subject.get("subjectId") or ""
|
|
505
|
+
target_dp = dub.get("detailPath") or subject.get("detailPath") or ""
|
|
506
|
+
|
|
507
|
+
alt_dub = next(
|
|
508
|
+
(
|
|
509
|
+
d
|
|
510
|
+
for d in (subject.get("dubs") or [])
|
|
511
|
+
if d.get("subjectId")
|
|
512
|
+
and d.get("subjectId") != target_sid
|
|
513
|
+
and (
|
|
514
|
+
d.get("original")
|
|
515
|
+
or "original" in str(d.get("lanName") or "").lower()
|
|
516
|
+
or d.get("lanCode") == "en"
|
|
517
|
+
)
|
|
518
|
+
),
|
|
519
|
+
None,
|
|
520
|
+
) or next(
|
|
521
|
+
(
|
|
522
|
+
d
|
|
523
|
+
for d in (subject.get("dubs") or [])
|
|
524
|
+
if d.get("subjectId") and d.get("subjectId") != target_sid
|
|
525
|
+
),
|
|
526
|
+
None,
|
|
527
|
+
)
|
|
528
|
+
|
|
529
|
+
fb_sid = (
|
|
530
|
+
subject.get("subjectId")
|
|
531
|
+
if subject.get("subjectId") and subject.get("subjectId") != target_sid
|
|
532
|
+
else (alt_dub.get("subjectId") if alt_dub else None)
|
|
533
|
+
)
|
|
534
|
+
fb_dp = (
|
|
535
|
+
subject.get("detailPath")
|
|
536
|
+
if subject.get("detailPath") and subject.get("detailPath") != target_dp
|
|
537
|
+
else (alt_dub.get("detailPath") if alt_dub else None)
|
|
538
|
+
)
|
|
539
|
+
|
|
540
|
+
return json.dumps(
|
|
541
|
+
{
|
|
542
|
+
"subjectId": target_sid,
|
|
543
|
+
"detailPath": target_dp,
|
|
544
|
+
"fallbackSubjectId": fb_sid,
|
|
545
|
+
"fallbackDetailPath": fb_dp,
|
|
546
|
+
"language": dub.get("lanName") or dub.get("lanCode") or "Original",
|
|
547
|
+
"season": (
|
|
548
|
+
(first_series_season.get("se") or 1)
|
|
549
|
+
if is_series and first_series_season
|
|
550
|
+
else (movie_season.get("se") or 0 if movie_season else 0)
|
|
551
|
+
),
|
|
552
|
+
"episode": 1,
|
|
553
|
+
"resolution": None if is_series else movie_res,
|
|
554
|
+
"seasons": seasons,
|
|
555
|
+
}
|
|
556
|
+
)
|
|
557
|
+
|
|
558
|
+
link_list: list[dict[str, Any]] = []
|
|
559
|
+
if subject.get("hasResource") is not False:
|
|
560
|
+
for dub in dubs:
|
|
561
|
+
if not (
|
|
562
|
+
dub.get("subjectId")
|
|
563
|
+
and (dub.get("detailPath") or subject.get("detailPath"))
|
|
564
|
+
):
|
|
565
|
+
continue
|
|
566
|
+
pb_link = _build_playback_link(dub)
|
|
567
|
+
lang_label = dub.get("lanName") or dub.get("lanCode") or "Original"
|
|
568
|
+
if is_series:
|
|
569
|
+
link_list.append({"title": lang_label, "episodesLink": pb_link})
|
|
570
|
+
else:
|
|
571
|
+
link_list.append(
|
|
572
|
+
{
|
|
573
|
+
"title": lang_label,
|
|
574
|
+
"directLinks": [
|
|
575
|
+
{
|
|
576
|
+
"title": lang_label,
|
|
577
|
+
"link": pb_link,
|
|
578
|
+
"type": "movie",
|
|
579
|
+
}
|
|
580
|
+
],
|
|
581
|
+
}
|
|
582
|
+
)
|
|
583
|
+
|
|
584
|
+
tags = [
|
|
585
|
+
t
|
|
586
|
+
for t in [
|
|
587
|
+
subject.get("countryName"),
|
|
588
|
+
str(subject.get("releaseDate") or "")[:4],
|
|
589
|
+
*[g.strip() for g in str(subject.get("genre") or "").split(",")],
|
|
590
|
+
]
|
|
591
|
+
if t
|
|
592
|
+
]
|
|
593
|
+
cover = subject.get("cover")
|
|
594
|
+
cover_url = cover.get("url") if isinstance(cover, dict) else None
|
|
595
|
+
|
|
596
|
+
return {
|
|
597
|
+
"title": subject.get("title") or "",
|
|
598
|
+
"image": _poster_url(cover_url, 900),
|
|
599
|
+
"synopsis": subject.get("description") or "",
|
|
600
|
+
"imdbId": "",
|
|
601
|
+
"type": "series" if is_series else "movie",
|
|
602
|
+
"quickDownload": self.kv.get("quickDownload") is not False,
|
|
603
|
+
"tags": tags,
|
|
604
|
+
"cast": [
|
|
605
|
+
s.get("name")
|
|
606
|
+
for s in (subject.get("stars") or [])
|
|
607
|
+
if isinstance(s, dict) and s.get("name")
|
|
608
|
+
],
|
|
609
|
+
"rating": subject.get("imdbRatingValue") or "",
|
|
610
|
+
"linkList": link_list,
|
|
611
|
+
"webUrl": page_url,
|
|
612
|
+
}
|
|
613
|
+
except Exception as err:
|
|
614
|
+
throw_provider_error("MovieBox Web", "metadata", err)
|
|
615
|
+
|
|
616
|
+
def get_episodes(
|
|
617
|
+
self,
|
|
618
|
+
url: str,
|
|
619
|
+
imdb_id: str = "",
|
|
620
|
+
season: int | None = None,
|
|
621
|
+
) -> list[dict[str, Any]]:
|
|
622
|
+
try:
|
|
623
|
+
playback = _decode_link(url)
|
|
624
|
+
episodes: list[dict[str, Any]] = []
|
|
625
|
+
for s in playback.get("seasons") or []:
|
|
626
|
+
season_num = s.get("se") or 1
|
|
627
|
+
resolutions = s.get("resolutions") or []
|
|
628
|
+
max_ep_from_res = (
|
|
629
|
+
max((r.get("epNum") or 0 for r in resolutions), default=0)
|
|
630
|
+
if resolutions
|
|
631
|
+
else 0
|
|
632
|
+
)
|
|
633
|
+
all_ep = s.get("allEp")
|
|
634
|
+
if all_ep:
|
|
635
|
+
avail = [
|
|
636
|
+
int(x)
|
|
637
|
+
for x in str(all_ep).split(",")
|
|
638
|
+
if x.strip().isdigit() and int(x.strip()) > 0
|
|
639
|
+
]
|
|
640
|
+
else:
|
|
641
|
+
max_ep = s.get("maxEp") or 0
|
|
642
|
+
count = min(max_ep or max_ep_from_res, max_ep_from_res) if max_ep_from_res > 0 else max_ep
|
|
643
|
+
avail = list(range(1, count + 1))
|
|
644
|
+
|
|
645
|
+
for ep in avail:
|
|
646
|
+
matching_res = [
|
|
647
|
+
r for r in resolutions if (r.get("epNum") or 0) >= ep
|
|
648
|
+
]
|
|
649
|
+
matching_res.sort(key=lambda r: r.get("resolution") or 0, reverse=True)
|
|
650
|
+
resolution = matching_res[0].get("resolution") if matching_res else None
|
|
651
|
+
if resolutions and not resolution:
|
|
652
|
+
continue
|
|
653
|
+
ep_payload = dict(playback)
|
|
654
|
+
ep_payload.pop("seasons", None)
|
|
655
|
+
ep_payload["season"] = season_num
|
|
656
|
+
ep_payload["episode"] = ep
|
|
657
|
+
ep_payload["resolution"] = resolution
|
|
658
|
+
episodes.append(
|
|
659
|
+
{
|
|
660
|
+
"title": f"S{season_num:02d} E{ep:02d}",
|
|
661
|
+
"link": json.dumps(ep_payload),
|
|
662
|
+
}
|
|
663
|
+
)
|
|
664
|
+
return episodes
|
|
665
|
+
except Exception as err:
|
|
666
|
+
throw_provider_error("MovieBox Web", "episodes", err)
|
|
667
|
+
|
|
668
|
+
def _fetch_play_data(
|
|
669
|
+
self,
|
|
670
|
+
params: dict[str, str],
|
|
671
|
+
referer_url: str,
|
|
672
|
+
user_agent: str,
|
|
673
|
+
) -> dict[str, Any] | None:
|
|
674
|
+
play_url = _absolute_url(
|
|
675
|
+
DEFAULT_BASE_URL,
|
|
676
|
+
f"/wefeed-h5api-bff/subject/play?{urlencode(params)}",
|
|
677
|
+
)
|
|
678
|
+
headers = {
|
|
679
|
+
**_REQUEST_HEADERS,
|
|
680
|
+
"User-Agent": user_agent,
|
|
681
|
+
"Referer": referer_url,
|
|
682
|
+
}
|
|
683
|
+
try:
|
|
684
|
+
resp = self.session.get(play_url, headers=headers, timeout=15)
|
|
685
|
+
if resp.status_code == 429:
|
|
686
|
+
raise RuntimeError(
|
|
687
|
+
"MovieBox is temporarily rate limiting playback. Please try again later."
|
|
688
|
+
)
|
|
689
|
+
if resp.status_code == 406:
|
|
690
|
+
return {"noContent": True}
|
|
691
|
+
if not (200 <= resp.status_code < 300):
|
|
692
|
+
return None
|
|
693
|
+
data = resp.json()
|
|
694
|
+
if isinstance(data, dict):
|
|
695
|
+
if (data.get("data") or {}).get("limited") and not _has_playable_streams(data):
|
|
696
|
+
raise RuntimeError(
|
|
697
|
+
"MovieBox is limiting playback for this session. Please try again later."
|
|
698
|
+
)
|
|
699
|
+
if data.get("code") == 406 or "find no content" in str(data.get("message") or ""):
|
|
700
|
+
return {"noContent": True}
|
|
701
|
+
return data
|
|
702
|
+
except RuntimeError:
|
|
703
|
+
raise
|
|
704
|
+
except Exception:
|
|
705
|
+
return None
|
|
706
|
+
|
|
707
|
+
def _get_captions(
|
|
708
|
+
self,
|
|
709
|
+
playback: dict[str, Any],
|
|
710
|
+
source: dict[str, Any],
|
|
711
|
+
referer: str,
|
|
712
|
+
user_agent: str,
|
|
713
|
+
) -> list[dict[str, str]]:
|
|
714
|
+
try:
|
|
715
|
+
sid = source.get("id")
|
|
716
|
+
fmt = source.get("format")
|
|
717
|
+
if not sid or not fmt:
|
|
718
|
+
return []
|
|
719
|
+
params = urlencode(
|
|
720
|
+
{
|
|
721
|
+
"format": fmt,
|
|
722
|
+
"id": sid,
|
|
723
|
+
"subjectId": playback.get("subjectId", ""),
|
|
724
|
+
"detailPath": playback.get("detailPath", ""),
|
|
725
|
+
}
|
|
726
|
+
)
|
|
727
|
+
url = _absolute_url(DEFAULT_BASE_URL, f"/wefeed-h5api-bff/subject/caption?{params}")
|
|
728
|
+
headers = {**_REQUEST_HEADERS, "User-Agent": user_agent, "Referer": referer}
|
|
729
|
+
resp = self.session.get(url, headers=headers, timeout=10)
|
|
730
|
+
if not (200 <= resp.status_code < 300):
|
|
731
|
+
return []
|
|
732
|
+
data = resp.json()
|
|
733
|
+
return _map_captions((data.get("data") or {}).get("captions") or [])
|
|
734
|
+
except Exception:
|
|
735
|
+
return []
|
|
736
|
+
|
|
737
|
+
def get_stream(
|
|
738
|
+
self,
|
|
739
|
+
url: str,
|
|
740
|
+
is_download: bool = False,
|
|
741
|
+
media_type: str = "movie",
|
|
742
|
+
) -> list[dict[str, Any]]:
|
|
743
|
+
try:
|
|
744
|
+
playback = _decode_link(url)
|
|
745
|
+
user_agent = str(self.session.headers.get("User-Agent") or _DEFAULT_USER_AGENT)
|
|
746
|
+
stream_headers = {
|
|
747
|
+
"Referer": f"{DEFAULT_BASE_URL}/",
|
|
748
|
+
"Origin": DEFAULT_BASE_URL,
|
|
749
|
+
"User-Agent": user_agent,
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
if not playback.get("subjectId") and playback.get("detailPath"):
|
|
753
|
+
try:
|
|
754
|
+
detail_url = _absolute_url(
|
|
755
|
+
DEFAULT_BASE_URL, f"/moviesDetail/{playback['detailPath']}"
|
|
756
|
+
)
|
|
757
|
+
detail = _parse_nuxt_detail(self.fetch_text(detail_url))
|
|
758
|
+
sid = (detail or {}).get("subject", {}).get("subjectId")
|
|
759
|
+
if sid:
|
|
760
|
+
playback["subjectId"] = sid
|
|
761
|
+
if not playback.get("fallbackSubjectId"):
|
|
762
|
+
playback["fallbackSubjectId"] = sid
|
|
763
|
+
except Exception:
|
|
764
|
+
pass
|
|
765
|
+
|
|
766
|
+
seasons = playback.get("seasons") or []
|
|
767
|
+
is_series = bool(
|
|
768
|
+
(playback.get("season") is not None and int(playback["season"]) > 0)
|
|
769
|
+
or any((s.get("se") or 0) > 0 for s in seasons)
|
|
770
|
+
)
|
|
771
|
+
season_num = (
|
|
772
|
+
int(playback["season"])
|
|
773
|
+
if playback.get("season") is not None
|
|
774
|
+
else next((int(s["se"]) for s in seasons if (s.get("se") or 0) > 0), 1)
|
|
775
|
+
)
|
|
776
|
+
ep_num = int(playback["episode"]) if playback.get("episode") is not None else 1
|
|
777
|
+
|
|
778
|
+
watch_params = urlencode(
|
|
779
|
+
{
|
|
780
|
+
"id": playback.get("subjectId", ""),
|
|
781
|
+
"type": "/movie/detail",
|
|
782
|
+
"detailSe": str(season_num) if is_series and season_num > 0 else "",
|
|
783
|
+
"detailEp": str(ep_num) if is_series and ep_num > 0 else "",
|
|
784
|
+
"lang": "en",
|
|
785
|
+
}
|
|
786
|
+
)
|
|
787
|
+
referer = _absolute_url(
|
|
788
|
+
DEFAULT_BASE_URL, f"/movies/{playback.get('detailPath', '')}?{watch_params}"
|
|
789
|
+
)
|
|
790
|
+
play_params: dict[str, str] = {
|
|
791
|
+
"subjectId": str(playback.get("subjectId", "")),
|
|
792
|
+
"detailPath": str(playback.get("detailPath", "")),
|
|
793
|
+
}
|
|
794
|
+
if is_series and season_num > 0:
|
|
795
|
+
play_params["se"] = str(season_num)
|
|
796
|
+
play_params["ep"] = str(ep_num)
|
|
797
|
+
|
|
798
|
+
play_result = self._fetch_play_data(play_params, referer, user_agent)
|
|
799
|
+
|
|
800
|
+
if not _has_playable_streams(play_result) and (
|
|
801
|
+
playback.get("fallbackSubjectId") or playback.get("fallbackDetailPath")
|
|
802
|
+
):
|
|
803
|
+
fb_sid = str(playback.get("fallbackSubjectId") or playback.get("subjectId") or "")
|
|
804
|
+
fb_dp = str(playback.get("fallbackDetailPath") or playback.get("detailPath") or "")
|
|
805
|
+
fb_params: dict[str, str] = {"subjectId": fb_sid, "detailPath": fb_dp}
|
|
806
|
+
if is_series and season_num > 0:
|
|
807
|
+
fb_params["se"] = str(season_num)
|
|
808
|
+
fb_params["ep"] = str(ep_num)
|
|
809
|
+
fb_watch = urlencode(
|
|
810
|
+
{
|
|
811
|
+
"id": fb_sid,
|
|
812
|
+
"type": "/movie/detail",
|
|
813
|
+
"detailSe": str(season_num) if is_series and season_num > 0 else "",
|
|
814
|
+
"detailEp": str(ep_num) if is_series and ep_num > 0 else "",
|
|
815
|
+
"lang": "en",
|
|
816
|
+
}
|
|
817
|
+
)
|
|
818
|
+
fb_ref = _absolute_url(DEFAULT_BASE_URL, f"/movies/{fb_dp}?{fb_watch}")
|
|
819
|
+
fb_res = self._fetch_play_data(fb_params, fb_ref, user_agent)
|
|
820
|
+
if _has_playable_streams(fb_res):
|
|
821
|
+
play_result = fb_res
|
|
822
|
+
|
|
823
|
+
if not _has_playable_streams(play_result):
|
|
824
|
+
clean_res = self._fetch_play_data(
|
|
825
|
+
{
|
|
826
|
+
"subjectId": str(playback.get("subjectId", "")),
|
|
827
|
+
"detailPath": str(playback.get("detailPath", "")),
|
|
828
|
+
},
|
|
829
|
+
referer,
|
|
830
|
+
user_agent,
|
|
831
|
+
)
|
|
832
|
+
if _has_playable_streams(clean_res):
|
|
833
|
+
play_result = clean_res
|
|
834
|
+
|
|
835
|
+
if (
|
|
836
|
+
not isinstance(play_result, dict)
|
|
837
|
+
or play_result.get("noContent")
|
|
838
|
+
or (play_result.get("data") or {}).get("hasResource") is False
|
|
839
|
+
):
|
|
840
|
+
return []
|
|
841
|
+
|
|
842
|
+
if play_result.get("code") != 0:
|
|
843
|
+
raise RuntimeError(
|
|
844
|
+
play_result.get("message")
|
|
845
|
+
or f"MovieBox Web play API code {play_result.get('code')}"
|
|
846
|
+
)
|
|
847
|
+
|
|
848
|
+
play_data = play_result.get("data")
|
|
849
|
+
if not isinstance(play_data, dict):
|
|
850
|
+
return []
|
|
851
|
+
|
|
852
|
+
sources = [
|
|
853
|
+
*(play_data.get("streams") or []),
|
|
854
|
+
*(play_data.get("hls") or []),
|
|
855
|
+
*(play_data.get("dash") or []),
|
|
856
|
+
]
|
|
857
|
+
available = [
|
|
858
|
+
s for s in sources if isinstance(s, dict) and s.get("url") and not s.get("vipLocked")
|
|
859
|
+
]
|
|
860
|
+
|
|
861
|
+
def _build_stream(src: dict[str, Any]) -> dict[str, Any]:
|
|
862
|
+
res_str = src.get("resolutions") or src.get("format") or ""
|
|
863
|
+
return {
|
|
864
|
+
"server": f"{playback.get('language', 'Original')} {res_str}".strip(),
|
|
865
|
+
"link": src.get("url") or "",
|
|
866
|
+
"type": _get_stream_type(src.get("format"), src.get("url")),
|
|
867
|
+
"quality": _get_quality(src.get("resolutions")),
|
|
868
|
+
"subtitles": self._get_captions(playback, src, referer, user_agent),
|
|
869
|
+
"headers": stream_headers,
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
with ThreadPoolExecutor(max_workers=max(1, min(6, len(available)))) as pool:
|
|
873
|
+
streams = list(pool.map(_build_stream, available))
|
|
874
|
+
|
|
875
|
+
if is_download:
|
|
876
|
+
preferred = self.kv.get("downloadQuality")
|
|
877
|
+
sub_pref = self.kv.get("downloadSubtitle")
|
|
878
|
+
|
|
879
|
+
def _norm_lang(val: str) -> str:
|
|
880
|
+
return val.strip().lower().replace("_", "-")
|
|
881
|
+
|
|
882
|
+
lang = _norm_lang(str(sub_pref or ""))
|
|
883
|
+
if lang:
|
|
884
|
+
for st in streams:
|
|
885
|
+
subs = st.get("subtitles") or []
|
|
886
|
+
idx = next(
|
|
887
|
+
(
|
|
888
|
+
i
|
|
889
|
+
for i, tr in enumerate(subs)
|
|
890
|
+
if _norm_lang(tr.get("language", "")) == lang
|
|
891
|
+
or _norm_lang(tr.get("title", "")) == lang
|
|
892
|
+
),
|
|
893
|
+
-1,
|
|
894
|
+
)
|
|
895
|
+
if idx < 0:
|
|
896
|
+
idx = next(
|
|
897
|
+
(
|
|
898
|
+
i
|
|
899
|
+
for i, tr in enumerate(subs)
|
|
900
|
+
if _norm_lang(tr.get("language", "")).startswith(f"{lang}-")
|
|
901
|
+
),
|
|
902
|
+
-1,
|
|
903
|
+
)
|
|
904
|
+
if idx > 0:
|
|
905
|
+
subs.insert(0, subs.pop(idx))
|
|
906
|
+
|
|
907
|
+
target = 0 if (not preferred or preferred == "highest") else int(preferred)
|
|
908
|
+
|
|
909
|
+
def _dl_sort_key(st: dict[str, Any]) -> tuple[int, int, int]:
|
|
910
|
+
qa = int(st["quality"]) if st.get("quality") else 0
|
|
911
|
+
if not qa:
|
|
912
|
+
return (1, 0, 0)
|
|
913
|
+
if target > 0:
|
|
914
|
+
return (0, abs(qa - target), -qa)
|
|
915
|
+
return (0, 0, -qa)
|
|
916
|
+
|
|
917
|
+
streams.sort(key=_dl_sort_key)
|
|
918
|
+
|
|
919
|
+
return streams
|
|
920
|
+
except Exception as err:
|
|
921
|
+
throw_provider_error("MovieBox Web", "stream", err)
|