File size: 617 Bytes
85356ea
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from imdb import IMDb

# Create a global IMDb instance
ia = IMDb()

def search_imdb(title: str):
    """
    Search for a movie by title and return the most relevant result.
    """
    results = ia.search_movie(title)
    if not results:
        return {"error": "No results found"}

    top_result = results[0]
    ia.update(top_result)  # fetch full details

    return {
        "Title": top_result.get("title"),
        "Year": top_result.get("year"),
        "Rating": top_result.get("rating"),
        "Genres": top_result.get("genres"),
        "Plot": top_result.get("plot", ["No plot available"])[0],
    }