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.
Files changed (84) hide show
  1. vega_cli/__init__.py +1 -0
  2. vega_cli/__main__.py +6 -0
  3. vega_cli/cli.py +247 -0
  4. vega_cli/config.py +99 -0
  5. vega_cli/display.py +138 -0
  6. vega_cli/html.py +540 -0
  7. vega_cli/interactive.py +220 -0
  8. vega_cli/player.py +82 -0
  9. vega_cli/providers/__init__.py +13 -0
  10. vega_cli/providers/ani_dream.py +1089 -0
  11. vega_cli/providers/anikoto.py +820 -0
  12. vega_cli/providers/animesalt.py +649 -0
  13. vega_cli/providers/animesub.py +1374 -0
  14. vega_cli/providers/animeworld.py +504 -0
  15. vega_cli/providers/auto_embed.py +479 -0
  16. vega_cli/providers/castle.py +497 -0
  17. vega_cli/providers/cncverse.py +873 -0
  18. vega_cli/providers/common/__init__.py +51 -0
  19. vega_cli/providers/common/aes.py +152 -0
  20. vega_cli/providers/common/aniskip.py +186 -0
  21. vega_cli/providers/common/base_url.py +102 -0
  22. vega_cli/providers/common/cinemeta.py +231 -0
  23. vega_cli/providers/common/errors.py +25 -0
  24. vega_cli/providers/common/extractors/__init__.py +23 -0
  25. vega_cli/providers/common/extractors/abbasy.py +247 -0
  26. vega_cli/providers/common/extractors/buzzheavier.py +72 -0
  27. vega_cli/providers/common/extractors/cinejoy.py +33 -0
  28. vega_cli/providers/common/extractors/gdflix.py +170 -0
  29. vega_cli/providers/common/extractors/gofile.py +167 -0
  30. vega_cli/providers/common/extractors/hubcloud.py +277 -0
  31. vega_cli/providers/common/extractors/movy.py +349 -0
  32. vega_cli/providers/common/extractors/st111477.py +139 -0
  33. vega_cli/providers/common/extractors/transferit.py +53 -0
  34. vega_cli/providers/common/extractors/vegadrive.py +161 -0
  35. vega_cli/providers/common/extractors/vidstuck.py +379 -0
  36. vega_cli/providers/common/extractors/zcloud.py +158 -0
  37. vega_cli/providers/common/extractors/zypter.py +72 -0
  38. vega_cli/providers/common/headers.py +25 -0
  39. vega_cli/providers/common/http.py +121 -0
  40. vega_cli/providers/common/net_mirror.py +1494 -0
  41. vega_cli/providers/common/theintrodb.py +112 -0
  42. vega_cli/providers/common/unpack.py +54 -0
  43. vega_cli/providers/disney_mirror.py +31 -0
  44. vega_cli/providers/dramacool.py +297 -0
  45. vega_cli/providers/drive.py +695 -0
  46. vega_cli/providers/durbin_live.py +354 -0
  47. vega_cli/providers/eon_movies.py +752 -0
  48. vega_cli/providers/extraflix.py +701 -0
  49. vega_cli/providers/four_khdhub.py +307 -0
  50. vega_cli/providers/goku_hd.py +336 -0
  51. vega_cli/providers/hdhub4u.py +665 -0
  52. vega_cli/providers/internet_archive.py +552 -0
  53. vega_cli/providers/kartoons.py +642 -0
  54. vega_cli/providers/kartoons2.py +395 -0
  55. vega_cli/providers/katmovies.py +816 -0
  56. vega_cli/providers/kick_ass_anime.py +445 -0
  57. vega_cli/providers/kiss_kh.py +490 -0
  58. vega_cli/providers/live_tg_tv.py +540 -0
  59. vega_cli/providers/lux_movies.py +650 -0
  60. vega_cli/providers/mod.py +676 -0
  61. vega_cli/providers/movie_box_web.py +921 -0
  62. vega_cli/providers/movielinkdb.py +734 -0
  63. vega_cli/providers/movies4u.py +580 -0
  64. vega_cli/providers/moviezwap.py +199 -0
  65. vega_cli/providers/mxplayer.py +470 -0
  66. vega_cli/providers/netflix_mirror.py +32 -0
  67. vega_cli/providers/one_cinevood.py +596 -0
  68. vega_cli/providers/prime_mirror.py +31 -0
  69. vega_cli/providers/rareanimes.py +676 -0
  70. vega_cli/providers/registry.py +124 -0
  71. vega_cli/providers/showbox.py +245 -0
  72. vega_cli/providers/topmovies.py +707 -0
  73. vega_cli/providers/torrentio.py +398 -0
  74. vega_cli/providers/uhd.py +483 -0
  75. vega_cli/providers/vega.py +891 -0
  76. vega_cli/providers/youtube.py +566 -0
  77. vega_cli/providers/zeefliz.py +563 -0
  78. vega_cli/store.py +45 -0
  79. vega_cli/utils.py +90 -0
  80. vega_cli-0.1.0.dist-info/METADATA +8 -0
  81. vega_cli-0.1.0.dist-info/RECORD +84 -0
  82. vega_cli-0.1.0.dist-info/WHEEL +5 -0
  83. vega_cli-0.1.0.dist-info/entry_points.txt +2 -0
  84. vega_cli-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,676 @@
