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