Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -56,14 +56,17 @@ def search_anime(keyword: str):
|
|
| 56 |
for item in items:
|
| 57 |
title_elem = item.select_one(".film-name a")
|
| 58 |
thumb_elem = item.select_one("img")
|
|
|
|
|
|
|
|
|
|
| 59 |
results.append({
|
| 60 |
"title": title_elem.text.strip() if title_elem else None,
|
| 61 |
"url": title_elem["href"] if title_elem else None,
|
| 62 |
-
"thumbnail":
|
| 63 |
})
|
| 64 |
-
|
| 65 |
-
return {"keyword": keyword, "results": results}
|
| 66 |
|
|
|
|
|
|
|
| 67 |
except Exception as e:
|
| 68 |
raise HTTPException(status_code=500, detail=f"Failed to search anime: {str(e)}")
|
| 69 |
# ===== END PATCH =====
|
|
|
|
| 56 |
for item in items:
|
| 57 |
title_elem = item.select_one(".film-name a")
|
| 58 |
thumb_elem = item.select_one("img")
|
| 59 |
+
thumbnail = None
|
| 60 |
+
if thumb_elem:
|
| 61 |
+
thumbnail = thumb_elem.get("src") or thumb_elem.get("data-src") or thumb_elem.get("data-lazy-src")
|
| 62 |
results.append({
|
| 63 |
"title": title_elem.text.strip() if title_elem else None,
|
| 64 |
"url": title_elem["href"] if title_elem else None,
|
| 65 |
+
"thumbnail": thumbnail
|
| 66 |
})
|
|
|
|
|
|
|
| 67 |
|
| 68 |
+
# Optionally filter out incomplete results
|
| 69 |
+
results = [r for r in results if r["title"] and r["url"]]
|
| 70 |
except Exception as e:
|
| 71 |
raise HTTPException(status_code=500, detail=f"Failed to search anime: {str(e)}")
|
| 72 |
# ===== END PATCH =====
|