Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
imdby package problem
#1
I am trying to build an app that connects on imdb module and will be able to access diferent kinds of information about the film in question
from imdby.imdb import imdb
details=imdb("tt4154796")
print(details)
My problem is whenever i try to run it i get an IndexError code. Can someone help me understand whats going wrong here?
Reply
#2
Post full error message and trace. Or would it be better if I installed the module so I can run your code snd maybe see the error?

My guess would be that tt4154796 is not a valid id. I did type this in as a search on imdb.com and it pulled up Avengers: End Game, so maybe the problem is something else. Hard to say without any information about the error.

Why are you using this package instead of something like Cinemagoer (used to be imdbPy)?
Reply
#3
(Sep-04-2023, 01:54 PM)deanhystad Wrote: Post full error message and trace. Or would it be better if I installed the module so I can run your code snd maybe see the error?

My guess would be that tt4154796 is not a valid id. I did type this in as a search on imdb.com and it pulled up Avengers: End Game, so maybe the problem is something else. Hard to say without any information about the error.

Why are you using this package instead of something like Cinemagoer (used to be imdbPy)?

ok so basically i updated my code a bit. I first look for a movie based on title. I then confirm that is the movie the user is looking for. After that i try to receive information about the movie based on the movie ID. However i still have the same problem. Basically i want to be able to get movie data from the movie id variable and use that to print out data like director(s),actor(s) etc. My code is:

import imdb as im
from tkinter import *
from tkinter import simpledialog,messagebox
from imdby.imdb import imdb

def get_data(movie_id):
    details=imdb(movie_id)
    print(details)
    messagebox.showinfo(title="Movie Information",message=f"{details}")

def search_for_film(name):
    cg = im.Cinemagoer()
    search = cg.search_movie(name)

    for i in range(len(search)):
        if messagebox.askokcancel(title=f"Movie Title",message=f"Is {search[i]} the movie you are looking for?"):
            id=search[i].movieID
            get_data(id)
            return id

window=Tk()
ia=im.IMDb()
window.config(padx=50,pady=50)
window.title("Movie Information App")
canvas=Canvas(width=523,height=523)
pic=PhotoImage(file="./IMDb_Jobs_Header_Mobile.png")
bg_img=canvas.create_image(272,272,image=pic)
canvas.grid(row=1,column=0)
movie_name=simpledialog.askstring(title="Movie Information",prompt="Choose a film")
movie_id=search_for_film(movie_name)




window.mainloop()
My current error code is:
Error:
Traceback (most recent call last): File "C:\Users\giorg\PycharmProjects\pythonProject2\IMDB\main.py", line 30, in <module> movie_id=search_for_film(movie_name) File "C:\Users\giorg\PycharmProjects\pythonProject2\IMDB\main.py", line 18, in search_for_film get_data(id) File "C:\Users\giorg\PycharmProjects\pythonProject2\IMDB\main.py", line 7, in get_data details=imdb(movie_id) File "C:\Users\giorg\AppData\Local\Programs\Python\Python39\lib\site-packages\imdby\imdb.py", line 23, in __init__ release_info.__init__(self, titleid) File "C:\Users\giorg\AppData\Local\Programs\Python\Python39\lib\site-packages\imdby\release_info.py", line 28, in __init__ releases_index = [i for i in range(len(soup.select('h4'))) if 'release' in ' '.join(soup.select('h4')[i].text.split()).lower()][0] IndexError: list index out of range
Reply
#4
(Sep-04-2023, 01:54 PM)deanhystad Wrote: Post full error message and trace. Or would it be better if I installed the module so I can run your code snd maybe see the error?

My guess would be that tt4154796 is not a valid id. I did type this in as a search on imdb.com and it pulled up Avengers: End Game, so maybe the problem is something else. Hard to say without any information about the error.

Why are you using this package instead of something like Cinemagoer (used to be imdbPy)?
ok so the code below now works. i forgot to add the parentheses after the object initialization. However i only get the title of the film back this time without errors. What i need is to get some kind of dictionary with the information about the film instead of just the title. do you know any packages or something that would help me acquire that?
def get_data(movie_id):
    ia=im.IMDb()
    search=ia.get_movie(movie_id)
    print(search)
