Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +23 -36
src/streamlit_app.py
CHANGED
|
@@ -3,14 +3,13 @@ from playwright.async_api import async_playwright
|
|
| 3 |
import asyncio
|
| 4 |
from io import BytesIO
|
| 5 |
|
| 6 |
-
st.set_page_config(page_title="HiAnime
|
| 7 |
-
st.title("HiAnime Episode
|
| 8 |
-
|
| 9 |
-
episode_url = st.text_input("Enter Episode URL", "https://www.aniwave.se/anime-watch/naruto/ep-1")
|
| 10 |
|
| 11 |
@st.cache_data(show_spinner=True)
|
| 12 |
-
def
|
| 13 |
-
|
|
|
|
| 14 |
async with async_playwright() as p:
|
| 15 |
browser = await p.chromium.launch(
|
| 16 |
headless=True,
|
|
@@ -28,48 +27,36 @@ def get_episode_info(url: str):
|
|
| 28 |
timezone_id="Africa/Lagos",
|
| 29 |
extra_http_headers={
|
| 30 |
"Accept-Language": "en-US,en;q=0.9",
|
| 31 |
-
"Referer": "https://
|
| 32 |
}
|
| 33 |
)
|
| 34 |
|
| 35 |
page = await context.new_page()
|
| 36 |
-
await page.goto(url, wait_until="domcontentloaded", timeout=60000)
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
|
| 45 |
-
|
| 46 |
-
videos = await page.eval_on_selector_all(
|
| 47 |
-
"#servers-content .server-item",
|
| 48 |
-
"""elements => elements.map(e => {
|
| 49 |
-
const type = e.querySelector(".server-name")?.textContent.trim();
|
| 50 |
-
const url = e.getAttribute("data-link") || e.querySelector("iframe")?.src;
|
| 51 |
-
return { type, url };
|
| 52 |
-
})"""
|
| 53 |
-
)
|
| 54 |
|
| 55 |
await context.close()
|
| 56 |
await browser.close()
|
| 57 |
|
| 58 |
-
return
|
| 59 |
-
|
| 60 |
-
return asyncio.run(fetch_async())
|
| 61 |
|
|
|
|
| 62 |
|
| 63 |
-
if episode_url:
|
| 64 |
-
st.write("Fetching episode info...")
|
| 65 |
-
result = get_episode_info(episode_url)
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
st.image(BytesIO(result["screenshot"]), caption="Episode Screenshot", use_column_width=True)
|
| 70 |
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
| 3 |
import asyncio
|
| 4 |
from io import BytesIO
|
| 5 |
|
| 6 |
+
st.set_page_config(page_title="HiAnime Screenshot", layout="wide")
|
| 7 |
+
st.title("HiAnime Episode Screenshot")
|
|
|
|
|
|
|
| 8 |
|
| 9 |
@st.cache_data(show_spinner=True)
|
| 10 |
+
def get_screenshot():
|
| 11 |
+
|
| 12 |
+
async def screenshot_async():
|
| 13 |
async with async_playwright() as p:
|
| 14 |
browser = await p.chromium.launch(
|
| 15 |
headless=True,
|
|
|
|
| 27 |
timezone_id="Africa/Lagos",
|
| 28 |
extra_http_headers={
|
| 29 |
"Accept-Language": "en-US,en;q=0.9",
|
| 30 |
+
"Referer": "https://anikai.to/",
|
| 31 |
}
|
| 32 |
)
|
| 33 |
|
| 34 |
page = await context.new_page()
|
|
|
|
| 35 |
|
| 36 |
+
await page.goto(
|
| 37 |
+
"https://anikai.to/watch/naruto-9r5k#ep=1",
|
| 38 |
+
wait_until="domcontentloaded",
|
| 39 |
+
timeout=60000
|
| 40 |
+
)
|
| 41 |
|
| 42 |
+
# Let JS redirect + player init finish
|
| 43 |
+
await page.wait_for_timeout(8000)
|
| 44 |
|
| 45 |
+
screenshot = await page.screenshot(full_page=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
await context.close()
|
| 48 |
await browser.close()
|
| 49 |
|
| 50 |
+
return screenshot
|
|
|
|
|
|
|
| 51 |
|
| 52 |
+
return asyncio.run(screenshot_async())
|
| 53 |
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
+
st.write("Fetching screenshot...")
|
| 56 |
+
img = get_screenshot()
|
|
|
|
| 57 |
|
| 58 |
+
if img:
|
| 59 |
+
st.image(BytesIO(img), caption="HiAnime Screenshot", use_column_width=True)
|
| 60 |
+
st.success("Screenshot loaded!")
|
| 61 |
+
else:
|
| 62 |
+
st.error("Failed to capture screenshot.")
|