def __init__(self): # key = self.load_api_key() tmdb = TMDb() tmdb.api_key = '76796d972576af7067d952e53839883b' tmdb.language = 'en' tmdb.debug = True self.tmdb = tmdb
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 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 getAdditionalData(self, movieId): if "Url" not in self.movieID_to_info[movieId]: tmdb = TMDb() tmdb.api_key = '66a11b9611008995220d8300279b6011' tmdb.language = 'en' tmdb.debug = True base = "https://image.tmdb.org/t/p/w200" url = "" title = self.movieID_to_info[movieId]["Title"][:-6] search = Movie().search(title) if search != []: url = search[0].poster_path else: search = TV().search(title) if search != []: url = search[0].poster_path self.movieID_to_info[movieId]["Url"] = base + url return self.getChartData(movieId)
# TMDb API from tmdbv3api import TMDb from tmdbv3api import Movie from tmdbv3api import TV # For loading JSON file import json # Open the JSON file with open('./everything.json', encoding='utf-8') as fh: file = json.load(fh) tmdb = TMDb() tmdb.api_key = 'a9545ec1bd745e79c447cdadf22cb82c' tmdb.language = 'en' tmdb.debug = True tv = TV() movie = Movie() data = [] for i in range(1): print(obj['title']) if (obj['type'] == "TV Show"): show = tv.search(obj['title']) try: print(show[0].name) print(show[0].poster_path)
from .models import ReviewMovie, ReviewSeries from django.contrib import messages from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from tmdbv3api import TMDb, Movie, TV from keras.datasets import imdb import re from keras.models import load_model tmdb = TMDb() tmdb.api_key = '9ab4b2025cfde942c159fa3dd7787eba' tmdb.language = 'en' tmdb.debug = 'True' model = load_model('model.h5') # This function will generate movie rating. def getRatingMovie(movieid): total_count = ReviewMovie.objects.filter(movieid=movieid).count() if total_count == 0: return 0 positive_count = ReviewMovie.objects.filter(movieid=movieid).filter(sentiment=1).count() return round((positive_count/total_count)*100, 2) # This function will generate series rating. def getRatingSeries(seriesid): total_count = ReviewSeries.objects.filter(seriesid=seriesid).count() if total_count == 0:
def handle(self, *args, **options): not_added = 0 added = 0 mov_id = 1 user_count = 1 from tmdbv3api import TMDb tmdb = TMDb() tmdb.api_key = '' # api_key tmdb.language = 'en' tmdb.debug = True from tmdbv3api import Movie mov = Movie() #file1 = open('film/management/commands/Attributes_Imdb_test1', 'r') #Lines = file1.readlines() imdb_id_list = [] """ f = open("recommendedfilm") recommend = {} for i in f: l = i.split("\n")[0].split("\t") recommend[l[0]] = eval(l[1]) """ f = open("film/management/commands/watchedfilms") watchedfilms = {} for i in f: l = i.split("\n")[0].split("\t") watchedfilms[l[0]] = eval(l[1]) """ for line in Lines: k = line.split('\t')[0] imdb_id_list.append(k) """ for user_id in watchedfilms.keys(): films = watchedfilms[user_id] user_email = "*****@*****.**" % user_count try: auth_user = User.objects.create_user(username=user_id, email=user_email, password='******') except: my_user = User.objects.get(username=user_id) user_profile = UserProfile.objects.create(user=my_user, spec_id=user_id) printed = 'User ID %d is added' % user_count print(printed) user_count = user_count + 1 for film in films: # film[0] = imdb_id ve film[1] = user_score imdb_id = film[0] user_score = Decimal(film[1]) control_exist = Mov.objects.filter(imdb=imdb_id) if control_exist: my_movie = Mov.objects.get(imdb=imdb_id) score = Score(user=my_user, movie=my_movie, score=user_score) score.save() user_profile.scores.add(score) user_profile.save() else: k = mov.details(imdb_id) try: m = k.poster_path img_path = "https://image.tmdb.org/t/p/w185%s" % m big_img_path = "https://image.tmdb.org/t/p/w500%s" % m except: error_id = "imdb id = %s can not be added" % imdb_id print(error_id) not_added = not_added+1 continue try: p = k.vote_average vote_average = Decimal(p) vote_average = vote_average/2 vote_average = round(vote_average, 1) except: vote_average = Decimal(0.0) genre_list = [] if k.original_title: title = k.original_title if k.overview: overview = k.overview for genre in k.genres: genre_list.append(genre) vid = mov.videos(imdb_id) key = "" if vid: key = vid[0].key yt_url = "https://www.youtube.com/embed/%s" % key rls_date = k.release_date rls_year = k.release_date.split('-')[0] credits = mov.credits(imdb_id) cast_list = [] for c in credits.cast: cast_list.append(c) if cast_list: print(cast_list[0]['name']) for c in cast_list: t = c['profile_path'] c['profile_path'] = "https://image.tmdb.org/t/p/w342%s" % t writer_list = [] director_list = [] for c in credits.crew: if c['department'] == "Writing": writer_list.append(c) if c['department'] == "Directing" and c['job'] == "Director": director_list.append(c) for c in writer_list: t = c['profile_path'] c['profile_path'] = "https://image.tmdb.org/t/p/w342%s" % t for c in director_list: t = c['profile_path'] c['profile_path'] = "https://image.tmdb.org/t/p/w342%s" % t movie = Mov(year=rls_year, date=rls_date, imdb=imdb_id, title=title, topic=overview,poster_url=img_path,poster_big_url=big_img_path, video_url=yt_url, avg_score=vote_average) try: movie.save() except: print("There is invalid field somewhere in movie fields. So this can not be added") not_added = not_added + 1 continue adding_control = "movie_id %d is added" % mov_id print(adding_control) mov_id = mov_id + 1 for i in cast_list: person_query = Person.objects.filter(id_unique = i['id']) if not person_query: person = Person(id_unique=i['id'], name=i['name'], portrait_url=i['profile_path'], type='Star') person.save() movie.starring.add(person) movie.save() else: person = Person.objects.get(id_unique = i['id']) movie.starring.add(person) movie.save() for i in writer_list: person_query = Person.objects.filter(id_unique=i['id']) if not person_query: person = Person(id_unique=i['id'], name=i['name'], portrait_url=i['profile_path'], type='Writer') person.save() movie.writer.add(person) movie.save() else: person = Person.objects.get(id_unique=i['id']) movie.writer.add(person) movie.save() for i in director_list: person_query = Person.objects.filter(id_unique=i['id']) if not person_query: person = Person(id_unique=i['id'], name=i['name'], portrait_url=i['profile_path'], type='Director') person.save() movie.director.add(person) movie.save() else: person = Person.objects.get(id_unique=i['id']) movie.director.add(person) movie.save() for i in genre_list: existing_genre = Genre.objects.filter(name__exact=i['name']) if not existing_genre: genre = Genre(name=i['name']) genre.save() movie.genres.add(genre) movie.save() else: genre = Genre.objects.get(name=i['name']) movie.genres.add(genre) movie.save() score = Score(user=my_user, movie=movie, score=user_score) score.save() user_profile.scores.add(score) user_profile.save() """ if user_count == 6: break """ not_added_result = 'Eklenmeyen sayisi = %d' % not_added print(not_added_result) self.stdout.write(self.style.SUCCESS('Successfully added'))
def initiate_api(api_key): tmdb = TMDb() tmdb.api_key = api_key tmdb.language = 'en' tmdb.debug = True
from tmdbv3api import TMDb, Movie, Discover, Search, TV from app.modules import load # ### Settings tmdb = TMDb() tmdb.api_key = load._cfg['extension']['tmdb']['API_TOKEN'] tmdb.language = 'zh-CN' tmdb.debug = False movie = Movie() discover = Discover() search = Search() tv = TV() # ### Movies def search_movie_by_title(query): result_movie = movie.search(query) return result_movie def search_movies(query, year): result_movie = search.movies({"query": query, "year": year}) return result_movie # ### TMDb_ID def search_movie_details(query):
def ready(self): tmdb = TMDb() tmdb.api_key = env('TMDB_API_KEY') tmdb.language = 'en' tmdb.debug = True
ch.setFormatter(formatter) fh.setFormatter(formatter) # add handlers to logger LOGGER.addHandler(ch) LOGGER.addHandler(fh) # start of logging session LOGGER.info("{} - TMDB_fetcher.py - {} - by C.Mineau".format( datetime.datetime.now(), VERSION)) if CLEANUP: doCleanup(DIRPATH) else: TMDB.api_key = KEY TMDB.language = 'fr' TMDB.debug = False MOVIE_CATALOG = os.path.join(DIRPATH, CATALOG) MOVIE_SHEETS = os.path.join(DIRPATH, SHEETS) movieDB = MovieDB(DIRPATH) if FILE: # Only one file has to be handled, no need to walk through everything filename = os.path.basename(FILE) dirpath = os.path.dirname(FILE) if os.path.isfile(FILE) and Film.isMovie(filename, dirpath): movieDB.handleMovie(FILE, dontKeepIfExist=True) movieDB.updateCatalog() movieDB.updateMovieNotesFile() else: LOGGER.error(