Coding Question: Easy way to get movie rating from moviedb?
#1
Hi there,

I am using the Sky Go addon (in Germany) and I am very happy with it. Only problem with it: Since the webside doesnt provide ratings for the movies, i keep looking up all the moviedb/imdb ratings in parallel and thinks this should be an easy task for some scrapper / code. Since I wanted to start coding for kodi and contribute to the community I was thinking about adding it myself and do a pull request afterwards...

I found out how to set the rating:

list_item = xbmcgui.ListItem(label=item)
list_item.setInfo('video', 'rating': '9.1')

However, not all movies are rated 9.1 Smile and therefore i need to get the corresponding value from moviedb/imdb or some other source before setting it. This works great with locale files (with scrappers), however I have not been able to find an easy way to get this generated by the Addon code... can someone help me and point to what is the easiest way to get the rating from moviedb/imdb? Title, Genre, Year are available - so this should not be an issue of providing enough info to find it on moviedb/imdb - I am just now sure how to get it scrapped/downloaded by the addon!

Thank you,
Linkin
Reply
#2
moviedb and tvdb provide public APIs that allow to fetch necessary data. You need to see documentation for respective APIs.
Reply
#3
I've got it to work with moviedb today. Works fine, only one issue: I can only get about 40 request per 10 seconds according to the api, however the list usually has a little more (45 to 50) ... I will look into how to solve his and create a pull request afterwards...!

Suggestions are welcome [emoji6]
Reply
#4
You can implement some kind of throttling, for example pause for 0.25-0.3s after each request.
Reply
#5
right, if your writing the addon then you can limit the requests to 40. and i'd also recommend threading it would really speed things up and you wont feel like you're downgrading because of the amount of results, unless this is a public addon. then i'd say request a premium api account
Reply
#6
Thank you for the input! I wasn't aware there is a way to get a premium api account! Currently I am trying this only for me, however when I am satisfied with the result I will create a pull request for the official addon!

What exactly do you mean by threading the request?
Reply
#7
(2017-05-15, 11:19)linkinsoldier Wrote: What exactly do you mean by threading the request?

In theory, you can use several threads/processes to fetch and process data in parallel. But this is not the case here, because you need to throttle your requests, not to speed up them.
Reply
#8
well python usually reads one line at a time or one calcucation or in this case it's one web request gets made at a time
when you impliment threading it allows you to make multiple calculations at once rendering the whole process faster.
so lets say you have 40 items that you need to make a web request to
first you want to have your queries (best to use the imdb or tmdb id) in some sort of list to generate through
make a function that sends a request to the api and executes your code


import threading
import urllib2
import json

apikey = "your key here"
address = "http://api.themoviedb.org/3/find/{0}?api_key={1}&external_source=imdb_id"

# function
def api(imdb):
GettingWebData = urllib2.urlopen(address.format(imdb,apikey))
ConvertToDict = json.loads(GettingWebData.read())
FirstMovieResultVotesAverage = ConvertToDict["movie_results"][0]["vote_average"]
#heres where i would start using add directory

but once you have that setup exactly how you want each item to be handled you call it from a thread

something like this
for i in listofimdbids::
threading.Thread(target="api",args=i,).start()

(2017-05-15, 11:19)linkinsoldier Wrote: Thank you for the input! I wasn't aware there is a way to get a premium api account! Currently I am trying this only for me, however when I am satisfied with the result I will create a pull request for the official addon!

What exactly do you mean by threading the request?
Reply
#9
All you can do is cache the results for re-use later on.
Read/follow the forum rules.
For troubleshooting and bug reporting, read this first
Interested in seeing some YouTube videos about Kodi? Go here and subscribe
Reply

Logout Mark Read Team Forum Stats Members Help
Coding Question: Easy way to get movie rating from moviedb?0