Reply
#5
Looks like an internal package problem. Probably due to a change in the IMDB web page. Move on to a different package.

This fails if there is no "h4" in your soup, or if none of the h4 contain the word 'release'. I hate it when there's no "h4" released in my soup.
releases_index = [i for i in range(len(soup.select('h4'))) if 'release' in  ' '.join(soup.select('h4')[i].text.split()).lower()][0]
Well written web scraping code should never assume any search will find a match. And it is so easy to fix:
releases = [i for i in range(len(soup.select('h4'))) if 'release' in  ' '.join(soup.select('h4')[i].text.split()).lower()]
release_index = releases[0] if releases else None
Stop using the "Reply" button unless your post directly references something in the post you are replying too. Use the "New Reply" button if your post just adds information.
Reply
#6
(Sep-04-2023, 02:33 PM)deanhystad Wrote: Looks like an internal package problem. Probably due to a change in the IMDB web page. Move on to a different package.

This fails if there is no "h4" in your soup, or if none of the h4 contain the word 'release'. I hate it when there's no "h4" released in my soup.
releases_index = [i for i in range(len(soup.select('h4'))) if 'release' in  ' '.join(soup.select('h4')[i].text.split()).lower()][0]
Well written web scraping code should never assume any search will find a match. And it is so easy to fix:
releases = [i for i in range(len(soup.select('h4'))) if 'release' in  ' '.join(soup.select('h4')[i].text.split()).lower()]
release_index = releases[0] if releases else None

ok.. wooooo. getting into the heavy stuff here. Can you check my comment above yours asking for any package or library or whatever that will help me retrieve some kind of json or dictionary file with the film information assigned by the movie id? Cause what i have now only gives me back the title which is useless
Reply
#7
How about the one I mentioned in my first reply, Cinemagoer (used to be imdbPy)? That was last updated in May.
Reply
#8
(Sep-04-2023, 02:42 PM)deanhystad Wrote: How about the one I mentioned in my first reply, Cinemagoer (used to be imdbPy)? That was last updated in May.

that was very helpful. after messing about a bit i decided to try and get the release year from Cinemagoer but i can't seem to be able to find the appropriate key for the release year of the feature. I tried printing the variable where i assign the get_movie function output but all i get is the title of the film. As you can see below i have access to the directors, genres and actors but i still cant find the year. ive tried 'year','release year' and 'release_year' to no avail


def get_data(movie_id):
    ia=im.Cinemagoer()
    search=ia.get_movie(movie_id)
    directors=[director['name'] for director in search['directors']]
    genres=search["genres"]
    actors=[actor['name'] for actor in search['actors']][0:8]
    messagebox.showinfo(title=f"{search} Information",message=f"Director(s): {directors}\n"
          f"Genres: {genres}\n"
          f"Actors: {actors}")
Reply
#9
Do you think guessing is the best strategy?

Most object keep their instance variables in a dictionary named dict. Let's see what keys are in the __dict__.
from imdb import Cinemagoer

ia = Cinemagoer()
search = ia.get_movie('0133093')   # The Matrix
print(*search.__dict__)
Output:
data myID notes titlesRefs namesRefs charactersRefs modFunct current_info infoset2keys key2infoset _Container__role movieID myTitle accessSystem keys_tomodify _roleIsPerson _roleClass
Nothing all that promising there. Those attributes must reference some sort of collection. "data" looks promising.
from imdb import Cinemagoer

ia = Cinemagoer()
search = ia.get_movie('0133093')   # The Matrix
print(type(search.data))
Output:
<class 'dict'>
data is a dict. Lets look at the keys.
from imdb import Cinemagoer

ia = Cinemagoer()
search = ia.get_movie('0133093')   # The Matrix
print(search.data.keys())
Output:
dict_keys(['localized title', 'cast', 'genres', 'runtimes', 'countries', 'country codes', 'language codes', 'color info', 'aspect ratio', 'sound mix', 'box office', 'certificates', 'original air date', 'rating', 'votes', 'cover url', 'imdbID', 'videos', 'plot outline', 'languages', 'title', 'year', 'kind', 'original title', 'director', 'writer', 'producer', 'composer', 'cinematographer', 'editor', 'editorial department', 'casting director', 'production design', 'art direction', 'set decoration', 'costume designer', 'make up', 'production manager', 'assistant director', 'art department', 'sound crew', 'special effects', 'visual effects', 'stunt performer', 'camera and electrical department', 'animation department', 'casting department', 'costume department', 'location management', 'music department', 'script department', 'transportation department', 'miscellaneous crew', 'akas', 'top 250 rank', 'production companies', 'distributors', 'special effects companies', 'other companies', 'plot', 'synopsis'])
"original air date" looks interesting.
from imdb import Cinemagoer

