I'm a beginner at Python.
I was trying to get some information about a movie using Imdbpy. The code looks like this:
def imdb(movie_name):
ia = IMDb()
results = ia.search_movie(movie_name)
movie_id = results[0].getID()
movie = ia.get_movie(movie_id)
return movie
This is very slow, it took about 1 minute to get the information. So I asked Chatgpt to make it faster and it told me to do this:
def imdb(movie_name):
ia = IMDb()
movie_fields = ['title', 'year', 'genres', 'Rating']
results = ia.search_movie(movie_name)
movie_id = results[0].getID()
movie = ia.get_movie(movie_id, info=movie_fields)
return movie
But now I get error like this:
2023-04-28 14:12:00,808 ERROR [imdbpy] C:\Users\mahdi\AppData\Roaming\Python\Python310-32\site-packages\imdb\__init__.py:844: unknown information set "title"
2023-04-28 14:12:00,813 ERROR [imdbpy] C:\Users\mahdi\AppData\Roaming\Python\Python310-32\site-packages\imdb\__init__.py:844: unknown information set "year"
2023-04-28 14:12:00,813 ERROR [imdbpy] C:\Users\mahdi\AppData\Roaming\Python\Python310-32\site-packages\imdb\__init__.py:844: unknown information set "genres"
2023-04-28 14:12:00,813 ERROR [imdbpy] C:\Users\mahdi\AppData\Roaming\Python\Python310-32\site-packages\imdb\__init__.py:844: unknown information set "Rating"
Traceback (most recent call last):
File "e:\python\file_name\film_names.py", line 185, in <module>
final_name = f"{film_name}.{movie['year']}"
File "C:\Users\mahdi\AppData\Roaming\Python\Python310-32\site-packages\imdb\utils.py", line 1503, in __getitem__
rawData = self.data[key]
KeyError: 'year'
Could you please help me to make this error disappear and also make it faster? Or if Imdb is not a good module to use, what should I use then?
I did try some APIs before this error popped up, I think some of them were Omdb API and Imdb API but it was working with requests and I just didn't want it to be complex.
And to note, I do want more information than ['title', 'year', 'genres', 'Rating']
. I want the plot that I'm taking this somewhere else and if it's a series I wanna get every episode's name and rate and maybe something else, not sure.