mirror of
https://huggingface.co/spaces/Catapang1989/aniscrap
synced 2026-04-18 00:01:47 +00:00
Update main.py
This commit is contained in:
16
main.py
16
main.py
@@ -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):
|
|
||||||
if m3u8:
|
|
||||||
break
|
|
||||||
await p.evaluate(
|
await p.evaluate(
|
||||||
"document.querySelectorAll('button, video, [class*=play]')"
|
"document.querySelectorAll('button, video, [class*=play]').forEach(el => el.click())"
|
||||||
".forEach(el => el.click())"
|
|
||||||
)
|
)
|
||||||
await asyncio.sleep(0.5)
|
try:
|
||||||
|
await asyncio.wait_for(found.wait(), timeout=5.0)
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
pass
|
||||||
finally:
|
finally:
|
||||||
await p.close()
|
await p.close()
|
||||||
return m3u8
|
return m3u8
|
||||||
|
|||||||
Reference in New Issue
Block a user