ia = Cinemagoer()
search = ia.get_movie('0133093')   # The Matrix
print(search.data['original air date'])
Output:
31 Mar 1999 (USA)
Snooping around in the other fields may reveal more information. You'll have to snoop around.

The best way to snoop is to use interactive python.
Output:
(env) > python Python 3.11.1 (tags/v3.11.1:a7a450f, Dec 6 2022, 19:58:39) [MSC v.1934 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from imdb import Cinemagoer >>> info = Cinemagoer().get_movie('0133093') >>> dir(info) ['_Container__role', '__bool__', '__class__', '__contains__', '__deepcopy__', '__delattr__', '__delitem__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getstate__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__len__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_additional_keys', '_clear', '_getSeriesTitle', '_get_currentRole', '_get_roleID', '_getitem', '_image_key', '_init', '_reset', '_roleClass', '_roleIsPerson', '_set_currentRole', '_set_roleID', 'accessSystem', 'add_to_current_info', 'append_item', 'asXML', 'charactersRefs', 'clear', 'cmpFunct', 'copy', 'currentRole', 'current_info', 'data', 'default_info', 'get', 'getAsXML', 'getID', 'get_charactersRefs', 'get_current_info', 'get_fullsizeURL', 'get_namesRefs', 'get_titlesRefs', 'guessLanguage', 'has_current_info', 'has_key', 'infoset2keys', 'isSame', 'isSameMovie', 'isSameTitle', 'items', 'iteritems', 'iterkeys', 'itervalues', 'key2infoset', 'keys', 'keys_alias', 'keys_tomodify', 'keys_tomodify_list', 'modFunct', 'movieID', 'myID', 'myTitle', 'namesRefs', 'notes', 'pop', 'popitem', 'reset', 'roleID', 'set_current_info', 'set_data', 'set_item', 'set_mod_funct', 'set_title', 'setdefault', 'smartCanonicalTitle', 'summary', 'titlesRefs', 'update', 'update_charactersRefs', 'update_infoset_map', 'update_namesRefs', 'update_titlesRefs', 'values'] >>> data = info.data >>> data.keys() dict_keys(['localized title', 'cast', 'genres', 'runtimes', 'countries', 'country codes', 'language codes', 'color info', 'aspect ratio', 'sound mix', 'box office', 'certificates', 'original air date', 'rating', 'votes', 'cover url', 'imdbID', 'videos', 'plot outline', 'languages', 'title', 'year', 'kind', 'original title', 'director', 'writer', 'producer', 'composer', 'cinematographer', 'editor', 'editorial department', 'casting director', 'production design', 'art direction', 'set decoration', 'costume designer', 'make up', 'production manager', 'assistant director', 'art department', 'sound crew', 'special effects', 'visual effects', 'stunt performer', 'camera and electrical department', 'animation department', 'casting department', 'costume department', 'location management', 'music department', 'script department', 'transportation department', 'miscellaneous crew', 'akas', 'top 250 rank', 'production companies', 'distributors', 'special effects companies', 'other companies', 'plot', 'synopsis']) >>> data["title"] 'The Matrix'
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem install somewhere package akbarza 1 493 Dec-27-2023, 01:25 PM
Last Post: Gribouillis
  Problem: Restart kernel onPydev console when trying to install a python package poppy2020 1 7,723 Nov-25-2020, 06:13 PM
Last Post: Larz60+
  Problem with importing an installed package Reverend_Jim 4 3,722 Jun-14-2019, 10:20 PM
Last Post: Reverend_Jim
  Problem installing urlparse4 package BobLoblaw 2 5,762 Oct-06-2017, 05:16 PM
Last Post: BobLoblaw

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020