Neon-AI commited on
Commit
d515885
·
verified ·
1 Parent(s): 23b1854

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py CHANGED
@@ -113,6 +113,42 @@ def get_metadata(path: str):
113
 
114
  except Exception as e:
115
  raise HTTPException(status_code=500, detail=f"Failed to fetch metadata: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
116
  # ===== END PATCH =====
117
 
118
  if __name__ == "__main__":
 
113
 
114
  except Exception as e:
115
  raise HTTPException(status_code=500, detail=f"Failed to fetch metadata: {str(e)}")
116
+
117
+ @app.get("/episodes")
118
+ async def get_episodes(path: str):
119
+ """
120
+ Example:
121
+ /episodes?path=/watch/naruto-677
122
+ """
123
+
124
+ async with async_playwright() as p:
125
+ browser = await p.chromium.launch(headless=True)
126
+ page = await browser.new_page()
127
+
128
+ await page.goto(f"https://hianime.to{path}", timeout=60000)
129
+
130
+ # Wait until episode list JS finishes
131
+ await page.wait_for_selector("#servers-content", timeout=60000)
132
+
133
+ episodes = []
134
+
135
+ items = await page.query_selector_all(".ep-item") # selector used after JS loads
136
+
137
+ for item in items:
138
+ ep_num = await item.get_attribute("data-ep")
139
+ ep_id = await item.get_attribute("data-id")
140
+
141
+ episodes.append({
142
+ "episode": int(ep_num),
143
+ "url": f"https://hianime.to{path}?ep={ep_id}"
144
+ })
145
+
146
+ await browser.close()
147
+
148
+ return {
149
+ "path": path,
150
+ "episodes": episodes
151
+ }
152
  # ===== END PATCH =====
153
 
154
  if __name__ == "__main__":