Поддръжка на 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 отговора (на страница 1 от общо 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.

Не можете да откриете филм или сериал? Влезте, за да го създадете.

Глобални

s фокусиране на лентата за търсене
p отваряне на меню "Профил"
esc затваряне на отворен прозорец
? отваряне на прозореца за клавишните комбинации

На страниците за медиите

b връщане назад
e към страницата за редактиране

На страниците за сезони

(стрелка надясно) към следващ сезон
(стрелка наляво) към предишния сезон

На страниците за епизоди

(стрелка надясно) към следващ епизод
(стрелка наляво) предишен епизод

На всички страници за изображения

a отваряне на прозорец за добавяне на изображение

На всички страници за редактиране

t меню за избор на език, на превода
ctrl+ s изпращане на форма

На страниците за дискусия

n създаване на нова дискусия
w статус на наблюдаване
p публична/лична
c затваряне/отваряне
a отваряне на действия
r отговаряне в дискусия
l към последния отговор
ctrl+ enter изпращане на вашето съобщение
(стрелка надясно) следваща страница
(стрелка наляво) предишна страница

Настройки

Искате ли да го оцените или добавите към списък?

Вход