Supporto The Movie Database

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 risposte (nella pagina 1 di 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.

Non riesci a trovare un film o una serie Tv? Accedi per crearlo.

Globale

s focalizza la barra di ricerca
p apri menu profilo
esc chiudi una finestra aperta
? apri finestra scorciatoia tastiera

Su tutte le pagine di media

b torna indietro (o al precedente quando applicabile)
e vai alla pagina di modifica

Nelle pagine delle stagioni TV

(freccia destra) vai alla stagione successiva
(freccia sinistra) vai alla stagione precedente

Nelle pagine degli episodi TV

(freccia destra) vai all'episodio successivo
(freccia sinistra) vai all'episodio precedente

Su tutte le pagine di immagini

a apri finestra aggiungi immagine

Su tutte le pagine di modifica

t apri selettore traduzione
ctrl+ s invia modulo

Sulle pagine di discussione

n crea nuova discussione
w segna come visto/non visto
p cambia publico/privato
c cambia chiuso/aperto
a apri attivita
r rispondi alla discussione
l vai all'ultima risposta
ctrl+ enter invia il tuo messaggio
(freccia destra) pagina successiva
(freccia sinistra) pagina precedente

Impostazioni

Vuoi valutare o aggiungere quest'elemento a una lista?

Accedi