from flask import Blueprint, render_template, request, make_response, send_file, send_from_directory from flask_login import login_required from urllib import parse from io import BytesIO from wand.image import Image import os, pytz, datetime from scripts import database, func Movies = Blueprint("movies", __name__, template_folder="templates") @Movies.route("/movies") @login_required def index(): return render_template("movies/index.html", title="Movies", movies=database.db_get_all_movies()) @Movies.route("/movies/") @login_required def movie_view(imdb_id): try: movie_data = database.db_get_movie_by_imdb_id(imdb_id) return render_template("movies/movieViewer.html", title="Movies: " + movie_data["title"], movie=movie_data) except Exception as e: print(e) return str(e) @Movies.route("/movies//extended") @login_required def movie_view_extended(imdb_id): try: movie_data = database.db_get_movie_by_imdb_id(imdb_id, extended=1) return render_template("movies/movieViewer.html", title="Movies: " + movie_data["title"], movie=movie_data) except Exception as e: print(e) return str(e) @Movies.route("/movies//directors_cut") @login_required def movie_view_directors_cut(imdb_id): try: movie_data = database.db_get_movie_by_imdb_id(imdb_id, directors_cut=1) return render_template("movies/movieViewer.html", title="Movies: " + movie_data["title"], movie=movie_data) except Exception as e: print(e) return str(e) @Movies.route("/movies/get_movie/") @login_required def get_movie(imdb_id): movie_data = database.db_get_movie_by_imdb_id(imdb_id) filename = movie_data["title"]+" ("+str(movie_data["year"])+").mkv" response = make_response(send_from_directory(func.MOVIES_DIRECTORY, filename)) response.headers["content-type"] = "video/webm" return response @Movies.route("/movies/get_movie//extended") @login_required def get_movie_extended(imdb_id): movie_data = database.db_get_movie_by_imdb_id(imdb_id, extended=1) filename = movie_data["title"]+" ("+str(movie_data["year"])+").mkv" response = make_response(send_from_directory(func.MOVIES_DIRECTORY, filename)) response.headers["content-type"] = "video/webm" return response @Movies.route("/movies/get_movie//directors_cut") @login_required def get_movie_directors_cut(imdb_id): movie_data = database.db_get_movie_by_imdb_id(imdb_id, directors_cut=1) filename = movie_data["title"]+" ("+str(movie_data["year"])+").mkv" response = make_response(send_from_directory(func.MOVIES_DIRECTORY, filename)) response.headers["content-type"] = "video/webm" return response