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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -13
app.py CHANGED
@@ -12,34 +12,50 @@ def home():
12
 
13
  @app.get("/search")
14
  def search_anime(keyword: str):
 
 
 
15
  try:
16
- url = f"https://hianime.to/search?keyword={keyword}"
17
  headers = {"User-Agent": "Mozilla/5.0"}
18
  resp = requests.get(url, headers=headers)
19
  if resp.status_code != 200:
20
  raise HTTPException(status_code=500, detail="Failed to fetch search page")
21
 
22
  soup = BeautifulSoup(resp.text, "html.parser")
23
- items = soup.select(".film-name") # each item container
24
 
25
  results = []
26
  for item in items:
27
- # title and URL
28
- title_elem = item.select_one("a")
29
  title = title_elem.text.strip() if title_elem else None
30
- url = title_elem["href"] if title_elem else None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
- # thumbnail
33
- thumb_elem = item.find_previous("img", class_="film-poster-img")
34
- thumbnail = None
35
- if thumb_elem:
36
- thumbnail = thumb_elem.get("data-src") or thumb_elem.get("src")
37
 
38
- if title and url:
39
  results.append({
40
  "title": title,
41
- "url": url,
42
- "thumbnail": thumbnail
 
 
43
  })
44
 
45
  return {"keyword": keyword, "results": results}
 
12
 
13
  @app.get("/search")
14
  def search_anime(keyword: str):
15
+ """
16
+ Example call: /search?keyword=naruto
17
+ """
18
  try:
19
+ url = f"https://www.aniwave.se/filter?keyword={keyword}"
20
  headers = {"User-Agent": "Mozilla/5.0"}
21
  resp = requests.get(url, headers=headers)
22
  if resp.status_code != 200:
23
  raise HTTPException(status_code=500, detail="Failed to fetch search page")
24
 
25
  soup = BeautifulSoup(resp.text, "html.parser")
26
+ items = soup.select("div.item") # each anime container
27
 
28
  results = []
29
  for item in items:
30
+ title_elem = item.select_one("a.name.d-title")
 
31
  title = title_elem.text.strip() if title_elem else None
32
+ path = title_elem["href"] if title_elem else None
33
+
34
+ thumb_elem = item.select_one("div.ani.poster img")
35
+ thumbnail = thumb_elem.get("src") if thumb_elem else None
36
+
37
+ # Episodes
38
+ sub_elem = item.select_one("span.ep-status.sub span")
39
+ dub_elem = item.select_one("span.ep-status.dub span")
40
+ total_elem = item.select_one("span.ep-status.total span")
41
+
42
+ episodes = {
43
+ "sub": int(sub_elem.text.strip()) if sub_elem else None,
44
+ "dub": int(dub_elem.text.strip()) if dub_elem else None,
45
+ "total": int(total_elem.text.strip()) if total_elem else None
46
+ }
47
 
48
+ # Type (Tv, Special, Movie)
49
+ type_elem = item.select_one("div.meta .inner .right")
50
+ anime_type = type_elem.text.strip() if type_elem else None
 
 
51
 
52
+ if title and path:
53
  results.append({
54
  "title": title,
55
+ "url": path,
56
+ "thumbnail": thumbnail,
57
+ "episodes": episodes,
58
+ "type": anime_type
59
  })
60
 
61
  return {"keyword": keyword, "results": results}