Added initial implementation of user data for tv shows and movies as well as OAuth for Google sign in.
115 lines
4.4 KiB
Python
115 lines
4.4 KiB
Python
from flask import Blueprint, render_template, request, make_response, send_from_directory, current_app
|
|
from flask_login import login_required
|
|
import inspect
|
|
|
|
from scripts import database, func
|
|
|
|
Movies = Blueprint("movies", __name__, template_folder="templates")
|
|
|
|
|
|
@Movies.route("/movies")
|
|
@login_required
|
|
def index():
|
|
try:
|
|
page = request.args.get("page", 1, type=int)
|
|
max_items = request.args.get("max_items", 30, type=int)
|
|
movies = database.db_get_all_movies()
|
|
start = (max_items*(page-1))
|
|
end = len(movies) if len(movies) < max_items*page else max_items*page
|
|
return render_template("movies/index.html", title="Movies", movies=movies, page=page, max_items=max_items, start=start, end=end, item_count=len(movies))
|
|
except Exception as e:
|
|
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
|
return str(type(e)) + " " + str(e)
|
|
|
|
|
|
@Movies.route("/movies/search")
|
|
@login_required
|
|
def search():
|
|
try:
|
|
page = request.args.get("page", 1, type=int)
|
|
max_items = request.args.get("max_items", 30, type=int)
|
|
start = 0
|
|
end = 0
|
|
query = request.args.get("q")
|
|
results = []
|
|
if query:
|
|
results = database.db_search_movies(query)
|
|
start = (max_items*(page-1))
|
|
end = len(results) if len(results) < max_items*page else max_items*page
|
|
return render_template("movies/search.html", title="Movies", movies=results, page=page, max_items=max_items, start=start, end=end, item_count=len(results))
|
|
except Exception as e:
|
|
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
|
return str(type(e)) + " " + str(e)
|
|
|
|
|
|
@Movies.route("/movies/<imdb_id>", methods=["GET", "POST"])
|
|
@login_required
|
|
def movie_view(imdb_id):
|
|
try:
|
|
if request.method == "POST":
|
|
time = int(request.args.get("time", type=float))
|
|
length = int(request.args.get("length", type=float, default=0))
|
|
database.update_user_tv_movie_data(imdb_id, None, time, 0, True if length-time <= 15 else False)
|
|
return make_response("", 201)
|
|
else:
|
|
movie_data = database.db_get_movie_by_imdb_id(imdb_id)
|
|
user_data = database.db_get_user_tv_movie_data(movie_data.imdb_id)
|
|
if not user_data:
|
|
user_data = database.update_user_tv_movie_data(movie_data.imdb_id, None, 0, 0)
|
|
return render_template("movies/movieViewer.html", title="Movies: " + movie_data.title, movie=movie_data, user_data=user_data)
|
|
except Exception as e:
|
|
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
|
return str(type(e)) + " " + str(e)
|
|
|
|
|
|
@Movies.route("/movies/<imdb_id>/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:
|
|
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
|
return str(type(e)) + " " + str(e)
|
|
|
|
|
|
@Movies.route("/movies/<imdb_id>/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:
|
|
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
|
return str(type(e)) + " " + str(e)
|
|
|
|
|
|
@Movies.route("/movies/get_movie/<imdb_id>")
|
|
@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/<imdb_id>/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/<imdb_id>/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
|