def getmovies(): name = User.get_by_email(session['email']).name searchlist = [] query = request.form['search'] movies = Movie.get_all_movies() for m in movies: if search(query, m.title): print(m.title) searchlist.append(m) request1 = youtube.search().list(part="snippet", maxResults=5, q=query + "movie trailer", topicId="/m/02vxn", regionCode="US") responselist = request1.execute() responselist1 = responselist["items"] print(responselist1) for response in responselist1: try: videoId = response["id"]["videoId"] except: print("something went wrong") videoId = None title = response["snippet"]["title"] poster = response["snippet"]["thumbnails"]["high"]["url"] if videoId != None and poster != None and title != None: link = "https://www.youtube.com/watch?v=" + videoId movie = Movie(title, "search", "search", "", poster, link) searchlist.append(movie) return render_template("search.html", movies=searchlist, name=name)
def profile(): user = User.get_by_email(session['email']) name = user.name movieslist = Movie.movieAI(user._id) random.shuffle(movieslist) m = movieslist[0] return render_template("main.html", name=name, m=m)
def unlike(movieid): user = User.get_by_email(session['email']) userunliked = user.getunliked() for u in userunliked: if u["_id"] == movieid: print("already added to unliked") return redirect("/profile") user.addtounliked(movieid) return redirect("/profile")
def add_to_unwatched(movieid): user = User.get_by_email(session['email']) userunwatched = user.getunwatched() for u in userunwatched: if u["_id"] == movieid: print("already added to favourites") return redirect("/profile") user.addtounwatched(movieid) return redirect("/profile")
def add_to_favourites(movieid): user = User.get_by_email(session['email']) userfavourites = user.getfavourites() for u in userfavourites: if u["_id"] == movieid: print("already added to favourites") return redirect("/profile") user.addtofavorites(movieid) return redirect("/profile")
def getunwatchedcache(): user = User.get_by_email(session['email']) userunwatched = user.getunwatched() return userunwatched
def getlikedcache(): user = User.get_by_email(session['email']) userliked = user.getliked() return userliked
def getfavcache(): user = User.get_by_email(session['email']) userfavourites = user.getfavourites() return userfavourites
def getbolly(): user = User.get_by_email(session['email']) name = user.name movies = Movie.get_bollywood() return render_template("bollywood.html", movies=movies, name=name)
def gettopmovies(): user = User.get_by_email(session['email']) movies = Movie.get_topmovies() name = user.name return render_template("topmovies.html", movies=movies, name=name)
def getunwatched(): user = User.get_by_email(session['email']) name = user.name userunwatched = getunwatchedcache() print(userunwatched) return render_template("unwatched.html", movies=userunwatched, name=name)
def getliked(): user = User.get_by_email(session['email']) name = user.name userliked = getlikedcache() return render_template("liked.html", movies=userliked, name=name)
def getfavourites(): user = User.get_by_email(session['email']) name = user.name userfavourites = getfavcache() return render_template("favourites.html", movies=userfavourites, name=name)