Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +12 -3
src/streamlit_app.py
CHANGED
|
@@ -9,13 +9,17 @@ st.title("HiAnime Episode Screenshot")
|
|
| 9 |
@st.cache_data(show_spinner=True)
|
| 10 |
def get_screenshot():
|
| 11 |
"""
|
| 12 |
-
Runs Playwright headless, navigates to the anime
|
| 13 |
and returns the screenshot as bytes.
|
| 14 |
"""
|
| 15 |
async def screenshot_async():
|
| 16 |
async with async_playwright() as p:
|
| 17 |
browser = await p.chromium.launch(headless=True, args=["--no-sandbox"])
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
try:
|
| 20 |
await page.goto(
|
| 21 |
"https://hianime.to/watch/naruto-677",
|
|
@@ -24,8 +28,13 @@ def get_screenshot():
|
|
| 24 |
)
|
| 25 |
except Exception as e:
|
| 26 |
st.warning(f"Goto issue: {e}")
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
| 28 |
bytes_img = await page.screenshot(full_page=True)
|
|
|
|
|
|
|
| 29 |
await browser.close()
|
| 30 |
return bytes_img
|
| 31 |
|
|
|
|
| 9 |
@st.cache_data(show_spinner=True)
|
| 10 |
def get_screenshot():
|
| 11 |
"""
|
| 12 |
+
Runs Playwright headless in a clean context, navigates to the anime episode,
|
| 13 |
and returns the screenshot as bytes.
|
| 14 |
"""
|
| 15 |
async def screenshot_async():
|
| 16 |
async with async_playwright() as p:
|
| 17 |
browser = await p.chromium.launch(headless=True, args=["--no-sandbox"])
|
| 18 |
+
|
| 19 |
+
# Use a clean context (like incognito)
|
| 20 |
+
context = await browser.new_context()
|
| 21 |
+
page = await context.new_page()
|
| 22 |
+
|
| 23 |
try:
|
| 24 |
await page.goto(
|
| 25 |
"https://hianime.to/watch/naruto-677",
|
|
|
|
| 28 |
)
|
| 29 |
except Exception as e:
|
| 30 |
st.warning(f"Goto issue: {e}")
|
| 31 |
+
|
| 32 |
+
# Give time for any JS redirect to finish
|
| 33 |
+
await page.wait_for_timeout(5000)
|
| 34 |
+
|
| 35 |
bytes_img = await page.screenshot(full_page=True)
|
| 36 |
+
|
| 37 |
+
await context.close()
|
| 38 |
await browser.close()
|
| 39 |
return bytes_img
|
| 40 |
|