Skip to content
This repository was archived by the owner on May 2, 2026. It is now read-only.

Commit 42f7e1d

Browse files
authored
Merge pull request #174 from viu-media/minor-fixes
2 parents 12ef447 + 7f4a1f2 commit 42f7e1d

4 files changed

Lines changed: 36 additions & 3 deletions

File tree

viu_media/core/downloader/yt_dlp.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ def download(self, params: DownloadParams) -> DownloadResult:
3030
sub_paths = []
3131
merged_path = None
3232

33+
logger.debug(f"Starting download for URL: {params.url}")
34+
logger.debug(f"Using Headers: {params.headers}")
35+
3336
if TORRENT_REGEX.match(params.url):
3437
from .torrents import download_torrent_with_webtorrent_cli
3538

viu_media/libs/provider/anime/animepahe/constants.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
ANIMEPAHE = "animepahe.si"
44
ANIMEPAHE_BASE = f"https://{ANIMEPAHE}"
55
ANIMEPAHE_ENDPOINT = f"{ANIMEPAHE_BASE}/api"
6+
CDN_PROVIDER = "kwik.cx"
7+
CDN_PROVIDER_BASE = f"https://{CDN_PROVIDER}"
68

79
SERVERS_AVAILABLE = ["kwik"]
810
REQUEST_HEADERS = {
@@ -25,13 +27,30 @@
2527
"Accept-Encoding": "Utf-8",
2628
"DNT": "1",
2729
"Connection": "keep-alive",
28-
"Referer": "https://animepahe.si/",
30+
"Referer": ANIMEPAHE_BASE + '/',
2931
"Upgrade-Insecure-Requests": "1",
3032
"Sec-Fetch-Dest": "iframe",
3133
"Sec-Fetch-Mode": "navigate",
3234
"Sec-Fetch-Site": "cross-site",
3335
"Priority": "u=4",
3436
"TE": "trailers",
3537
}
38+
39+
STREAM_HEADERS = {
40+
# "Host": "vault-16.owocdn.top", # This will have to be the actual host of the stream (behind Kwik)
41+
"Accept": "*/*",
42+
"Accept-Language": "en-US,en;q=0.5",
43+
"Accept-Encoding": "gzip, deflate, br, zstd",
44+
"Origin": CDN_PROVIDER_BASE,
45+
"Sec-GPC": "1",
46+
"Connection": "keep-alive",
47+
"Referer": CDN_PROVIDER_BASE + '/',
48+
"Sec-Fetch-Dest": "empty",
49+
"Sec-Fetch-Mode": "cors",
50+
"Sec-Fetch-Site": "cross-site",
51+
"TE": "trailers",
52+
}
53+
54+
3655
JUICY_STREAM_REGEX = re.compile(r"source='(.*)';")
3756
KWIK_RE = re.compile(r"Player\|(.+?)'")

viu_media/libs/provider/anime/animepahe/mappers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def map_to_server(
8888
episode: AnimeEpisodeInfo,
8989
translation_type: str,
9090
stream_links: list[tuple[str, str]],
91+
headers: dict[str, str],
9192
) -> Server:
9293
links = [
9394
EpisodeStream(
@@ -97,4 +98,4 @@ def map_to_server(
9798
)
9899
for link in stream_links
99100
]
100-
return Server(name="kwik", links=links, episode_title=episode.title)
101+
return Server(name="kwik", links=links, episode_title=episode.title, headers=headers)

viu_media/libs/provider/anime/animepahe/provider.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from functools import lru_cache
33
from typing import Iterator, Optional
4+
from urllib.parse import urlparse
45

56
from ..base import BaseAnimeProvider
67
from ..params import AnimeParams, EpisodeStreamsParams, SearchParams
@@ -9,9 +10,11 @@
910
from .constants import (
1011
ANIMEPAHE_BASE,
1112
ANIMEPAHE_ENDPOINT,
13+
CDN_PROVIDER,
1214
JUICY_STREAM_REGEX,
1315
REQUEST_HEADERS,
1416
SERVER_HEADERS,
17+
STREAM_HEADERS,
1518
)
1619
from .extractor import process_animepahe_embed_page
1720
from .mappers import map_to_anime_result, map_to_search_results, map_to_server
@@ -132,6 +135,7 @@ def episode_streams(self, params: EpisodeStreamsParams) -> Iterator[Server] | No
132135
quality = None
133136
translation_type = None
134137
stream_links = []
138+
stream_host = None
135139

136140
# TODO: better document the scraping process
137141
for res_dict in res_dicts:
@@ -170,13 +174,19 @@ def episode_streams(self, params: EpisodeStreamsParams) -> Iterator[Server] | No
170174
continue
171175
logger.debug(f"Found juicy stream: {juicy_stream.group(1)}")
172176
juicy_stream = juicy_stream.group(1)
177+
stream_host = urlparse(juicy_stream).hostname
173178
quality = res_dict["resolution"]
174179
logger.debug(f"Found quality: {quality}")
175180
translation_type = data_audio
176181
stream_links.append((quality, juicy_stream))
177182

178183
if translation_type and stream_links:
179-
yield map_to_server(episode, translation_type, stream_links)
184+
headers = {
185+
"User-Agent": self.client.headers["User-Agent"],
186+
"Host": stream_host or CDN_PROVIDER,
187+
**STREAM_HEADERS
188+
}
189+
yield map_to_server(episode, translation_type, stream_links, headers=headers)
180190

181191
@lru_cache()
182192
def _get_episode_info(

0 commit comments

Comments
 (0)