Update main.py

This commit is contained in:
Aira Catapang
2026-03-17 04:23:42 +00:00
committed by system
parent c1124c4e1b
commit 40d28f9f79

20
main.py
View File

@@ -249,27 +249,27 @@ class AnimePahe:
return res_data
async def _embed_to_m3u8(self, embed_url: str) -> Optional[str]:
"""Open embed URL and capture the first .m3u8 network request."""
p = await self.context.new_page()
m3u8 = None
found = asyncio.Event()
def capture(req):
nonlocal m3u8
if ".m3u8" in req.url:
if ".m3u8" in req.url and not found.is_set():
m3u8 = req.url
found.set()
p.on("request", capture)
try:
await p.set_extra_http_headers({"Referer": BASE_URL})
await p.goto(embed_url, wait_until="domcontentloaded")
for _ in range(10):
if m3u8:
break
await p.evaluate(
"document.querySelectorAll('button, video, [class*=play]')"
".forEach(el => el.click())"
)
await asyncio.sleep(0.5)
await p.evaluate(
"document.querySelectorAll('button, video, [class*=play]').forEach(el => el.click())"
)
try:
await asyncio.wait_for(found.wait(), timeout=5.0)
except asyncio.TimeoutError:
pass
finally:
await p.close()
return m3u8