Neon-AI commited on
Commit
d607631
·
verified ·
1 Parent(s): e398dc5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -13
app.py CHANGED
@@ -31,36 +31,41 @@ class StartPayload(BaseModel):
31
 
32
  def download_video(anime_id: str, episode: int, quality: str) -> str | None:
33
  url = f"{HF_AYANO_BASE}/anime/download?id={anime_id}&episode={episode}&quality={quality}"
34
- log(f"Calling Ayano: {url}")
35
-
36
- resp = requests.get(url, timeout=30)
37
- log(f"Ayano HTTP {resp.status_code}")
38
 
 
39
  if resp.status_code != 200:
40
- log("Ayano non-200 HTTP")
41
  return None
42
 
43
  data = resp.json()
44
- log(f"Ayano JSON: {data}")
45
-
46
- if data.get("status") == 422:
47
- raise EpisodeExceedsAvailableCount()
48
 
49
  if data.get("status") != 200:
50
- log("Ayano returned non-200 status field")
51
  return None
52
 
53
  video_url = data["direct_link"]
54
- log(f"Downloading video from: {video_url}")
 
 
 
 
 
 
 
 
 
 
55
 
56
  tmp_path = tempfile.mktemp(suffix=".mp4")
 
57
 
58
- with requests.get(video_url, stream=True, timeout=60) as r:
59
  r.raise_for_status()
60
  with open(tmp_path, "wb") as f:
61
  shutil.copyfileobj(r.raw, f)
62
 
63
- log(f"Video saved to {tmp_path}")
64
  return tmp_path
65
 
66
  def get_filename(anime_name: str, ep: int, quality: str) -> str:
 
31
 
32
  def download_video(anime_id: str, episode: int, quality: str) -> str | None:
33
  url = f"{HF_AYANO_BASE}/anime/download?id={anime_id}&episode={episode}&quality={quality}"
34
+ print(f"[HF] Calling Ayano: {url}")
 
 
 
35
 
36
+ resp = requests.get(url, timeout=20)
37
  if resp.status_code != 200:
38
+ print("[HF] Ayano non-200")
39
  return None
40
 
41
  data = resp.json()
42
+ print(f"[HF] Ayano JSON: {data}")
 
 
 
43
 
44
  if data.get("status") != 200:
 
45
  return None
46
 
47
  video_url = data["direct_link"]
48
+
49
+ headers = {
50
+ "User-Agent": (
51
+ "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
52
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
53
+ "Chrome/120.0.0.0 Safari/537.36"
54
+ ),
55
+ "Referer": "https://animepahe.com/",
56
+ "Accept": "*/*",
57
+ "Connection": "keep-alive",
58
+ }
59
 
60
  tmp_path = tempfile.mktemp(suffix=".mp4")
61
+ print(f"[HF] Downloading video from: {video_url}")
62
 
63
+ with requests.get(video_url, headers=headers, stream=True, timeout=60) as r:
64
  r.raise_for_status()
65
  with open(tmp_path, "wb") as f:
66
  shutil.copyfileobj(r.raw, f)
67
 
68
+ print(f"[HF] Download complete → {tmp_path}")
69
  return tmp_path
70
 
71
  def get_filename(anime_name: str, ep: int, quality: str) -> str: