Spaces:
Sleeping
Sleeping
Rename utils/imdb to utils/imdb_tools.py
Browse files- utils/imdb +0 -18
- utils/imdb_tools.py +23 -0
utils/imdb
DELETED
@@ -1,18 +0,0 @@
|
|
1 |
-
from imdb import IMDb
|
2 |
-
|
3 |
-
ia = IMDb()
|
4 |
-
|
5 |
-
def search_imdb(title):
|
6 |
-
results = ia.search_movie(title)
|
7 |
-
if not results:
|
8 |
-
return "No results found"
|
9 |
-
|
10 |
-
top = results[0]
|
11 |
-
ia.update(top)
|
12 |
-
return {
|
13 |
-
"Title": top.get("title"),
|
14 |
-
"Year": top.get("year"),
|
15 |
-
"Rating": top.get("rating"),
|
16 |
-
"Genres": top.get("genres"),
|
17 |
-
"Plot": top.get("plot")[0] if top.get("plot") else "No plot available"
|
18 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
utils/imdb_tools.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from imdb import IMDb
|
2 |
+
|
3 |
+
# Create a global IMDb instance
|
4 |
+
ia = IMDb()
|
5 |
+
|
6 |
+
def search_imdb(title: str):
|
7 |
+
"""
|
8 |
+
Search for a movie by title and return the most relevant result.
|
9 |
+
"""
|
10 |
+
results = ia.search_movie(title)
|
11 |
+
if not results:
|
12 |
+
return {"error": "No results found"}
|
13 |
+
|
14 |
+
top_result = results[0]
|
15 |
+
ia.update(top_result) # fetch full details
|
16 |
+
|
17 |
+
return {
|
18 |
+
"Title": top_result.get("title"),
|
19 |
+
"Year": top_result.get("year"),
|
20 |
+
"Rating": top_result.get("rating"),
|
21 |
+
"Genres": top_result.get("genres"),
|
22 |
+
"Plot": top_result.get("plot", ["No plot available"])[0],
|
23 |
+
}
|