def search_movie(request): if request.method == 'GET': form = FilmSearchForm() return render(request, 'save_search.html', {'form': form}) elif request.method == 'POST': form = FilmSearchForm(request.POST) if form.is_valid(): tmdb = TMDb() tmdb.api_key = os.environ['KEY-MDB'] movie = Movie() query = request.POST.get('query', 'Marlina') search = movie.search(query) db, token, uid = initializationDb() for p in search: data = { "id": p.id, "title": p.title, "overview": p.overview, "poster_path": p.poster_path, "release_date": p.release_date, "popularity": p.popularity, "original_title": p.original_title, "vote_count": p.vote_count, "vote_average": p.vote_average } db.child(uid).child("movie_list").child(p.id).set(data, token) response = {"status": 200, "message": "Success Save"} return JsonResponse(response) else: response = {"status": 401, "message": "Invalid Input"} return JsonResponse(response)
def search_movie(query): tmdb = TMDb() tmdb.api_key = 'PLEASE GENERATE UR OWN API KEY, ALL INFO IN README FILE' movie = Movie() result = movie.search(query) number_of_movies = len(result) if number_of_movies == 0: print("SORRY, I CAN'T FIND ANYTHING, PLEASE TRY ANOTHER PHRASE") else: random_movie_title = choice(result).title print( f'I have found {number_of_movies} movies, here is a random choice for you:' ) print(f'Title: {random_movie_title}') for res in result: if res.title == random_movie_title: if res.overview == "": print('Sorry, no plot available :c') else: print(f'Movie id: {res.id}') print(f'Plot: {res.overview}') print(f'Released in {res.release_date}') similar = movie.similar(res.id) for sim in similar: print( f'Similar movie: {sim} (movie id: {sim.id}), released in {sim.release_date}' ) break break
def getMovies(self): tmdb = TMDb() tmdb.api_key = '1dc5bcb73c0781470cb348d5e02a05a5' tmdb.language = 'en' tmdb.debug = False movie = Movie() self.movie = movie self.popular = movie.popular() self.now = movie.now_playing() self.top = movie.top_rated() discover = Discover() self.movie_discovered = discover.discover_movies( {'sort_by': 'vote_average.desc'}) lists = [self.top, self.now, self.popular, self.movie_discovered] self.all_movies = [] for li in lists: for m in li: exist = False for r in self.all_movies: if r.id == m.id: exist = True if (not exist): self.all_movies.append(m)
def single_page(request, movie_id): conn = http.client.HTTPSConnection("api.themoviedb.org") tmdb3 = TMDb() tmdb3.api_key = 'bf4a7e22bb42072d024a9c1b6f88597f' movie = Movie() details = movie.details(movie_id) credits = movie.credits(movie_id) conn.request( "GET", "/3/movie/" + str(movie_id) + "/translations?api_key=" + tmdb3.api_key) res = conn.getresponse() data = res.read() json_data = json.loads(data) translations = json_data['translations'] rus = [] for indx in range(0, 10): if translations[indx]['iso_639_1'] == 'ru': rus = translations[indx] context = { 'details': details, 'credits': credits, "rus": rus, } return render(request, "kinopoiskapi/single.html", context)
def __init__(self): # key = self.load_api_key() tmdb = TMDb() tmdb.api_key = '76796d972576af7067d952e53839883b' tmdb.language = 'en' tmdb.debug = True self.tmdb = tmdb
def add_poster(self, movie_title): import requests from PyQt5.QtGui import QIcon, QPixmap from tmdbv3api import TMDb from tmdbv3api import Movie tmdb = TMDb() tmdb.api_key = '1437062848d1dda19bd3907cf120e9f4' tmdb.language = 'en' #tmdb.debug = True movie = Movie() m = movie.search(movie_title) for i in m: continue_path = i.poster_path if continue_path != "None": continue_path = i.poster_path #print(continue_path) break url = 'http://image.tmdb.org/t/p/w185' combine = url + continue_path #readlink href = combine r = requests.get(href, stream=True) pixmap = QPixmap() pixmap.loadFromData(r.content) self.poster.setPixmap(pixmap) self.poster.setScaledContents(True) #fullsizepic self.poster.show()
def popular_movie(request): if request.method == 'GET': return render(request, 'search_popular.html') elif request.method == 'POST': tmdb = TMDb() tmdb.api_key = os.environ['KEY-MDB'] movie = Movie() popular = movie.popular() db, token, uid = initializationDb() db.child("movie_popular").remove(token) for p in popular: data = { "id": p.id, "title": p.title, "overview": p.overview, "poster_path": p.poster_path, "release_date": p.release_date, "popularity": p.popularity, "original_title": p.original_title, "vote_count": p.vote_count, "vote_average": p.vote_average } db.child(uid).child("movie_popular").child(p.id).set(data, token) response = {"status": 200, "message": "Success Save"} return JsonResponse(response)
def discoverMedia(self, start_date, end_date): sd_str = datetime.strftime(start_date, '%Y-%m-%d') ed_str = datetime.strftime(end_date, '%Y-%m-%d') tmdb = TMDb() tmdb.api_key = tmdb_key tmdb.language = 'en' discover = Discover() movies = discover.discover_movies({ 'primary_release_date.gte': sd_str, 'primary_release_date.lte': ed_str }) for res in movies: try: Media.objects.get(external_id=res.id) continue except Media.DoesNotExist as ex: if res.release_date == '': res.release_date = None if res.poster_path == None: poster = "https://lascrucesfilmfest.com/wp-content/uploads/2018/01/no-poster-available-737x1024.jpg" else: poster = "https://www.themoviedb.org/t/p/w600_and_h900_bestv2" + res.poster_path Media.objects.create( title = res.title, description = res.overview, poster_url = poster, release_date = res.release_date, media_type= "Movie", external_id= res.id ) series = discover.discover_tv_shows({ 'first_air_date.gte': sd_str, 'first_air_date.lte': ed_str }) for res in series: if res.first_air_date == '': res.first_air_date = None if res.poster_path == None: poster = "https://lascrucesfilmfest.com/wp-content/uploads/2018/01/no-poster-available-737x1024.jpg" else: poster = "https://www.themoviedb.org/t/p/w600_and_h900_bestv2" + res.poster_path try: Media.objects.get(external_id=res.id) continue except Media.DoesNotExist as ex: Media.objects.create( title = res.name, description = res.overview, poster_url = poster, release_date = res.first_air_date, media_type= "TV", external_id= res.id )
def start(self): movie = Movie() if self.enviroment == "development": self.enviroment="localhost" else: self.enviroment="docker_redis" self.redis_server = redis.StrictRedis(host=self.enviroment, port=6379, db=0) tmdb = TMDb() tmdb.api_key = self.api_key self.getPopular(movie)
def query_api(self, name): tmdb = TMDb() tmdb.api_key = tmdb_key tmdb.language = 'en' #search movies movie = Movie() search_movie = movie.search(name) for res in search_movie: try: Media.objects.get(external_id=res.id) continue except Media.DoesNotExist as ex: if res.release_date == '': res.release_date = None if res.poster_path == None: poster = "https://lascrucesfilmfest.com/wp-content/uploads/2018/01/no-poster-available-737x1024.jpg" else: poster = "https://www.themoviedb.org/t/p/w600_and_h900_bestv2" + res.poster_path Media.objects.create( title = res.title, description = res.overview, poster_url = poster, release_date = res.release_date, media_type= "Movie", external_id= res.id ) #search TV tv = TV() search_tv = tv.search(name) for res in search_tv: if res.first_air_date == '': res.first_air_date = None if res.poster_path == None: poster = "https://lascrucesfilmfest.com/wp-content/uploads/2018/01/no-poster-available-737x1024.jpg" else: poster = "https://www.themoviedb.org/t/p/w600_and_h900_bestv2" + res.poster_path try: Media.objects.get(external_id=res.id) continue except Media.DoesNotExist as ex: Media.objects.create( title = res.name, description = res.overview, poster_url = poster, release_date = res.first_air_date, media_type= "TV", external_id= res.id )
def imdb_get_movies(config_path, plex, data): title_ids = data[1] print("| {} Movies found on IMDb".format(len(title_ids))) tmdb = TMDb() tmdb.api_key = config_tools.TMDB(config_path).apikey movie = Movie() imdb_map = {} matched_imdb_movies = [] missing_imdb_movies = [] current_length = 0 current_count = 0 plex_tools.create_cache(config_path) plex_movies = plex.Library.all() for m in plex_movies: current_count += 1 print_display = "| Processing: {}/{} {}".format(current_count, len(plex_movies), m.title) print(adjust_space(current_length, print_display), end="\r") current_length = len(print_display) if 'plex://' in m.guid: item = m # Check cache for imdb_id imdb_id = plex_tools.query_cache(config_path, item.guid, 'imdb_id') if not imdb_id: imdb_id, tmdb_id = plex_tools.alt_id_lookup(plex, item) print(adjust_space(current_length, "| Cache | + | {} | {} | {} | {}".format(item.guid, imdb_id, tmdb_id, item.title))) plex_tools.update_cache(config_path, item.guid, imdb_id=imdb_id, tmdb_id=tmdb_id) elif 'themoviedb://' in m.guid: if not tmdb.api_key == "None": tmdb_id = m.guid.split('themoviedb://')[1].split('?')[0] tmdbapi = movie.details(tmdb_id) imdb_id = tmdbapi.imdb_id if hasattr(tmdbapi, 'imdb_id') else None else: imdb_id = None elif 'imdb://' in m.guid: imdb_id = m.guid.split('imdb://')[1].split('?')[0] else: imdb_id = None if imdb_id and imdb_id in title_ids: imdb_map[imdb_id] = m else: imdb_map[m.ratingKey] = m print(adjust_space(current_length, "| Processed {} Movies".format(len(plex_movies)))) for imdb_id in title_ids: movie = imdb_map.pop(imdb_id, None) if movie: matched_imdb_movies.append(plex.Server.fetchItem(movie.ratingKey)) else: missing_imdb_movies.append(imdb_id) return matched_imdb_movies, missing_imdb_movies
def index(request): tmdb3 = TMDb() tmdb3.api_key = 'bf4a7e22bb42072d024a9c1b6f88597f' movie = Movie() popular = movie.popular() for p in popular: print(p.title) print(p.poster_path) print("===================BREAKLINE=====================") context = {'popular': popular} return render(request, "kinopoiskapi/kinopoisk.html", context)
def initTmdb(api_key): """ Returns a TMDB object initialized with the given api key Args: api_key (str) : TMDB api key Returns: tmdb : TMDB object """ tmdb = TMDb() tmdb.api_key = api_key tmdb.language = 'en' return tmdb
def ViewGroup(request, pk): #When a groups is clicked on - all the details #pk is group id #Recommender is in group_recommender.py template_name = 'movies/group_details.html' tmdb = TMDb() tmdb.api_key = '69c1026aa20e6449c7a0f74f69dffd7d' tmdb.language = 'en' people = GroupUsers.objects.filter(group_id=pk) group_name = GroupInfo.objects.filter(group_id=pk) group_movies = GroupMovieList.objects.filter(group_id=pk) m = [] vote_score = [] test = [] #Getting movies for watch list for movie in group_movies: vote_score.append(movie.vote) my_movies = Movie.objects.filter(movie_id=movie.movie_id) for mov in my_movies: tmdbId = mov.tmdbId movs = tmdb_movie() m.append(movs.details(tmdbId)) #Appending the vote count to the TMDB api link of top movies for index, i in enumerate(m): test.append((i, vote_score[index])) #Getting recommendations for group merging = [] for user in people: u_id = user.user_id user_info = UserProfile.objects.filter(id=u_id) for users in user_info: user_age = users.Age user_occupation = users.Occupation rec_movs = group_rec(user_age, user_occupation) rec_movs = rec_movs.index.values.tolist() merging.extend(rec_movs) all_mov = [word for word, word_count in Counter(merging).most_common(10)] id = pk args = { 'id': id, 'test': test, 'people': people, 'group_name': group_name, 'group_movies': group_movies, 'm': m, 'merging': merging, 'all_mov': all_mov } return render(request, template_name, args)
def Top10(request): #Display top 10 rated movies template_name = 'movies/movie_list.html' top_movies = TopMovies.objects.all() tmdb = TMDb() tmdb.api_key = '69c1026aa20e6449c7a0f74f69dffd7d' tmdb.language = 'en' movie = tmdb_movie() m = [] for mov in top_movies: m.append(movie.details(mov.tmdbId)) args = {'top_movies': top_movies, 'm': m} return render(request, template_name, args)
def IMDBtoTMDB(args): if args.tmdb != "AUTO-DETECT": return format = "" movie = Movie() tv = TV() tmdb = TMDb() tmdb.api_key = args.tmdbapi if (args.type == "TV"): format = 'tv_results' if (args.type == "Movie"): format = 'movie_results' tmdb = movie.external(f"{args.imdb}", f'imdb_id') if len(tmdb.get(format)) != 0: args.tmdb = tmdb.get(format)[0].get("id", "")
def __init__(self, language: str): self.tmdb = TMDb() self.tmdb.api_key = config.MOVIE_DB_API_KEY # '26e13c6a960c2e640f5e1867b9c52a46' self.tmdb.language = language or settings.LANGUAGE_CODE self.movie = Movie() self.discover = Discover() self.genre = Genre()
def __init__(self): self.tmdb = TMDb() self.tmdb.api_key = "e00b72174e4ae097af808f34a8f220fc" self.tv = TV() self.season = Season() self.movie = Movie() self.discover = Discover()
def __init__(self, bot): self.bot = bot config = configparser.ConfigParser() config.read('../auth.ini') self.tmdb = TMDb() self.tmdb.api_key = config.get('TMDB', 'api_key')
def __init__(self, api_key: str, language: str = 'en'): self.tmbd = TMDb() self.tmbd.api_key = api_key self.tmbd.language = language self.__tv = QueryTV(TV()) self.__movie = QueryMovie(Movie())
def imdb_get_movies(config_path, plex, data): tmdb = TMDb() movie = Movie() tmdb.api_key = config_tools.TMDB(config_path).apikey imdb_url = data if imdb_url[-1:] == " ": imdb_url = imdb_url[:-1] imdb_map = {} library_language = plex.Library.language try: r = requests.get(imdb_url, headers={'Accept-Language': library_language}) except requests.exceptions.MissingSchema: return tree = html.fromstring(r.content) title_ids = tree.xpath("//div[contains(@class, 'lister-item-image')]" "//a/img//@data-tconst") if title_ids: for m in plex.Library.all(): if 'themoviedb://' in m.guid: if not tmdb.api_key == "None": tmdb_id = m.guid.split('themoviedb://')[1].split('?')[0] tmdbapi = movie.details(tmdb_id) imdb_id = tmdbapi.imdb_id else: imdb_id = None elif 'imdb://' in m.guid: imdb_id = m.guid.split('imdb://')[1].split('?')[0] else: imdb_id = None if imdb_id and imdb_id in title_ids: imdb_map[imdb_id] = m else: imdb_map[m.ratingKey] = m matched_imbd_movies = [] missing_imdb_movies = [] for imdb_id in title_ids: movie = imdb_map.pop(imdb_id, None) if movie: matched_imbd_movies.append( plex.Server.fetchItem(movie.ratingKey)) else: missing_imdb_movies.append(imdb_id) return matched_imbd_movies, missing_imdb_movies
def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ['TMDB_API_KEY'] self.tmdb.language = "en" self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.tmdb.cache = False self.network = Network()
class TMDbTests(unittest.TestCase): def setUp(self): self.tmdb = TMDb('') def test_search(self): movie = self.tmdb.search("Pokémon") for l in movie: print l.title
def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ["TMDB_API_KEY"] self.tmdb.language = "en-US" self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.tmdb.cache = False self.certification = Certification()
def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = '48f5c3a8e871801d8ad36d4360ef1f84' self.tmdb.language = "en-US" self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.tmdb.cache = False self.episode = Episode()
def scrape_images(filepath, save_to='media/images/'): """ Takes path to a csv file as argument and uses TMDB API to download images by searching for title """ BASE_IMG_URL = 'https://image.tmdb.org/t/p/w500' tmdb = TMDb() tmdb.api_key = TMDB_API_KEY tmdb.language = 'en' tmdb.debug = True with open(filepath, 'r') as f: reader = csv.DictReader(f) movie = Movie() tv = TV() for i, row in enumerate(reader): title = row['title'] print(f'{i} Title: {title}') if row['type'] == 'TV Show': res = tv.search(title) else: res = movie.search(title) if len(res) == 0: print('No results found') continue elif len(res) > 1: print('Length of results: ', len(res)) print(res) # Check to see if image is available try: image_url = BASE_IMG_URL + res[0].poster_path except TypeError as e: print('No image available') continue image_response = requests.get(image_url) if image_response.status_code == 200: with open(save_to + row['show_id'] + '.jpg', 'wb') as f: f.write(image_response.content) else: print(f'Error retreiving image for: {title}') print(f'Status code: {image_response.status_code}') time.sleep(0.1)
def __init__(self): ''' A custom client for The Movie Database API for French movies ''' self.client = TMDb() self.client.language = 'fr-FR' self.movie_db = Movie() self.search = Search()
def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ["TMDB_API_KEY"] self.tmdb.language = "en-US" self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.tmdb.cache = False self.discover = Discover()
def setUp(self): self.tmdb = TMDb() self.tmdb.api_key = os.environ['TMDB_API_KEY'] self.tmdb.language = "en-US" self.tmdb.debug = True self.tmdb.wait_on_rate_limit = True self.tmdb.cache = False self.genre = Genre()
def init(): movieName = input("\nMovie Name?") tmdb = TMDb() tmdb.api_key = "10163a322f4558e7cc6411377702d81d" movie = Movie() try: search = movie.search(movieName) if search is not None: for e in search: movieID = e.id break else: movieID = None m = movie.details(movieID) initial_budget = m.budget revenue = m.revenue title = m.original_title print("-Full name: " + title) if (initial_budget is not 0): print("-Intial Budget: " + (str(int(initial_budget)))) else: print( "NO INITIAL BUDGET REPORTED. DO NOT USE THIS ENTRY FOR TRAINING DATA." ) if (revenue is not 0): print("-Revenue: " + (str(int(revenue)))) else: print( "NO REVENUE REPORTED. DO NOT USE THIS ENTRY FOR TRAINING DATA." ) exit() except: print("\nBad movie entry?") return title, initial_budget, revenue
def __init__(self, movieId, api_key, tmdb): tmdb = TMDb() self.language = 'en' self.base = "https://api.themoviedb.org/3/movie/" self.append_to_response = "videos" self.key = [] self.name = [] self.site = [] self.movieId = movieId self.api_key = api_key
for g in movie.genres: genre += '#' + g['name'].replace(' ', '') + ' ' image = movie.poster_path if image: image_path = pictures_path + image urllib.urlretrieve(config.TMDB_BASE_IMAGE_PATH + image, image_path) status = '%s - %s #movies %s' % (movie.title, movie.url, genre.lower()) try: api.update_with_media(image_path, status=status) except Exception as e: print(e.message) os.remove(image_path) print('Status updated: ' + status.encode('utf-8')) if __name__ == '__main__': tmdb = TMDb(api_key=None) tmdb.api_key = config.TMDB_API_KEY reddit = praw.Reddit(client_id=config.REDDIT_CLIENT_ID, client_secret=config.REDDIT_CLIENT_SECRET, user_agent=config.REDDIT_USER_AGENT) pictures_path = expanduser(config.PICTURES_PATH) auth = tweepy.OAuthHandler(config.CONSUMER_KEY, config.CONSUMER_SECRET) auth.set_access_token(config.ACCESS_KEY, config.ACCESS_SECRET) api = tweepy.API(auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True) Bot() schedule.every(60).minutes.do(Bot()) while 1: schedule.run_pending() time.sleep(1)
def setUp(self): self.tmdb = TMDb('')