def get_movie_ids(name): # check for IMDB URL url_split = name.split('https://www.imdb.com/title/') if len(url_split) == 2: return {'included': [url_split[1].split('/')[0]], 'excluded': []} # otherwise use name year = re.search(' \((\d{4})\)$', name) if year: name = name[:len(name) - 7] year = year[1] name = name.rsplit(', The')[0].rsplit(', A')[0].lower().replace( ',', '').replace(':', '') movies = omdb.search_movie( name, year=int(year)) if year else omdb.search_movie(name) return { # TODO: the included/excluded comprehensions have overgrown; refactor to be more streamlined 'included': [ movie['imdb_id'] for movie in movies if movie['title'].lower().replace(',', '').replace(':', '') == name or movie['title'].lower().replace(',', '').replace( ':', '') == "a " + name or movie['title'].lower().replace( ',', '').replace(':', '') == "the " + name ], 'excluded': [ movie['imdb_id'] for movie in movies if movie['title'].lower().replace(',', '').replace(':', '') != name and movie['title'].lower().replace(',', '').replace( ':', '') != "a " + name and movie['title'].lower().replace( ',', '').replace(':', '') != "the " + name ] }
def test_search_movie(self): t = 'True Grit' media_type = 'movie' self.assertEqual(omdb.search_movie(t)[0].type, media_type) self.assertEqual( omdb.get(title=t, media_type=media_type).type, media_type)
def add_dvd(request): # This is a form, with an input box or two. # Should trigger some omdb stuff and fill in the database if request.method == 'POST': form = DvDForm(request.POST, user=request.user) if form.is_valid(): name = form.cleaned_data['name'] year = form.cleaned_data['year'] dvd_location = form.cleaned_data['location'] type = form.cleaned_data['type'] omdb.set_default('apikey', api_key) if type == 'film': possible_dvds = omdb.search_movie(name, year=year) request.session['is_series'] = False else: possible_dvds = omdb.search_series(name, year=year) request.session['is_series'] = True request.session['possible_dvds'] = possible_dvds request.session['dvd_location'] = dvd_location.id # this is a list of dictionaries with films matching the search. # want to display the possibilities to the user. # user then picks which one is right, and a further call to the omdb api # gets the rest of the data. return redirect('confirm_dvd') else: # display the form form = DvDForm(user=request.user) return render(request, 'dvds/add_dvd.html', {'form': form})
async def imdb(ctx, *movie_full_name): movie = '' if len(movie_full_name) > 1: for element in movie_full_name: movie = movie + element + ' ' else: movie = movie_full_name[0] info = omdb.search_movie(movie_full_name) if len(info) > 0: info = omdb.imdbid(info[0]['imdb_id']) else: await ctx.send('No results found') return embed = discord.Embed(title=info['title'], description=info['plot'], colour=discord.Colour.blue()) embed.set_footer(text='A ' + info['production'] + ' production') embed.set_image(url=info['poster']) embed.add_field(name="Release Date", value=info['released'], inline=False) embed.add_field(name="Director(s)", value=info['director'], inline=False) embed.add_field(name="MetaScore", value=info['metascore'], inline=True) embed.add_field(name="IMDB Score", value=info['imdb_rating'], inline=True) await ctx.send(embed=embed)
def search(request): if request.method == 'POST': returned_values = omdb.search_movie(request.POST['movie_title']) return render(request, 'movies/search.html', {'movie_results': returned_values}) return render(request, 'movies/search.html')
def test_search_movie(self): t = 'True Grit' media_type = 'movie' self.assertEqual(omdb.search_movie(t)[0].type, media_type) self.assertEqual(omdb.get(title=t, media_type=media_type).type, media_type)
def test_search_movie(): t = 'True Grit' media_type = 'movie' results = omdb.search_movie(t) assert results[0]['type'] == media_type result = omdb.get(title=t, media_type=media_type) assert result['type'] == media_type
def result(query): '''Request the user search to OMDB API to render results''' data_request = omdb.search_movie(query, page=1) if data_request: return render_template("results.html", data_request=data_request, query=query) else: return render_template("no_results.html")
def search_movie(request, movie_name): movie = omdb.search_movie(movie_name) list = [] for i in movie: list.append(i['title']) list.append(i['year']) list.append(i['poster']) list.append(i['imdb_id']) return JsonResponse(list, safe=False)
def textMessage(bot, update): ls = omdb.search_movie(update.message.text) response = 'Привет.Вот держи список.\n' if len(ls) != 0: for i in ls: response += i['title'] + '\n' bot.send_message(chat_id=update.message.chat_id, text=response) else: response = 'ничего не найдено:(' bot.send_message(chat_id=update.message.chat_id, text=response)
def process_search(): ''' Handle a search Request; This takes in a movie title via a client request and returns the panel containing a list of matching films. ''' movie = request.get_json() title = movie['title'] searchResults = omdb.search_movie(title) return render_template("search_results.html", searchList=searchResults)
def index(request): movies = omdb.search_movie('true') if request.method == 'POST': form = SearchForm(request.POST) if form.is_valid(): movies = movie_api(form) else: form = SearchForm() return render(request,'index.html', {'form': form, 'movies': movies })
def get_poster(movie: str): # Set OMDB API key omdb.set_default("apikey", "1454b6c1") movies_list = omdb.search_movie(movie) # Get poster if len(movies_list) != 0: poster = movies_list[0]["poster"] return poster else: return None
def movie_api(form): title = form.cleaned_data['title'] year = form.cleaned_data['year'] genre = form.cleaned_data['genre'] if title: if year: movie = [] movie.append(omdb.get(title=title, year=year)) return movie else: return omdb.search_movie(title)
def year(filename): ret = None title_search = omdb.title(filename) if len(title_search) > 0: ret = title_search['year'] else: movie_search = omdb.search_movie(filename) if len(movie_search) > 0: ret = movie_search[0]['year'] else: print('Could not find year for "{0}"'.format(filename)) return ret
def search(self, input): results = {} cp = couchpotato() for i in omdb.search_movie(input): cp_data = json.loads(cp.get('media.get', id=i['imdb_id'])) if cp_data['success'] is True: status = cp_data['media']['status'] if status == 'done': result = 'exists' elif status == 'active': result = 'wishlist' elif cp_data['success'] is False: result = 'available' results[i['imdb_id']] = [i['title'], i['year'], i['type'], result] return results
def handle_data(): try: movieChoice = request.form["projectFilePath"] movieChoice = movieChoice.upper() movieInfo = omdb.search_movie(movieChoice) raw = movieInfo[0] for i in raw: raw[i].split(" ") noPunc = raw[i].translate( str.maketrans(".,;!£$%^&*()'", ' ', string.punctuation)) if noPunc.upper() == movieChoice or raw[i].upper() == movieChoice: movieChoice = raw[i] mining(movieChoice) metaData = getMovieMeta(movieChoice) genreSplit = metaData[6].split(",") genre = genreSplit[0] return render_template("displayMovie.html", movieName=movieChoice, timeYear=metaData[2], img=metaData[3], rating=metaData[4], plot=metaData[5], genre=genre, imdb=metaData[7], metacritic=metaData[8], movieTotal=metaData[9]) else: return render_template( "Main.html", error="This movie does not exist, try again.") except werkzeug.exceptions.BadRequestKeyError: return redirect(url_for("main")) except IndexError: return render_template("Main.html", error="This movie does not exist, try again.") except KeyError: return redirect(url_for("main")) except tweepy.TweepError: return render_template( "Main.html", error="An Error occured, Keys have been revoked.")
def get_in_theaters_movies_list(): movies = [] for cinemark_movie in xml['cinemark']['programacao']['filmes']['filme']: movie_entry = {} movie_entry['title'] = cinemark_movie['titulo_original'] movie_entry['title_br'] = cinemark_movie['titulo_portugues'] imdb_search = omdb.search_movie(movie_entry['title']) if imdb_search: imdb_movie = omdb.get(title = imdb_search[0].title, tomatoes = True) if imdb_movie: movie_entry['poster'] = imdb_movie.poster movie_entry['genre'] = imdb_movie.genre movie_entry['awards'] = imdb_movie.awards movie_entry['runtime'] = imdb_movie.runtime movie_entry['metascore'] = imdb_movie.metascore movie_entry['imdb_rating'] = imdb_movie.imdb_rating movie_entry['tomato_rating'] = imdb_movie.tomato_rating movies.append(movie_entry) return movies
def give_some_information(self): self.assistant.say("which movie would you like to know about?") movie_name = self.assistant.listen().decipher() movies = omdb.search_movie(movie_name) if len(movies) > 0: movies.sort(key=lambda x: x.year, reverse=True) for i in range(0, len(movies)): if i == 0: speech = "Is the movie you're referring to is %s, released in %s" % ( movies[i].title, movies[i].year) else: speech = "Alright, then how about %s, released in %s" % ( movies[i].title, movies[i].year) self.assistant.say(speech) response = self.assistant.listen().decipher() if len(response.split()) > 3: return "Alright dude, you are kind of moody." elif response == "yes": imdb_id = movies[i].imdb_id print("found") return self.give_movie_information_from_imdb_id(imdb_id) else: return "Sorry, but your pronounciation is awful. Try again"
def search_movies(): search_string = "" response = [] print "hello" if request.args and request.args.get("s"): search_string = request.args.get("s") auto_store = request.args.get("auto_store") result = omdb.search_movie(search_string) for movie in result: try: print movie.title movie["_id"] = movie["imdb_id"] if movie["poster"].endswith(".jpg"): response.append(movie) alreadyExists = mydb.movies.find({"_id": movie["imdb_id"]}) alreadyExists = count_iterable(alreadyExists) > 0 if (not alreadyExists and auto_store == "1"): print "going to save a movie " + movie["_id"] movieInfo = omdb.imdbid(movie["_id"]) movieInfo["_id"] = movieInfo["imdb_id"] movieInfo["time_stamp"] = datetime.datetime.now( ).isoformat() mydb.movies.insert_one(movieInfo) print movieInfo.title + " Inserted!" calculate_movies_count() if alreadyExists: movie.stored = "true" else: movie.stored = "false" except Exception as e: print "Exception has occured" print str(e) return jsonify(response)
import omdb import sys import do_what_it_says as comp_choice from dotenv import load_dotenv load_dotenv() COMMAND_1 = '1: spotify-this-song' COMMAND_2 = '2: movie-this' COMMAND_3 = '3: do-what-it-says' COMMAND_4 = 'Q: Quit' question = [ inquirer.List('command', message="Enter command", choices=[COMMAND_1, COMMAND_2, COMMAND_3, COMMAND_4]) ] while True: answers = inquirer.prompt(question) command = answers['command'] if answers["command"] == COMMAND_1 or answers["command"] == COMMAND_2: search_text = input("[?] Enter search text: ") if command == COMMAND_1: spotify.search_song(search_text) elif command == COMMAND_2: omdb.search_movie(search_text) elif command == COMMAND_3: comp_choice.get_result() elif command == COMMAND_4: break
def scrape_movie(url): soup=BeautifulSoup(requests.session().get(url).text, "lxml") #Scrape Movie Title & Release Date title=soup.find("title").text title=title.split("(")[0].strip() release_date=scrape_value(soup, "Release Date:") #Convert Release Date to Python Datetime Object and Derive Release Month and Year release_date=parse(release_date) release_month=release_date.month release_year=release_date.year #Scrape Genre, Rating, Runtime, and Budget genre=scrape_value(soup, "Genre:") rating=scrape_value(soup, "Rating:") runtime=scrape_value(soup, "Runtime:") budget=scrape_value(soup, "Production Budget:") #Clean-Up Runtime and Budget runtime=clean_runtime(runtime) budget=clean_budget(budget) budget=inflation_adjust(release_year, budget) #Scrape Number of Oscar Noms, Number Oscar Wins, and List of Oscar Nominations url=url.replace("/movies/","/oscar/movies/") soup=BeautifulSoup(requests.session().get(url).text, "lxml") oscar_links=soup.find_all("a", href=True) oscar_noms=0 oscar_wins=0 oscar_list=[] for link in soup.find_all("a", href=True): if link["href"].find("oscar/chart/")>0: oscar=str(link.contents[0].encode('utf-8')) if re.search("View All", oscar.title())==None: oscar_noms+=1 if re.search("(WIN)", oscar.upper())>0: oscar_wins+=1 oscar_list.append(oscar) #Pull in Rotten Tomato Ratings & Plot Description from OMDB API search_results=omdb.search_movie(title) imdb_id=None for result in search_results: if int(result["year"])==release_year: imdb_id=result["imdb_id"] break if imdb_id != None: omdb_content=omdb.imdbid(imdb_id, tomatoes=True) metascore=omdb_content["metascore"] imdb_rating=omdb_content["imdb_rating"] tomato_meter=omdb_content["tomato_meter"] tomato_user_meter=omdb_content["tomato_user_meter"] plot=omdb_content["plot"] else: metascore=None imdb_rating=None tomato_meter=None tomato_user_meter=None plot=None #Store Data for One movie in dictionary keys=["title","release_date","release_year","genre","rating","runtime","budget","imdb_id","metascore","imdb_rating","tomato_meter","tomato_user_meter","plot","oscar_noms","oscar_wins"] values=[title,release_date,release_year,genre,rating,runtime,budget,imdb_id,metascore,imdb_rating,tomato_meter,tomato_user_meter,plot,oscar_noms,oscar_wins] d=dict(zip(keys,values)) return d
def com_omdb_search_movie(self, media_title): """ Search movie """ omdb.search_movie(media_title)
def scrape_movie(url): soup = BeautifulSoup(requests.session().get(url).text, "lxml") #Scrape Movie Title & Release Date title = soup.find("title").text title = title.split("(")[0].strip() release_date = scrape_value(soup, "Release Date:") #Convert Release Date to Python Datetime Object and Derive Release Month and Year release_date = parse(release_date) release_month = release_date.month release_year = release_date.year #Scrape Genre, Rating, Runtime, and Budget genre = scrape_value(soup, "Genre:") rating = scrape_value(soup, "Rating:") runtime = scrape_value(soup, "Runtime:") budget = scrape_value(soup, "Production Budget:") #Clean-Up Runtime and Budget runtime = clean_runtime(runtime) budget = clean_budget(budget) budget = inflation_adjust(release_year, budget) #Scrape Number of Oscar Noms, Number Oscar Wins, and List of Oscar Nominations url = url.replace("/movies/", "/oscar/movies/") soup = BeautifulSoup(requests.session().get(url).text, "lxml") oscar_links = soup.find_all("a", href=True) oscar_noms = 0 oscar_wins = 0 oscar_list = [] for link in soup.find_all("a", href=True): if link["href"].find("oscar/chart/") > 0: oscar = str(link.contents[0].encode('utf-8')) if re.search("View All", oscar.title()) == None: oscar_noms += 1 if re.search("(WIN)", oscar.upper()) > 0: oscar_wins += 1 oscar_list.append(oscar) #Pull in Rotten Tomato Ratings & Plot Description from OMDB API search_results = omdb.search_movie(title) imdb_id = None for result in search_results: if int(result["year"]) == release_year: imdb_id = result["imdb_id"] break if imdb_id != None: omdb_content = omdb.imdbid(imdb_id, tomatoes=True) metascore = omdb_content["metascore"] imdb_rating = omdb_content["imdb_rating"] tomato_meter = omdb_content["tomato_meter"] tomato_user_meter = omdb_content["tomato_user_meter"] plot = omdb_content["plot"] else: metascore = None imdb_rating = None tomato_meter = None tomato_user_meter = None plot = None #Store Data for One movie in dictionary keys = [ "title", "release_date", "release_year", "genre", "rating", "runtime", "budget", "imdb_id", "metascore", "imdb_rating", "tomato_meter", "tomato_user_meter", "plot", "oscar_noms", "oscar_wins" ] values = [ title, release_date, release_year, genre, rating, runtime, budget, imdb_id, metascore, imdb_rating, tomato_meter, tomato_user_meter, plot, oscar_noms, oscar_wins ] d = dict(zip(keys, values)) return d
def search_movies(title): return omdb.search_movie(title)