''' This file is part of tmdb-bot. tmdb-bot is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation. tmdb-bot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with tmdb-bot. If not, see . ''' import requests class TmdbApi(): def __init__(self): self.load_parameters() self.title = None self.id = None self.poster_url = None self.overview = None self.web_url = None self.vote_average = None self.language = 'de' self.valid = False def load_parameters(self): self.api_key = '51d75c00dc1502dc894b7773ec3e7a15' self.base_url = "https://api.themoviedb.org/3/" result = requests.get(self.base_url + 'configuration', params = self.get_apikey()).json() self.base_url_poster = result['images']['base_url'] + result['images']['poster_sizes'][0] def get_apikey(self): return { 'api_key' : self.api_key } def request(self, request_uri, payload : dict = {}): url = self.base_url + request_uri _payload = self.get_apikey() _payload['language'] = self.language _payload.update(payload) result = requests.get(url, params=_payload) self.valid = True return result def set_language(self, language): self.language = language def get_image_binary(self): if self.poster_url: return requests.get(self.poster_url).content else: return None class Movie(TmdbApi): def __init__(self): super().__init__() self.load_parameters() pass def search_title(self, title): url = self.base_url+ 'search/movie' payload = self.get_apikey() payload['language'] = self.language payload['query'] = title result = requests.get(url, params=payload) json = result.json() if json['total_results'] > 0: movie_id = json['results'][0]['id'] self.query_details(movie_id) return movie_id def query_details(self, id): data = self.request('movie/' + str(id)).json() self.title = data['title'] self.id = data['id'] self.poster_url = self.base_url_poster + data['poster_path'] self.overview = data['overview'] self.web_url = 'https://www.themoviedb.org/movie/' + str(self.id) self.vote_average = str(data['vote_average']) self.query_cast() def query_cast(self): data = self.request('movie/'+str(self.id)+'/credits').json() self.cast = [] for actor in data['cast']: self.cast.append(actor['name']) def get_cast(self, amount): return self.cast[:amount]