def title_genres(imdb_id): """return title genre(s)""" # check if valid imdb_id if valid_id(imdb_id): try: # get genre list genres = imdb.get_title_genres(imdb_id)["genres"] s = '' # turn list in string for genre in genres: if not s: s = s + genre else: s = s + ", " + genre return s except: return "Sorry, no genre(s) found!" else: return False
def title_summary(imdb_id): """return title summary""" # check if valid imdb_id if valid_id(imdb_id): try: plot_summary = imdb.get_title_plot(imdb_id) # if there are no summaries return short plot if plot_summary["totalSummaries"] == 0: # if there are no summaries put outline in dic return plot_summary["outline"]['text'] # check if there are summaries else: # put summary in dic return plot_summary["summaries"][0]['text'] # notify user that no plot is found except: return "Sorry, no plot found!" else: return False
def title_poster(imdb_id, check=0): """return title poster""" # check if valid imdb_id if valid_id(imdb_id): # prevent searching in the same database if check == 0: # check if there is a poster try: return imdb.get_title(imdb_id)["base"]["image"]['url'] # if there is no poster try to find image except: try: return ( imdb.get_title_images(imdb_id)['images'][0]['url']) # if there is no image return image not found image except: return "http://www.gentsbierfestival.be/sites/default/files/default_images/notfound.jpg" # do not search in imdb_get_title if check == 1: try: return (imdb.get_title_images(imdb_id)['images'][0]['url']) # if there is no image return image not found image except: return "http://www.gentsbierfestival.be/sites/default/files/default_images/notfound.jpg" else: return False
def title_name(imdb_id): """return title name""" # check if valid imdb_id if valid_id(imdb_id): return imdb.get_title(imdb_id)["base"]['title'] else: return False
def title_year(imdb_id): """return title year""" # check if valid imdb_id if valid_id(imdb_id): try: return imdb.get_title(imdb_id)["base"]['year'] except: return "Sorry, no year found!" else: return False
def title_rating(imdb_id): """return title rating""" # check if valid imdb_id if valid_id(imdb_id): try: return imdb.get_title_ratings(imdb_id)["rating"] except: return "Sorry, no rating found!" else: return False
def title_info(imdb_id): """Returns list of dics of all possible title info""" # check if valid imdb_id if valid_id(imdb_id): full_movie_info = {} # get title information title_info_id = imdb.get_title(imdb_id) # put imdb_id in in dic full_movie_info["imdb_id"] = imdb_id # put movie title in dic full_movie_info["title"] = title_info_id["base"]['title'] # try to put movie year in dic try: full_movie_info["year"] = title_info_id["base"]['year'] except: full_movie_info["year"] = "Sorry, no year found!" # try to find movie poster try: # put a movie image in the dic full_movie_info["image"] = title_info_id["base"]["image"][ 'url'] except: # try to find related image else put image not found image in dic full_movie_info["image"] = Search.title_poster(imdb_id, check=1) # try to find a summary else put outline in dic full_movie_info["plot"] = Search.title_summary(imdb_id) # try to get genre list full_movie_info["genre"] = Search.title_genres(imdb_id) # try to get movie rating full_movie_info["rating"] = Search.title_rating(imdb_id) return full_movie_info else: return False
def search_titles(to_search): """return list of dics with searched title and info""" # request title, year, imdb_id in dictionary title_results = imdb.search_for_title(to_search) all_movie_info = [] # put title, image, year and short discription in list for i in range(len(title_results)): movie_info = {} # look for information in database info_database = db.execute( "SELECT * FROM films WHERE film_id = :film_id", film_id=title_results[i]["imdb_id"]) if info_database: # extract dic from one list movie_info = info_database[0] # change film_id to imdb_id and summary to short plot movie_info['imdb_id'] = movie_info.pop("film_id") movie_info['short plot'] = movie_info.pop("summary") # put the movie_info in a list all_movie_info.append(movie_info) # do if imdb_id exist and movie not in database elif valid_id(title_results[i]["imdb_id"]): title_info = imdb.get_title(title_results[i]["imdb_id"]) # put movie imdb_id in list movie_info["imdb_id"] = title_results[i]["imdb_id"] # put movie title in list movie_info["title"] = title_results[i]["title"] # try to find year in searched dic try: # put movie year in list movie_info["year"] = title_results[i]["year"] # change none to could not find if movie_info["year"] == None: movie_info["year"] = "Sorry, no year found!" except: # try to find year from other dic try: movie_info["year"] = Search.title_year( title_results[i]["imdb_id"]) # put notification that nothings is found in dic except: movie_info["year"] = "Sorry, no year found!" # try to find movie poster try: # put a movie image in the list movie_info["image"] = title_info["base"]["image"]['url'] except: # try to find related image else put image not found image in dic movie_info["image"] = Search.title_poster( title_results[i]["imdb_id"], check=1) # try to find a short plot try: # put short plot in dic movie_info["short plot"] = title_info["plot"]["outline"][ "text"] except: # try to find a summary try: # put summary in dic movie_info["short plot"] = Search.title_summary( title_results[i]["imdb_id"]) except: # put in dic a notification that nothing is found movie_info["short plot"] = "Sorry, no plot found!" # put the movie_info in a list all_movie_info.append(movie_info) return all_movie_info