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