1
+ """Pure-Python Vega RareAnimes provider."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import re
6
+ import time
7
+ from concurrent.futures import ThreadPoolExecutor
8
+ from typing import Any
9
+ from urllib.parse import quote, urljoin, urlparse, urlunparse
10
+
11
+ from ..html import Node, parse_html
12
+ from .common import (
13
+ BaseProvider,
14
+ apply_cinemeta_meta,
15
+ enrich_cinemeta_episodes,
16
+ get_base_url,
17
+ get_cinemeta_meta,
18
+ read_cinemeta_context,
19
+ throw_provider_error,
20
+ )
21
+ from .common.extractors import hubcloud_extractor
22
+
23
+ _POSTS_HEADERS = {
24
+ "Referer": "https://www.google.com",
25
+ "User-Agent": (
26
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
27
+ "(KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36"
28
+ ),
29
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
30
+ "Accept-Language": "en-US,en;q=0.9",
31
+ "Pragma": "no-cache",
32
+ "Cache-Control": "no-cache",
33
+ }
34
+
35
+ _META_HEADERS = {
36
+ "Accept": (
37
+ "text/html,application/xhtml+xml,application/xml;q=0.9,"
38
+ "image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"
39
+ ),
40
+ "Cache-Control": "no-store",
41
+ "Accept-Language": "en-US,en;q=0.9",
42
+ "DNT": "1",
43
+ "sec-ch-ua": '"Not_A Brand";v="8", "Chromium";v="120", "Microsoft Edge";v="120"',
44
+ "sec-ch-ua-mobile": "?0",
45
+ "sec-ch-ua-platform": '"Windows"',
46
+ "Sec-Fetch-Dest": "document",
47
+ "Sec-Fetch-Mode": "navigate",
48
+ "Sec-Fetch-Site": "none",
49
+ "Sec-Fetch-User": "?1",
50
+ "Upgrade-Insecure-Requests": "1",
51
+ "User-Agent": (
52
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
53
+ "(KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0"
54
+ ),
55
+ }
56
+
57
+ _STREAM_HEADERS = {
58
+ **_META_HEADERS,
59
+ "User-Agent": (
60
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
61
+ "(KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36 Edg/142.0.0.0"
62
+ ),
63
+ }
64
+
65
+ _CATEGORY_TAG_MAP = {
66
+ "category-hindi-dub": "HINDI DUB",
67
+ "category-tamil": "TAMIL",
68
+ "category-telugu": "TELUGU",
69
+ "category-animes": "ANIME",
70
+ "category-anime": "ANIME",
71
+ "category-movies": "MOVIE",
72
+ "category-movie": "MOVIE",
73
+ "category-crunchyroll": "CRUNCHYROLL",
74
+ "category-amazon-prime-original": "PRIME",
75
+ "category-completed": "COMPLETED",
76
+ "category-ongoing": "ONGOING",
77
+ }
78
+
79
+ _POST_SELECTORS = ", ".join(
80
+ [
81
+ "article.herald-post",
82
+ ".herald-posts article.herald-post",
83
+ "article.herald-lay-b.herald-post",
84
+ "article.herald-lay-b",
85
+ ".herald-posts article.herald-lay-b",
86
+ "li.post",
87
+ ".swiper-slide li",
88
+ ".latest-movies-series-swiper-slide li",
89
+ "ul.post-lst li",
90
+ ]
91
+ )
92
+
93
+ _PREFERRED_LANG_ORDER = [
94
+ "Hindi DUB",
95
+ "Hindi",
96
+ "Tamil",
97
+ "Telugu",
98
+ "English",
99
+ "Japanese",
100
+ "Korean",
101
+ "Malayalam",
102
+ "Kannada",
103
+ "Bengali",
104
+ "Marathi",
105
+ "Punjabi",
106
+ "Urdu",
107
+ "Multi-Audio",
108
+ "Multi Audio",
109
+ "MultiAudio",
110
+ ]
111
+
112
+ _SERVER_DEFS: list[tuple[re.Pattern[str], str, int]] = [
113
+ (re.compile(r"^hubcloud$", re.I), "HubCloud", 1),
114
+ (re.compile(r"hubcloud", re.I), "HubCloud", 1),
115
+ (re.compile(r"^watch\s*multi\s*quality$", re.I), "Watch Multi Quality", 2),
116
+ (re.compile(r"watch\s*multi\s*quality", re.I), "Watch Multi Quality", 2),
117
+ (re.compile(r"^watchmulti(quality)?$", re.I), "Watch Multi Quality", 2),
118
+ (re.compile(r"watchmulti(quality)?", re.I), "Watch Multi Quality", 2),
119
+ (re.compile(r"^watch\s*now$", re.I), "Watch Now", 3),
120
+ (re.compile(r"watch\s*now", re.I), "Watch Now", 3),
121
+ (re.compile(r"^dl\s*beta$", re.I), "DL Beta", 4),
122
+ (re.compile(r"dl\s*beta", re.I), "DL Beta", 4),
123
+ (re.compile(r"^mega$", re.I), "Mega", 5),
124
+ (re.compile(r"mega", re.I), "Mega", 5),
125
+ (re.compile(r"^gdrive$|^google\s*drive$", re.I), "GDrive", 6),
126
+ (re.compile(r"gdrive|google\s*drive", re.I), "GDrive", 6),
127
+ (re.compile(r"^gdflix$", re.I), "GDFlix", 7),
128
+ (re.compile(r"gdflix", re.I), "GDFlix", 7),
129
+ ]
130
+
131
+
132
+ def _lang_order_index(lang: str) -> int:
133
+ lower = lang.lower()
134
+ for idx, item in enumerate(_PREFERRED_LANG_ORDER):
135
+ if item.lower() == lower:
136
+ return idx
137
+ return 10**9
138
+
139
+
140
+ def _normalize_lang(raw: str) -> str:
141
+ cleaned = re.sub(r"\s+", " ", raw).strip()
142
+ if re.fullmatch(r"hindi\s*dub", cleaned, re.I):
143
+ return "Hindi DUB"
144
+ for canonical in ("Hindi", "Tamil", "Telugu", "English", "Japanese", "Korean"):
145
+ if cleaned.lower() == canonical.lower():
146
+ return canonical
147
+ return cleaned
148
+
149
+
150
+ def _match_server(anchor_text: str) -> tuple[str, int] | None:
151
+ text = anchor_text.strip()
152
+ for pattern, name, order in _SERVER_DEFS:
153
+ if pattern.search(text):
154
+ return name, order
155
+ return None
156
+
157
+
158
+ def _pick_best_server_link(p: Node) -> tuple[str, str, int] | None:
159
+ candidates: list[tuple[str, str, int]] = []
160
+ for a in p.select("a"):
161
+ href = a.attr("href")
162
+ if not href or ("codedew.com/zipper" not in href and "hubcloud" not in href):
163
+ continue
164
+ matched = _match_server(a.text())
165
+ if matched:
166
+ candidates.append((matched[0], href, matched[1]))
167
+ if not candidates:
168
+ return None
169
+ candidates.sort(key=lambda c: c[2])
170
+ return candidates[0]
171
+
172
+
173
+ def _extract_imdb_id(doc: Node, html: str) -> str:
174
+ imdb_a = doc.select_one('a[href*="imdb.com/title/tt"]')
175
+ if imdb_a:
176
+ m = re.search(r"tt\d{7,}", imdb_a.attr("href"))
177
+ if m:
178
+ return m.group(0)
179
+ meta = doc.select_one('meta[property="og:see_also"], meta[name="imdb"]')
180
+ if meta:
181
+ m = re.search(r"tt\d{7,}", meta.attr("content"))
182
+ if m:
183
+ return m.group(0)
184
+ ld = doc.select_one('script[type="application/ld+json"]')
185
+ if ld:
186
+ m = re.search(r"tt\d{7,}", ld.text())
187
+ if m:
188
+ return m.group(0)
189
+ m = re.search(r"tt\d{7,}", html)
190
+ return m.group(0) if m else ""
191
+
192
+
193
+ def _is_zipper_url(url: str) -> bool:
194
+ try:
195
+ host = urlparse(url).hostname or ""
196
+ return "codedew.com" in host or "/zipper" in url or "ad_done" in url
197
+ except Exception:
198
+ return "zipper" in url or "ad_done" in url
199
+
200
+
201
+ def _extract_next_url(doc: Node, html: str, base_url: str) -> str | None:
202
+ data_el = doc.select_one("[data-href]")
203
+ if data_el:
204
+ data_href = data_el.attr("data-href").strip()
205
+ if data_href:
206
+ return data_href if data_href.startswith("http") else urljoin(base_url, data_href)
207
+
208
+ meta_m = re.search(
209
+ r"""<meta[^>]+http-equiv=["']?refresh["']?[^>]+content=["'][^"']*?url=([^"'&]+)""",
210
+ html,
211
+ re.I,
212
+ )
213
+ if meta_m:
214
+ target = meta_m.group(1)
215
+ return target if target.startswith("http") else urljoin(base_url, target)
216
+
217
+ anchor_m = re.search(
218
+ r"""<a[^>]+href=["']([^"']*(?:hubcloud|gamerxyt|drive)[^"']*)["']""",
219
+ html,
220
+ re.I,
221
+ )
222
+ if anchor_m:
223
+ target = anchor_m.group(1)
224
+ return target if target.startswith("http") else urljoin(base_url, target)
225
+
226
+ js_m = re.search(
227
+ r"""(?:window\.)?location(?:\.href)?\s*=\s*["']([^"']+)["']""",
228
+ html,
229
+ re.I,
230
+ )
231
+ if js_m:
232
+ target = js_m.group(1)
233
+ return target if target.startswith("http") else urljoin(base_url, target)
234
+
235
+ return None
236
+
237
+
238
+ class RareanimesClient(BaseProvider):
239
+ """Client for the RareAnimes provider."""
240
+
241
+ name: str = "rareanimes"
242
+ catalog: list[dict[str, str]] = [
243
+ {"title": "Trending", "filter": "home/"},
244
+ {"title": "Series", "filter": "?s=series"},
245
+ ]
246
+ genres: list[dict[str, str]] = []
247
+
248
+ def _fetch_posts(
249
+ self,
250
+ *,
251
+ filter_path: str = "",
252
+ query: str = "",
253
+ page: int = 1,
254
+ operation: str = "posts",
255
+ ) -> list[dict[str, Any]]:
256
+ try:
257
+ base_url = get_base_url("RareAnimes", kv=self.kv).rstrip("/")
258
+ if query.strip():
259
+ search = quote(query.strip())
260
+ url = (
261
+ f"{base_url}/page/{page}/?s={search}"
262
+ if page > 1
263
+ else f"{base_url}/?s={search}"
264
+ )
265
+ elif filter_path:
266
+ target = urljoin(f"{base_url}/", filter_path)
267
+ if page > 1:
268
+ parsed = urlparse(target)
269
+ new_path = f"{parsed.path.rstrip('/')}/page/{page}/"
270
+ target = urlunparse(parsed._replace(path=new_path))
271
+ url = target
272
+ else:
273
+ url = f"{base_url}/page/{page}/" if page > 1 else f"{base_url}/"
274
+
275
+ doc = self.fetch_html(url, headers=_POSTS_HEADERS)
276
+ seen: set[str] = set()
277
+ posts: list[dict[str, Any]] = []
278
+
279
+ for article in doc.select(_POST_SELECTORS):
280
+ link_el = (
281
+ article.select_one("h2.entry-title a[href]")
282
+ or article.select_one("a.herald-read-more[href]")
283
+ or article.select_one("a[href]")
284
+ )
285
+ href = link_el.attr("href") if link_el else ""
286
+ if not href:
287
+ continue
288
+ link = href if href.startswith("http") else urljoin(base_url, href)
289
+ if link in seen:
290
+ continue
291
+
292
+ h2 = article.select_one("h2.entry-title")
293
+ img_el = article.select_one("img")
294
+ more_el = article.select_one("a.herald-read-more")
295
+ raw_title = (
296
+ (h2.text().strip() if h2 else "")
297
+ or (img_el.attr("alt").strip() if img_el else "")
298
+ or (more_el.attr("title").strip() if more_el else "")
299
+ )
300
+ if not raw_title:
301
+ continue
302
+ title = re.sub(r"^Image\s+", "", raw_title, flags=re.I).strip()
303
+
304
+ img_src = ""
305
+ if img_el:
306
+ img_src = (
307
+ img_el.attr("data-src")
308
+ or img_el.attr("data-lazy-src")
309
+ or img_el.attr("src")
310
+ )
311
+ image = (
312
+ img_src
313
+ if img_src.startswith("http")
314
+ else (urljoin(base_url, img_src) if img_src else "")
315
+ )
316
+
317
+ classes = article.attr("class")
318
+ tag = next(
319
+ (val for cls, val in _CATEGORY_TAG_MAP.items() if cls in classes),
320
+ None,
321
+ )
322
+ corner_tag: str | None = None
323
+ season_m = re.search(r"Season\s*(\d+)", title, re.I)
324
+ if season_m:
325
+ corner_tag = f"S{season_m.group(1)}"
326
+ elif "sticky" in classes:
327
+ corner_tag = "NEW"
328
+
329
+ seen.add(link)
330
+ post: dict[str, Any] = {
331
+ "title": title,
332
+ "link": link,
333
+ "image": image,
334
+ "aspectRatio": 16 / 9,
335
+ "borderRadius": 8,
336
+ }
337
+ if tag:
338
+ post["tag"] = tag
339
+ if corner_tag:
340
+ post["cornerTag"] = corner_tag
341
+ posts.append(post)
342
+
343
+ return posts[:100]
344
+ except Exception as exc:
345
+ throw_provider_error("RareAnimes", operation, exc)
346
+
347
+ def get_posts(self, filter_path: str = "", page: int = 1) -> list[dict[str, Any]]:
348
+ return self._fetch_posts(filter_path=filter_path, page=page, operation="posts")
349
+
350
+ def get_search_posts(self, query: str, page: int = 1) -> list[dict[str, Any]]:
351
+ return self._fetch_posts(query=query, page=page, operation="search posts")
352
+
353
+ def get_meta(self, link: str) -> dict[str, Any]:
354
+ try:
355
+ current_base = get_base_url("RareAnimes", kv=self.kv).rstrip("/")
356
+ url = urljoin(f"{current_base}/", link)
357
+ base_url = "/".join(url.split("/")[:3])
358
+ html = self.fetch_text(url, headers={**_META_HEADERS, "Referer": base_url})
359
+ doc = parse_html(html)
360
+
361
+ h1 = doc.select_one("h1.entry-title")
362
+ og_title = doc.select_one("meta[property='og:title']")
363
+ title = (
364
+ (h1.text().strip() if h1 else "")
365
+ or (og_title.attr("content").strip() if og_title else "")
366
+ or "Unknown Title"
367
+ )
368
+
369
+ thumb = doc.select_one(".herald-post-thumbnail img")
370
+ og_img = doc.select_one("meta[property='og:image']")
371
+ image = (
372
+ (thumb.attr("src") if thumb else "")
373
+ or (og_img.attr("content") if og_img else "")
374
+ )
375
+ if image.startswith("//"):
376
+ image = "https:" + image
377
+
378
+ synopsis = ""
379
+ paragraphs = doc.select(".entry-content p")
380
+ for p in paragraphs:
381
+ spans = p.select("span")
382
+ if spans and re.match(r"^Synopsis", spans[0].text().strip(), re.I):
383
+ synopsis = spans[-1].text().strip()
384
+ break
385
+ if not synopsis:
386
+ for p in paragraphs:
387
+ txt = p.text().strip()
388
+ if txt.startswith("✅") and len(txt) > 40:
389
+ synopsis = txt
390
+ break
391
+
392
+ imdb_id = _extract_imdb_id(doc, html)
393
+
394
+ def detect_season_number() -> int | None:
395
+ for p in paragraphs:
396
+ m = re.search(r"Season\s*:?\s*0*(\d+)", p.text(), re.I)
397
+ if m:
398
+ return int(m.group(1))
399
+ tm = re.search(r"Season\s*0*(\d+)", title, re.I)
400
+ return int(tm.group(1)) if tm else None
401
+
402
+ entry_content = doc.select_one(".entry-content")
403
+ content_text = entry_content.text() if entry_content else ""
404
+ has_episodes = bool(re.search(r"Episode\s+\d+", content_text, re.I))
405
+ media_type = "series" if has_episodes else "movie"
406
+
407
+ cinemeta = (
408
+ get_cinemeta_meta(imdb_id, media_type, self.session) if imdb_id else None
409
+ )
410
+
411
+ link_list: list[dict[str, Any]] = []
412
+ if has_episodes:
413
+ season_number = detect_season_number()
414
+ lang_map: dict[str, list[dict[str, Any]]] = {}
415
+ current_ep: dict[str, str] | None = None
416
+
417
+ for p in paragraphs:
418
+ full_text = p.text().strip()
419
+ ep_m = re.match(
420
+ r"^Episode\s+0*(\d+)\s*(?:[–\-—:]\s*(.+?))?\s*$",
421
+ full_text,
422
+ re.I,
423
+ )
424
+ if ep_m:
425
+ current_ep = {
426
+ "num": ep_m.group(1),
427
+ "name": (ep_m.group(2) or "").strip(),
428
+ }
429
+ continue
430
+
431
+ if not current_ep:
432
+ continue
433
+ first_span = p.select_one("span")
434
+ if not first_span:
435
+ continue
436
+ lang_m = re.match(
437
+ r"^(Hindi\s*DUB|Hindi|Tamil|Telugu|English|Japanese|Korean|"
438
+ r"Malayalam|Kannada|Bengali|Marathi|Punjabi|Urdu|Multi[\s-]?Audio)\b",
439
+ first_span.text().strip(),
440
+ re.I,
441
+ )
442
+ if not lang_m:
443
+ continue
444
+ lang_name = _normalize_lang(lang_m.group(1))
445
+ picked = _pick_best_server_link(p)
446
+ if not picked:
447
+ continue
448
+
449
+ ep_title = (
450
+ f"Episode {current_ep['num']} – {current_ep['name']}"
451
+ if current_ep["name"]
452
+ else f"Episode {current_ep['num']}"
453
+ )
454
+ lang_map.setdefault(lang_name, []).append(
455
+ {"title": ep_title, "link": picked[1]}
456
+ )
457
+
458
+ if lang_map:
459
+ langs = sorted(
460
+ lang_map.keys(),
461
+ key=lambda lg: (_lang_order_index(lg), lg.lower()),
462
+ )
463
+ videos = (cinemeta or {}).get("videos") or []
464
+ for lang in langs:
465
+ eps = lang_map[lang]
466
+ enriched_eps = (
467
+ enrich_cinemeta_episodes(eps, videos, season_number)
468
+ if season_number is not None and videos
469
+ else eps
470
+ )
471
+ if season_number is not None:
472
+ entry_title = (
473
+ f"Season {season_number}"
474
+ if len(langs) == 1
475
+ else f"Season {season_number} · {lang}"
476
+ )
477
+ else:
478
+ entry_title = lang
479
+ link_list.append(
480
+ {
481
+ "title": entry_title,
482
+ "quality": "auto",
483
+ "directLinks": enriched_eps,
484
+ }
485
+ )
486
+
487
+ if not has_episodes or not link_list:
488
+ single_links: list[tuple[str, str, int]] = []
489
+ seen_links: set[str] = set()
490
+ seen_servers: set[str] = set()
491
+
492
+ for a in doc.select(".entry-content a"):
493
+ href = a.attr("href")
494
+ if not href or ("codedew.com/zipper" not in href and "hubcloud" not in href):
495
+ continue
496
+ matched = _match_server(a.text())
497
+ if not matched:
498
+ continue
499
+ srv_name, order = matched
500
+ if srv_name in seen_servers or href in seen_links:
501
+ continue
502
+ seen_servers.add(srv_name)
503
+ seen_links.add(href)
504
+ single_links.append((srv_name, href, order))
505
+
506
+ single_links.sort(key=lambda item: item[2])
507
+ if single_links:
508
+ season_number = detect_season_number()
509
+ fallback_title = (
510
+ "Movie"
511
+ if media_type == "movie"
512
+ else (
513
+ f"Season {season_number}"
514
+ if season_number is not None
515
+ else "Download"
516
+ )
517
+ )
518
+ link_list.append(
519
+ {
520
+ "title": fallback_title,
521
+ "quality": "auto",
522
+ "directLinks": [
523
+ {"title": name, "link": href}
524
+ for name, href, _ in single_links
525
+ ],
526
+ }
527
+ )
528
+ elif not link_list:
529
+ link_list.append(
530
+ {
531
+ "title": "Watch",
532
+ "quality": "auto",
533
+ "directLinks": [{"title": "Watch", "link": link}],
534
+ }
535
+ )
536
+
537
+ base_info: dict[str, Any] = {
538
+ "title": title,
539
+ "synopsis": synopsis,
540
+ "image": image,
541
+ "imdbId": imdb_id,
542
+ "type": media_type,
543
+ "linkList": link_list,
544
+ }
545
+ return apply_cinemeta_meta(base_info, cinemeta)
546
+ except Exception as exc:
547
+ throw_provider_error("RareAnimes", "info", exc)
548
+
549
+ def _resolve_episode_stream(self, episode_page: str, title: str) -> dict[str, Any] | None:
550
+ try:
551
+ doc = self.fetch_html(episode_page)
552
+ iframe = (
553
+ doc.select_one("section.player iframe")
554
+ or doc.select_one("iframe#main-video-frame")
555
+ or doc.select_one("iframe")
556
+ )
557
+ embed = iframe.attr("src") if iframe else ""
558
+ if not embed:
559
+ return None
560
+ if embed.startswith("//"):
561
+ embed = "https:" + embed
562
+ elif embed.startswith("/"):
563
+ embed = urljoin(episode_page, embed)
564
+
565
+ embed_doc = self.fetch_html(embed)
566
+ stream_iframe = (
567
+ embed_doc.select_one(".Video iframe") or embed_doc.select_one("iframe")
568
+ )
569
+ stream_url = stream_iframe.attr("src") if stream_iframe else ""
570
+ if not stream_url:
571
+ return None
572
+ if stream_url.startswith("//"):
573
+ stream_url = "https:" + stream_url
574
+ elif stream_url.startswith("/"):
575
+ stream_url = urljoin(embed, stream_url)
576
+ return {"title": title, "link": stream_url}
577
+ except Exception:
578
+ return None
579
+
580
+ def get_episodes(
581
+ self,
582
+ url: str,
583
+ imdb_id: str = "",
584
+ season: int | None = None,
585
+ ) -> list[dict[str, Any]]:
586
+ try:
587
+ doc = self.fetch_html(url)
588
+ cinemeta: dict[str, Any] | None = None
589
+ context_season: int | None = None
590
+ try:
591
+ ctx = read_cinemeta_context(url)
592
+ if ctx.get("imdbId") and ctx.get("season"):
593
+ context_season = ctx["season"]
594
+ cinemeta = get_cinemeta_meta(ctx["imdbId"], "series", self.session)
595
+ except Exception:
596
+ pass
597
+
598
+ episode_pages: list[dict[str, str]] = []
599
+ for card in doc.select("#episode_by_temp li, #episode_by_temp article.post"):
600
+ h2 = card.select_one("h2.entry-title")
601
+ num_epi = card.select_one(".num-epi")
602
+ title = (
603
+ (h2.text().strip() if h2 else "")
604
+ or (num_epi.text().strip() if num_epi else "")
605
+ or "Episode"
606
+ )
607
+ lnk = card.select_one("a.lnk-blk")
608
+ page = lnk.attr("href") if lnk else ""
609
+ if not page:
610
+ continue
611
+ if page.startswith("//"):
612
+ page = "https:" + page
613
+ elif page.startswith("/"):
614
+ page = urljoin(url, page)
615
+ episode_pages.append({"title": title, "link": page})
616
+
617
+ if not episode_pages:
618
+ single = self._resolve_episode_stream(url, "Play")
619
+ return [single] if single else []
620
+
621
+ pages = episode_pages
622
+ if cinemeta and cinemeta.get("videos") and context_season is not None:
623
+ pages = enrich_cinemeta_episodes(
624
+ episode_pages, cinemeta["videos"], context_season
625
+ )
626
+
627
+ with ThreadPoolExecutor(max_workers=6) as pool:
628
+ resolved = list(
629
+ pool.map(
630
+ lambda ep: self._resolve_episode_stream(ep["link"], ep["title"]),
631
+ pages,
632
+ )
633
+ )
634
+ return [item for item in resolved if item is not None]
635
+ except Exception as exc:
636
+ throw_provider_error("RareAnimes", "episodes", exc)
637
+
638
+ def get_stream(
639
+ self,
640
+ url: str,
641
+ is_download: bool = False,
642
+ media_type: str = "movie",
643
+ ) -> list[dict[str, Any]]:
644
+ try:
645
+ current_link = url
646
+ hubcloud_url: str | None = None
647
+
648
+ for _ in range(6):
649
+ if not _is_zipper_url(current_link):
650
+ hubcloud_url = current_link
651
+ break
652
+
653
+ html = self.fetch_text(current_link, headers=_STREAM_HEADERS, timeout=30)
654
+ doc = parse_html(html)
655
+ next_url = _extract_next_url(doc, html, current_link)
656
+ if not next_url:
657
+ break
658
+ if not _is_zipper_url(next_url):
659
+ hubcloud_url = next_url
660
+ break
661
+ time.sleep(5.5)
662
+ current_link = next_url
663
+
664
+ final_link = hubcloud_url or current_link
665
+ if not final_link or _is_zipper_url(final_link):
666
+ return []
667
+
668
+ return hubcloud_extractor(
669
+ final_link,
670
+ self.session,
671
+ is_download=is_download,
672
+ provider_value="rareanimes",
673
+ kv_store=self.kv,
674
+ )
675
+ except Exception:
676
+ return []