refactored
This commit is contained in:
parent
5e238ba9b0
commit
89c1c1d7c5
23
tmdb.py
23
tmdb.py
@ -10,13 +10,16 @@ class Tmdb:
|
||||
self.apikey = apikey
|
||||
self.language = language
|
||||
|
||||
def get_tmdbid(self, imdbid):
|
||||
print("getting tmdbid for imdbid %s" % imdbid)
|
||||
url = self.baseurl + 'find/%s?api_key=%s&external_source=imdb_id'
|
||||
url = url % (imdbid, self.apikey)
|
||||
def fetch_from_tmdb(self, path, parameters, data):
|
||||
apikey = "?api_key=%s" % self.apikey
|
||||
url = (self.baseurl + path + apikey + parameters) % data
|
||||
json_url = urllib.urlopen(url)
|
||||
data = json.loads(json_url.read())
|
||||
print(data)
|
||||
return data
|
||||
|
||||
def get_tmdbid(self, imdbid):
|
||||
print("getting tmdbid for imdbid %s" % imdbid)
|
||||
data = self.fetch_from_tmdb('find/%s', '&external_source=imdb_id', imdbid)
|
||||
try:
|
||||
tmdbid = data['movie_results'][0]['id']
|
||||
print("tmdbid is %d" % tmdbid)
|
||||
@ -27,10 +30,7 @@ class Tmdb:
|
||||
|
||||
def get_recommendations(self, movieid, choice):
|
||||
print("getting %s for %d" % (choice, movieid))
|
||||
url = self.baseurl + 'movie/%d/%s?api_key=%s&language=%s'
|
||||
url = url % (movieid, choice, self.apikey, self.language)
|
||||
json_url = urllib.urlopen(url)
|
||||
data = json.loads(json_url.read())
|
||||
data = self.fetch_from_tmdb('movie/%d/%s', '&language=%s', (movieid, choice, self.language))
|
||||
results = []
|
||||
for result in data['results']:
|
||||
results.append({'title': result['title'], 'movieid': result['id']})
|
||||
@ -38,10 +38,7 @@ class Tmdb:
|
||||
|
||||
def get_movie_trailers(self, movieid):
|
||||
print("getting trailers for %d" % movieid)
|
||||
url = self.baseurl + 'movie/%d?api_key=%s&language=%s&append_to_response=videos'
|
||||
url = url % (movieid, self.apikey, self.language)
|
||||
json_url = urllib.urlopen(url)
|
||||
data = json.loads(json_url.read())
|
||||
data = self.fetch_from_tmdb('movie/%d', '&language=%s&append_to_response=videos', (movieid, self.language))
|
||||
results = []
|
||||
for result in data['videos']['results']:
|
||||
if result['site'] == 'YouTube':
|
||||
|
Loading…
Reference in New Issue
Block a user