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,540 @@
|
|
|
1
|
+
"""Pure-Python Vega LiveTG TV provider."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import re
|
|
7
|
+
import time
|
|
8
|
+
from typing import Any
|
|
9
|
+
from urllib.parse import parse_qsl, quote, unquote
|
|
10
|
+
|
|
11
|
+
import requests
|
|
12
|
+
|
|
13
|
+
from .common import BaseProvider, COMMON_HEADERS, throw_provider_error
|
|
14
|
+
|
|
15
|
+
_WEBSITE = "https://livetgtv.lovable.app"
|
|
16
|
+
_CHANNELS_URL = f"{_WEBSITE}/api/public/channels"
|
|
17
|
+
_PLAYLIST_URL = f"{_WEBSITE}/api/public/playlist.m3u"
|
|
18
|
+
_LINK_PREFIX = "livetgtv://channel/"
|
|
19
|
+
_CACHE_KEY = "channelMetadataV1"
|
|
20
|
+
_CACHE_TTL_MS = 300_000
|
|
21
|
+
_PAGE_SIZE = 40
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def _channel_detail_url(channel_id: str) -> str:
|
|
25
|
+
return f"{_WEBSITE}/api/public/channels/{quote(channel_id, safe='')}"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _channel_link(channel_id: str) -> str:
|
|
29
|
+
return _LINK_PREFIX + quote(channel_id, safe="")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _channel_id(link: str) -> str:
|
|
33
|
+
if not link.startswith(_LINK_PREFIX):
|
|
34
|
+
raise RuntimeError("LiveTG TV: invalid channel link")
|
|
35
|
+
return unquote(link[len(_LINK_PREFIX) :])
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _channel_image(image: str, layout: str = "card") -> str:
|
|
39
|
+
if not image:
|
|
40
|
+
return ""
|
|
41
|
+
if layout == "poster":
|
|
42
|
+
size = "&w=300&h=450&fit=contain"
|
|
43
|
+
elif layout == "backdrop":
|
|
44
|
+
size = "&w=1280&h=720&fit=contain"
|
|
45
|
+
else:
|
|
46
|
+
size = "&w=400&h=300&fit=contain"
|
|
47
|
+
return f"https://wsrv.nl/?url={quote(image, safe='')}{size}&bg=grey&cbg=grey"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _set_header(headers: dict[str, str], name: str, value: str) -> None:
|
|
51
|
+
aliases = {
|
|
52
|
+
"cookie": "Cookie",
|
|
53
|
+
"origin": "Origin",
|
|
54
|
+
"referer": "Referer",
|
|
55
|
+
"referrer": "Referer",
|
|
56
|
+
"user-agent": "User-Agent",
|
|
57
|
+
}
|
|
58
|
+
key = aliases.get(name.lower(), name)
|
|
59
|
+
if not key or re.search(r"[\r\n]", key + value):
|
|
60
|
+
return
|
|
61
|
+
for existing in [k for k in headers if k.lower() == key.lower()]:
|
|
62
|
+
headers.pop(existing, None)
|
|
63
|
+
headers[key] = value
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _normalize_image(image: Any) -> str:
|
|
67
|
+
if not isinstance(image, str):
|
|
68
|
+
return ""
|
|
69
|
+
trimmed = image.strip()
|
|
70
|
+
if not trimmed:
|
|
71
|
+
return ""
|
|
72
|
+
if re.match(r"^https?://", trimmed, re.I):
|
|
73
|
+
return trimmed
|
|
74
|
+
return _WEBSITE + trimmed if trimmed.startswith("/") else ""
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _build_source_url(raw_url: str, headers: dict[str, str]) -> str:
|
|
78
|
+
pipe = raw_url.find("|")
|
|
79
|
+
url = raw_url if pipe < 0 else raw_url[:pipe]
|
|
80
|
+
if pipe >= 0:
|
|
81
|
+
for key, value in parse_qsl(raw_url[pipe + 1 :], keep_blank_values=True):
|
|
82
|
+
_set_header(headers, key, value)
|
|
83
|
+
|
|
84
|
+
signed = re.match(r"^https?://([^/?#]+)[^?#]*\?([^#]*)", url, re.I)
|
|
85
|
+
if signed and re.search(r"(?:^|\.)cdn\.jio\.com$", signed.group(1), re.I):
|
|
86
|
+
params = dict(parse_qsl(signed.group(2), keep_blank_values=True))
|
|
87
|
+
token = params.get("__hdnea__")
|
|
88
|
+
if token:
|
|
89
|
+
cookie_key = next((k for k in headers if k.lower() == "cookie"), None)
|
|
90
|
+
cookies = headers[cookie_key] if cookie_key else ""
|
|
91
|
+
if not re.search(r"(?:^|;\s*)__hdnea__=", cookies):
|
|
92
|
+
_set_header(
|
|
93
|
+
headers,
|
|
94
|
+
"Cookie",
|
|
95
|
+
f"{cookies}; __hdnea__={token}" if cookies else f"__hdnea__={token}",
|
|
96
|
+
)
|
|
97
|
+
return url
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _apply_drm_properties(drm: Any, properties: dict[str, str]) -> None:
|
|
101
|
+
if drm is None:
|
|
102
|
+
return
|
|
103
|
+
if not isinstance(drm, dict):
|
|
104
|
+
properties["inputstream.adaptive.license_type"] = "invalid"
|
|
105
|
+
return
|
|
106
|
+
kind = drm.get("type").strip() if isinstance(drm.get("type"), str) else ""
|
|
107
|
+
properties["inputstream.adaptive.license_type"] = kind or "invalid"
|
|
108
|
+
clear_keys = drm.get("clearKeys")
|
|
109
|
+
if isinstance(clear_keys, dict):
|
|
110
|
+
properties["inputstream.adaptive.license_key"] = ",".join(
|
|
111
|
+
f"{k}:{v}" for k, v in clear_keys.items()
|
|
112
|
+
)
|
|
113
|
+
elif drm.get("keyId") is not None or drm.get("key") is not None:
|
|
114
|
+
properties["inputstream.adaptive.license_key"] = (
|
|
115
|
+
f"{drm.get('keyId') or ''}:{drm.get('key') or ''}"
|
|
116
|
+
)
|
|
117
|
+
else:
|
|
118
|
+
properties["inputstream.adaptive.license_key"] = ""
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
def _parse_channels_api(payload: Any) -> list[dict[str, Any]]:
|
|
122
|
+
if not isinstance(payload, dict) or not isinstance(payload.get("channels"), list):
|
|
123
|
+
raise RuntimeError("LiveTG TV: invalid channels response")
|
|
124
|
+
channels_map: dict[str, dict[str, Any]] = {}
|
|
125
|
+
for item in payload["channels"]:
|
|
126
|
+
if not isinstance(item, dict):
|
|
127
|
+
continue
|
|
128
|
+
raw_id = str(item["id"]).strip() if isinstance(item.get("id"), (str, int)) else ""
|
|
129
|
+
title = item["name"].strip() if isinstance(item.get("name"), str) else ""
|
|
130
|
+
if not raw_id or not title:
|
|
131
|
+
continue
|
|
132
|
+
group = (
|
|
133
|
+
item["category"].strip()
|
|
134
|
+
if isinstance(item.get("category"), str) and item["category"].strip()
|
|
135
|
+
else "Other"
|
|
136
|
+
)
|
|
137
|
+
image = _normalize_image(item.get("logo"))
|
|
138
|
+
cid = f"{raw_id}:{re.sub(r'\s+', ' ', title.lower()).strip()}"
|
|
139
|
+
existing = channels_map.get(cid)
|
|
140
|
+
if existing:
|
|
141
|
+
if group not in existing["groups"]:
|
|
142
|
+
existing["groups"].append(group)
|
|
143
|
+
if not existing["image"] and image:
|
|
144
|
+
existing["image"] = image
|
|
145
|
+
else:
|
|
146
|
+
channels_map[cid] = {
|
|
147
|
+
"id": cid,
|
|
148
|
+
"title": title,
|
|
149
|
+
"image": image,
|
|
150
|
+
"groups": [group],
|
|
151
|
+
}
|
|
152
|
+
if not channels_map:
|
|
153
|
+
raise RuntimeError("LiveTG TV: channels response contains no channels")
|
|
154
|
+
return list(channels_map.values())
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def _parse_channel_detail(channel_id: str, payload: Any) -> list[dict[str, Any]]:
|
|
158
|
+
if not isinstance(payload, dict) or not isinstance(payload.get("sources"), list):
|
|
159
|
+
raise RuntimeError("LiveTG TV: invalid channel detail response")
|
|
160
|
+
colon = channel_id.find(":")
|
|
161
|
+
fallback_title = channel_id[colon + 1 :] if colon >= 0 else channel_id
|
|
162
|
+
title = (
|
|
163
|
+
payload["name"].strip()
|
|
164
|
+
if isinstance(payload.get("name"), str) and payload["name"].strip()
|
|
165
|
+
else fallback_title
|
|
166
|
+
)
|
|
167
|
+
group = (
|
|
168
|
+
payload["category"].strip()
|
|
169
|
+
if isinstance(payload.get("category"), str) and payload["category"].strip()
|
|
170
|
+
else "Live TV"
|
|
171
|
+
)
|
|
172
|
+
image = _normalize_image(payload.get("logo"))
|
|
173
|
+
channel = {"id": channel_id, "title": title, "image": image, "groups": [group]}
|
|
174
|
+
|
|
175
|
+
base_headers: dict[str, str] = {}
|
|
176
|
+
if isinstance(payload.get("headers"), dict):
|
|
177
|
+
for k, v in payload["headers"].items():
|
|
178
|
+
if isinstance(v, str):
|
|
179
|
+
_set_header(base_headers, k, v)
|
|
180
|
+
|
|
181
|
+
base_props: dict[str, str] = {}
|
|
182
|
+
_apply_drm_properties(payload.get("drm"), base_props)
|
|
183
|
+
|
|
184
|
+
sources: list[dict[str, Any]] = []
|
|
185
|
+
for item in payload["sources"]:
|
|
186
|
+
raw_url = ""
|
|
187
|
+
headers = dict(base_headers)
|
|
188
|
+
props = dict(base_props)
|
|
189
|
+
if isinstance(item, str):
|
|
190
|
+
raw_url = item.strip()
|
|
191
|
+
elif isinstance(item, dict):
|
|
192
|
+
if isinstance(item.get("url"), str):
|
|
193
|
+
raw_url = item["url"].strip()
|
|
194
|
+
if isinstance(item.get("headers"), dict):
|
|
195
|
+
for k, v in item["headers"].items():
|
|
196
|
+
if isinstance(v, str):
|
|
197
|
+
_set_header(headers, k, v)
|
|
198
|
+
if "drm" in item:
|
|
199
|
+
props.pop("inputstream.adaptive.license_type", None)
|
|
200
|
+
props.pop("inputstream.adaptive.license_key", None)
|
|
201
|
+
_apply_drm_properties(item.get("drm"), props)
|
|
202
|
+
if not re.match(r"^https?://", raw_url, re.I):
|
|
203
|
+
continue
|
|
204
|
+
sources.append(
|
|
205
|
+
{
|
|
206
|
+
"channel": channel,
|
|
207
|
+
"group": group,
|
|
208
|
+
"url": _build_source_url(raw_url, headers),
|
|
209
|
+
"headers": headers,
|
|
210
|
+
"properties": props,
|
|
211
|
+
}
|
|
212
|
+
)
|
|
213
|
+
return sources
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def _parse_playlist(text: str) -> list[dict[str, Any]]:
|
|
217
|
+
cleaned = text.lstrip("\ufeff").lstrip()
|
|
218
|
+
if not cleaned.startswith("#EXTM3U"):
|
|
219
|
+
raise RuntimeError("LiveTG TV: invalid playlist response")
|
|
220
|
+
sources: list[dict[str, Any]] = []
|
|
221
|
+
entry: dict[str, Any] | None = None
|
|
222
|
+
|
|
223
|
+
for raw in re.split(r"\r?\n", text):
|
|
224
|
+
line = raw.strip()
|
|
225
|
+
if line.startswith("#EXTINF:"):
|
|
226
|
+
attrs = dict(re.findall(r'([\w-]+)="([^"]*)"', line))
|
|
227
|
+
quoted = False
|
|
228
|
+
comma = -1
|
|
229
|
+
for i, ch in enumerate(line):
|
|
230
|
+
if ch == '"':
|
|
231
|
+
quoted = not quoted
|
|
232
|
+
if ch == "," and not quoted:
|
|
233
|
+
comma = i
|
|
234
|
+
break
|
|
235
|
+
title = (line[comma + 1 :].strip() if comma >= 0 else "") or attrs.get("tvg-name", "")
|
|
236
|
+
if not title:
|
|
237
|
+
entry = None
|
|
238
|
+
continue
|
|
239
|
+
group = attrs.get("group-title") or "Other"
|
|
240
|
+
cid = f"{attrs.get('tvg-id', '')}:{re.sub(r'\s+', ' ', title.lower()).strip()}"
|
|
241
|
+
entry = {
|
|
242
|
+
"channel": {
|
|
243
|
+
"id": cid,
|
|
244
|
+
"title": title,
|
|
245
|
+
"image": attrs.get("tvg-logo") or "",
|
|
246
|
+
"groups": [group],
|
|
247
|
+
},
|
|
248
|
+
"group": group,
|
|
249
|
+
"url": "",
|
|
250
|
+
"headers": {},
|
|
251
|
+
"properties": {},
|
|
252
|
+
}
|
|
253
|
+
elif entry and line.startswith("#KODIPROP:"):
|
|
254
|
+
val = line[10:]
|
|
255
|
+
eq = val.find("=")
|
|
256
|
+
if eq >= 0:
|
|
257
|
+
entry["properties"][val[:eq]] = val[eq + 1 :]
|
|
258
|
+
elif entry and line.startswith("#EXTHTTP:"):
|
|
259
|
+
try:
|
|
260
|
+
values = json.loads(line[9:])
|
|
261
|
+
if isinstance(values, dict):
|
|
262
|
+
for k, v in values.items():
|
|
263
|
+
if isinstance(v, str):
|
|
264
|
+
_set_header(entry["headers"], k, v)
|
|
265
|
+
except Exception:
|
|
266
|
+
pass
|
|
267
|
+
elif entry and line.startswith("#EXTVLCOPT:"):
|
|
268
|
+
val = line[11:]
|
|
269
|
+
eq = val.find("=")
|
|
270
|
+
if eq >= 0:
|
|
271
|
+
key, content = val[:eq], val[eq + 1 :]
|
|
272
|
+
if key == "http-extra-headers":
|
|
273
|
+
for item in re.split(r"\\r\\n|\\n", content):
|
|
274
|
+
colon = item.find(":")
|
|
275
|
+
if colon > 0:
|
|
276
|
+
_set_header(
|
|
277
|
+
entry["headers"],
|
|
278
|
+
item[:colon].strip(),
|
|
279
|
+
item[colon + 1 :].strip(),
|
|
280
|
+
)
|
|
281
|
+
elif key in ("http-user-agent", "http-referrer", "http-cookie"):
|
|
282
|
+
_set_header(entry["headers"], key[5:], content)
|
|
283
|
+
elif entry and re.match(r"^https?://", line, re.I):
|
|
284
|
+
entry["url"] = _build_source_url(line, entry["headers"])
|
|
285
|
+
sources.append(entry)
|
|
286
|
+
entry = None
|
|
287
|
+
|
|
288
|
+
if not sources:
|
|
289
|
+
raise RuntimeError("LiveTG TV: playlist contains no channels")
|
|
290
|
+
return sources
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
def _source_drm(source: dict[str, Any]) -> dict[str, Any] | None:
|
|
294
|
+
props = source.get("properties") or {}
|
|
295
|
+
kind = props.get("inputstream.adaptive.license_type")
|
|
296
|
+
license_val = props.get("inputstream.adaptive.license_key")
|
|
297
|
+
if not kind and not license_val:
|
|
298
|
+
return None
|
|
299
|
+
if (kind or "").lower() not in ("clearkey", "org.w3.clearkey"):
|
|
300
|
+
raise RuntimeError("LiveTG TV: unsupported DRM")
|
|
301
|
+
clear_keys: dict[str, str] = {}
|
|
302
|
+
for pair in (license_val or "").split(","):
|
|
303
|
+
m = re.fullmatch(r"([a-f\d]{32}):([a-f\d]{32})", pair.strip(), re.I)
|
|
304
|
+
if not m:
|
|
305
|
+
raise RuntimeError("LiveTG TV: invalid ClearKey configuration")
|
|
306
|
+
clear_keys[m.group(1).lower()] = m.group(2).lower()
|
|
307
|
+
return {"type": "clearkey", "clearKeys": clear_keys}
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
class LiveTgTvClient(BaseProvider):
|
|
311
|
+
"""Client for the LiveTG TV provider."""
|
|
312
|
+
|
|
313
|
+
name: str = "liveTgTv"
|
|
314
|
+
catalog: list[dict[str, str]] = [{"title": "All Channels", "filter": "all"}]
|
|
315
|
+
genres: list[dict[str, str]] = []
|
|
316
|
+
|
|
317
|
+
def _request_text(self, url: str) -> str:
|
|
318
|
+
sep = "&" if "?" in url else "?"
|
|
319
|
+
target = f"{url}{sep}_vega_refresh={int(time.time() * 1000)}"
|
|
320
|
+
return self.fetch_text(
|
|
321
|
+
target,
|
|
322
|
+
headers={**COMMON_HEADERS, "Cache-Control": "no-cache", "Pragma": "no-cache"},
|
|
323
|
+
timeout=30,
|
|
324
|
+
)
|
|
325
|
+
|
|
326
|
+
def _request_json(self, url: str) -> Any:
|
|
327
|
+
return json.loads(self._request_text(url))
|
|
328
|
+
|
|
329
|
+
def _load_sources(self) -> list[dict[str, Any]]:
|
|
330
|
+
return _parse_playlist(self._request_text(_PLAYLIST_URL))
|
|
331
|
+
|
|
332
|
+
def _channels(self) -> list[dict[str, Any]]:
|
|
333
|
+
now = int(time.time() * 1000)
|
|
334
|
+
cached = self.kv.get(_CACHE_KEY)
|
|
335
|
+
if (
|
|
336
|
+
isinstance(cached, dict)
|
|
337
|
+
and isinstance(cached.get("channels"), list)
|
|
338
|
+
and now - (cached.get("time") or 0) < _CACHE_TTL_MS
|
|
339
|
+
):
|
|
340
|
+
return cached["channels"]
|
|
341
|
+
|
|
342
|
+
try:
|
|
343
|
+
result = _parse_channels_api(self._request_json(_CHANNELS_URL))
|
|
344
|
+
except Exception as api_err:
|
|
345
|
+
try:
|
|
346
|
+
ch_map: dict[str, dict[str, Any]] = {}
|
|
347
|
+
for source in self._load_sources():
|
|
348
|
+
ch = source["channel"]
|
|
349
|
+
existing = ch_map.get(ch["id"])
|
|
350
|
+
if existing:
|
|
351
|
+
if source["group"] not in existing["groups"]:
|
|
352
|
+
existing["groups"].append(source["group"])
|
|
353
|
+
if not existing["image"]:
|
|
354
|
+
existing["image"] = ch["image"]
|
|
355
|
+
else:
|
|
356
|
+
ch_map[ch["id"]] = {
|
|
357
|
+
**ch,
|
|
358
|
+
"groups": list(ch["groups"]),
|
|
359
|
+
}
|
|
360
|
+
result = list(ch_map.values())
|
|
361
|
+
except Exception:
|
|
362
|
+
raise api_err
|
|
363
|
+
|
|
364
|
+
self.kv.set(_CACHE_KEY, {"time": now, "channels": result})
|
|
365
|
+
return result
|
|
366
|
+
|
|
367
|
+
def _load_channel_sources(self, cid: str) -> list[dict[str, Any]]:
|
|
368
|
+
colon = cid.find(":")
|
|
369
|
+
api_id = (cid[:colon] if colon >= 0 else cid).strip()
|
|
370
|
+
detail_error: Exception | None = None
|
|
371
|
+
missing_from_detail = False
|
|
372
|
+
|
|
373
|
+
if api_id:
|
|
374
|
+
try:
|
|
375
|
+
sources = _parse_channel_detail(
|
|
376
|
+
cid, self._request_json(_channel_detail_url(api_id))
|
|
377
|
+
)
|
|
378
|
+
if sources:
|
|
379
|
+
return sources
|
|
380
|
+
missing_from_detail = True
|
|
381
|
+
except requests.HTTPError as err:
|
|
382
|
+
if err.response is not None and err.response.status_code == 404:
|
|
383
|
+
missing_from_detail = True
|
|
384
|
+
detail_error = err
|
|
385
|
+
except Exception as err:
|
|
386
|
+
detail_error = err
|
|
387
|
+
|
|
388
|
+
try:
|
|
389
|
+
matched = [s for s in self._load_sources() if s["channel"]["id"] == cid]
|
|
390
|
+
if matched:
|
|
391
|
+
return matched
|
|
392
|
+
raise RuntimeError("LiveTG TV: channel is no longer available")
|
|
393
|
+
except Exception as err:
|
|
394
|
+
if missing_from_detail:
|
|
395
|
+
raise RuntimeError("LiveTG TV: channel is no longer available") from err
|
|
396
|
+
if detail_error is not None:
|
|
397
|
+
raise detail_error from err
|
|
398
|
+
raise
|
|
399
|
+
|
|
400
|
+
def get_catalog(self) -> dict[str, list[dict[str, str]]]:
|
|
401
|
+
all_items = [{"title": "All Channels", "filter": "all"}]
|
|
402
|
+
groups: set[str] = set()
|
|
403
|
+
for ch in self._channels():
|
|
404
|
+
groups.update(ch["groups"])
|
|
405
|
+
dynamic = [
|
|
406
|
+
{"title": g, "filter": "group:" + quote(g, safe="")}
|
|
407
|
+
for g in sorted(groups)
|
|
408
|
+
]
|
|
409
|
+
return {"catalog": all_items + dynamic, "genres": []}
|
|
410
|
+
|
|
411
|
+
def _list_channels(
|
|
412
|
+
self, filter_path: str = "", query: str = "", page: int = 1
|
|
413
|
+
) -> list[dict[str, Any]]:
|
|
414
|
+
group = unquote(filter_path[6:]) if filter_path.startswith("group:") else None
|
|
415
|
+
q = query.strip().lower()
|
|
416
|
+
items = [
|
|
417
|
+
item
|
|
418
|
+
for item in self._channels()
|
|
419
|
+
if (not group or group in item["groups"])
|
|
420
|
+
and (not q or q in item["title"].lower())
|
|
421
|
+
]
|
|
422
|
+
offset = (max(1, page) - 1) * _PAGE_SIZE
|
|
423
|
+
return [
|
|
424
|
+
{
|
|
425
|
+
"title": item["title"],
|
|
426
|
+
"image": _channel_image(item["image"]),
|
|
427
|
+
"link": _channel_link(item["id"]),
|
|
428
|
+
"tag": "LIVE",
|
|
429
|
+
"aspectRatio": 4 / 3,
|
|
430
|
+
}
|
|
431
|
+
for item in items[offset : offset + _PAGE_SIZE]
|
|
432
|
+
]
|
|
433
|
+
|
|
434
|
+
def get_posts(self, filter_path: str = "", page: int = 1) -> list[dict[str, Any]]:
|
|
435
|
+
try:
|
|
436
|
+
return self._list_channels(filter_path=filter_path, page=page)
|
|
437
|
+
except Exception as exc:
|
|
438
|
+
throw_provider_error("LiveTG TV", "getPosts", exc)
|
|
439
|
+
|
|
440
|
+
def get_search_posts(self, query: str, page: int = 1) -> list[dict[str, Any]]:
|
|
441
|
+
try:
|
|
442
|
+
return self._list_channels(query=query, page=page)
|
|
443
|
+
except Exception as exc:
|
|
444
|
+
throw_provider_error("LiveTG TV", "getSearchPosts", exc)
|
|
445
|
+
|
|
446
|
+
def get_meta(self, link: str) -> dict[str, Any]:
|
|
447
|
+
try:
|
|
448
|
+
cid = _channel_id(link)
|
|
449
|
+
channel = next((c for c in self._channels() if c["id"] == cid), None)
|
|
450
|
+
if not channel:
|
|
451
|
+
raise RuntimeError("LiveTG TV: channel is no longer available")
|
|
452
|
+
return {
|
|
453
|
+
"title": channel["title"],
|
|
454
|
+
"image": _channel_image(channel["image"], "backdrop"),
|
|
455
|
+
"poster": _channel_image(channel["image"], "poster"),
|
|
456
|
+
"synopsis": f"Watch {channel['title']} live.",
|
|
457
|
+
"imdbId": "",
|
|
458
|
+
"type": "movie",
|
|
459
|
+
"quickDownload": False,
|
|
460
|
+
"tags": ["Live TV", *channel["groups"]],
|
|
461
|
+
"webUrl": _WEBSITE,
|
|
462
|
+
"linkList": [
|
|
463
|
+
{
|
|
464
|
+
"title": "Live TV",
|
|
465
|
+
"quickDownload": False,
|
|
466
|
+
"directLinks": [
|
|
467
|
+
{
|
|
468
|
+
"title": "Watch Live",
|
|
469
|
+
"link": link,
|
|
470
|
+
"type": "movie",
|
|
471
|
+
"quickDownload": False,
|
|
472
|
+
}
|
|
473
|
+
],
|
|
474
|
+
}
|
|
475
|
+
],
|
|
476
|
+
}
|
|
477
|
+
except Exception as exc:
|
|
478
|
+
throw_provider_error("LiveTG TV", "getMeta", exc)
|
|
479
|
+
|
|
480
|
+
def get_stream(
|
|
481
|
+
self,
|
|
482
|
+
url: str,
|
|
483
|
+
is_download: bool = False,
|
|
484
|
+
media_type: str = "movie",
|
|
485
|
+
) -> list[dict[str, Any]]:
|
|
486
|
+
try:
|
|
487
|
+
cid = _channel_id(url)
|
|
488
|
+
sources = self._load_channel_sources(cid)
|
|
489
|
+
if not sources:
|
|
490
|
+
raise RuntimeError("LiveTG TV: channel is no longer available")
|
|
491
|
+
|
|
492
|
+
streams: list[dict[str, Any]] = []
|
|
493
|
+
seen: set[str] = set()
|
|
494
|
+
invalid = False
|
|
495
|
+
|
|
496
|
+
for source in sources:
|
|
497
|
+
try:
|
|
498
|
+
drm = _source_drm(source)
|
|
499
|
+
if is_download and drm:
|
|
500
|
+
continue
|
|
501
|
+
hint = source["properties"].get("inputstream.adaptive.manifest_type", "")
|
|
502
|
+
s_url = source["url"]
|
|
503
|
+
if hint == "mpd" or re.search(r"\.mpd(?:[?/#]|$)", s_url, re.I):
|
|
504
|
+
s_type = "mpd"
|
|
505
|
+
elif hint == "hls" or re.search(r"\.m3u8(?:[?/#]|$)", s_url, re.I):
|
|
506
|
+
s_type = "m3u8"
|
|
507
|
+
elif re.search(r"\.mp4(?:[?/#]|$)", s_url, re.I):
|
|
508
|
+
s_type = "mp4"
|
|
509
|
+
elif drm:
|
|
510
|
+
s_type = "mpd"
|
|
511
|
+
else:
|
|
512
|
+
s_type = "m3u8"
|
|
513
|
+
|
|
514
|
+
fingerprint = json.dumps(
|
|
515
|
+
[s_url, sorted(source["headers"].items()), drm],
|
|
516
|
+
sort_keys=True,
|
|
517
|
+
)
|
|
518
|
+
if fingerprint in seen:
|
|
519
|
+
continue
|
|
520
|
+
seen.add(fingerprint)
|
|
521
|
+
|
|
522
|
+
entry: dict[str, Any] = {
|
|
523
|
+
"server": f"{source['group']} • {s_type.upper()}",
|
|
524
|
+
"link": s_url,
|
|
525
|
+
"type": s_type,
|
|
526
|
+
"headers": source["headers"],
|
|
527
|
+
}
|
|
528
|
+
if drm:
|
|
529
|
+
entry["drm"] = drm
|
|
530
|
+
streams.append(entry)
|
|
531
|
+
except Exception:
|
|
532
|
+
invalid = True
|
|
533
|
+
|
|
534
|
+
if not streams and invalid:
|
|
535
|
+
raise RuntimeError("LiveTG TV: no source has a supported DRM configuration")
|
|
536
|
+
|
|
537
|
+
target_type = "mp4" if is_download else "m3u8"
|
|
538
|
+
return sorted(streams, key=lambda s: 0 if s["type"] == target_type else 1)
|
|
539
|
+
except Exception as exc:
|
|
540
|
+
throw_provider_error("LiveTG TV", "getStream", exc)
|