The Movie Database Support

This for an XBMC plugin I am building which displays movies you are missing from your movie collection. From what I understand, XBMC stores IMDB ids, while TMDB's collections api only returns TMDB ids for the movies in the collection. This means I have to make a call for every movie in the xbmc database in order to get their TMDB id. Below is my code:

def get_tmdb_configuration():
    request = urllib2.Request("http://api.themoviedb.org/3/configuration?api_key=%s" % API_KEY, headers={"Accept" : "application/json"})
    response = urllib2.urlopen(request).read()
    data = json.loads(response)
    return data['images']['base_url']

def get_movie_by_imdb_id(imdb_id):
    request = urllib2.Request("http://api.themoviedb.org/3/movie/%s?api_key=%s" % (imdb_id,API_KEY), headers={"Accept" : "application/json"})
    response = urllib2.urlopen(request).read()
    data = json.loads(response)
    collection = str(data["belongs_to_collection"]['id']) if data["belongs_to_collection"]  is not None else None
    movie = Movie(title=data['title'], id=str(data['id']),collection_id=collection,poster_path=base_image_url + data["poster_path"])
    return movie

def get_collection(collection_id):
    request = urllib2.Request("http://api.themoviedb.org/3/collection/%s?api_key=%s" % (collection_id,API_KEY), headers={"Accept" : "application/json"})
    response = urllib2.urlopen(request).read()
    data = json.loads(response)
    collection = Collection(name=data["name"],id=str(data["id"]),poster_path=base_image_url + data["poster_path"])
    for part in data["parts"]:
        movie = Movie(title=part['title'], id=str(part['id']),own=False,collection_id=collection.id,poster_path= base_image_url + part["poster_path"])
        collection.movies.append(movie)
    return collection

def organize_movies_by_collections(imdb_ids):
    collections ={}
    for imdb_id in imdb_ids:
        current_movie = get_movie_by_imdb_id(imdb_id)

        if current_movie.collection_id is not None:  
            if current_movie.collection_id in collections:
                current_collection = collection[current_movie.collection_id]
            else:
                current_collection = get_collection(current_movie.collection_id)
                collections[current_movie.collection_id] = current_collection

            movies_in_collection_owned = 0    
            for movie in current_collection.movies:
                if movie.id == current_movie.id:
                    movie.own = True
                    movies_in_collection_owned += 1

            if len(current_collection.movies) == movies_in_collection_owned:
                current_collection.own_all = True
    return collections

Thanks in advance for your help.

4 replies (on page 1 of 1)

Jump to last post

Hi yzupnick,

It doesn't look like anything crazy. Just looping through ids and when you find one that belongs to a collection, go off and retrieve the relevant collection info, right?

Correct. But if there is a way I can retrieve the imdb id from the collection API, I can significantly reduce the amount of requests I'm making.

For example: The script encounters the imdb id for "Back to the future 1" I receive the Back to the Future collection, which contains the TMDB ids of all the back to the future movies in the collection. When my script comes across the imdb id for "Back to the Future 2" I have to go make a request to get the TMDB id. If there is a way for me to get the IMDB ids with the collection, I wouldn't have to make a second request for the TMDB id.

We only provide the IMDB for referencing purposes, it's not designed to be an ID we use for cross-referencing items. This will always be our own, internal ID.

Does XBMC not provide a way of retrieving the TMDb id?

I don't believe so. I asked over at the XBMC forums though.

Can't find a movie or TV show? Login to create it.

Global

s focus the search bar
p open profile menu
esc close an open window
? open keyboard shortcut window

On media pages

b go back (or to parent when applicable)
e go to edit page

On TV season pages

(right arrow) go to next season
(left arrow) go to previous season

On TV episode pages

(right arrow) go to next episode
(left arrow) go to previous episode

On all image pages

a open add image window

On all edit pages

t open translation selector
ctrl+ s submit form

On discussion pages

n create new discussion
w toggle watching status
p toggle public/private
c toggle close/open
a open activity
r reply to discussion
l go to last reply
ctrl+ enter submit your message
(right arrow) next page
(left arrow) previous page

Settings

Want to rate or add this item to a list?

Login