Move some files out of scripts folder

Change error logging to log messages as error rather than info
Add 404 error when video or comic not found
Change paths to use pathlib
This commit is contained in:
Matthew Welch 2021-07-10 13:17:28 -07:00
parent bb697eb320
commit c4e6824a8a
10 changed files with 179 additions and 167 deletions

View File

@ -8,7 +8,8 @@ import pytz
from flask import Blueprint, current_app, make_response, render_template, request
from flask_login import login_required
from scripts import database, func
import func
import database
Comics = Blueprint("comics", __name__, template_folder="templates")
@ -35,7 +36,7 @@ def index():
item_count=len(publishers),
)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -92,7 +93,7 @@ def search():
comics_end=comics_end,
)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -149,7 +150,7 @@ def comics_publisher(publisher):
item_count=len(publisher_series),
)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -176,7 +177,7 @@ def comic_gallery(comic_id):
item_count=meta.pagecount,
)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -184,6 +185,8 @@ def comic_gallery(comic_id):
@login_required
def get_comic_page(comic_id, page_number):
meta = database.db_get_comic_by_id(comic_id)
if not os.path.exists(meta.path):
return "File not found", 404
comic = func.open_comic(meta.path)
byte_image = comic.getPage(page_number)
type = filetype.guess(byte_image).mime
@ -205,8 +208,9 @@ def get_comic_thumbnail(comic_id, page_number):
thumb = database.db_get_thumbnail_by_id_page(comic_id, page_number)
response = make_response(thumb.image)
response.headers["cache-control"] = "public"
date = pytz.utc.localize(datetime.datetime.utcfromtimestamp(os.path.getmtime(meta.path)))
response.headers["last-modified"] = date.strftime("%a, %d %b %Y %H:%M:%S %Z")
if os.path.exists(meta.path):
date = pytz.utc.localize(datetime.datetime.utcfromtimestamp(os.path.getmtime(meta.path)))
response.headers["last-modified"] = date.strftime("%a, %d %b %Y %H:%M:%S %Z")
response.headers["content-type"] = thumb.type
response.headers["Content-Disposition"] = 'attachment; filename="{} {}_{}_thumbnail"'.format(str(meta.series), meta.issuetext, str(page_number))
response.headers["Content-Disposition"] = 'filename="{} {}_{}_thumbnail"'.format(str(meta.series), meta.issuetext, str(page_number))
return response

View File

@ -76,7 +76,7 @@ class Comic(Base):
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "Comic" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "Comic" + " " + str(type(e)) + " " + str(e))
def __repr__(self):
return "<Comic: {series} {issue}>".format(series=self.series, issue=self.issuetext)
@ -100,7 +100,7 @@ class ComicThumbnail(Base):
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "ComicThumbnail" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "ComicThumbnail" + " " + str(type(e)) + " " + str(e))
class Movie(Base):
@ -124,7 +124,7 @@ class Movie(Base):
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "Movie" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "Movie" + " " + str(type(e)) + " " + str(e))
class TvShow(Base):
@ -144,7 +144,7 @@ class TvShow(Base):
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "TvShow" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "TvShow" + " " + str(type(e)) + " " + str(e))
class TvEpisode(Base):
@ -166,7 +166,7 @@ class TvEpisode(Base):
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "TvEpisode" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "TvEpisode" + " " + str(type(e)) + " " + str(e))
class DupComic(Base):
@ -219,7 +219,7 @@ class DupComic(Base):
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "DupComic" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "DupComic" + " " + str(type(e)) + " " + str(e))
class Game(Base):
@ -242,7 +242,7 @@ class Game(Base):
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "Game" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "Game" + " " + str(type(e)) + " " + str(e))
class User(Base, UserMixin):
@ -262,7 +262,7 @@ class User(Base, UserMixin):
i += 1
pass
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "User" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "User" + " " + str(type(e)) + " " + str(e))
def get_id(self):
return self.email
@ -297,7 +297,7 @@ class UserTvMovieData(Base):
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "UserTvMovieData" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "UserTvMovieData" + " " + str(type(e)) + " " + str(e))
class TvMovieKeywords(Base):
@ -319,7 +319,7 @@ class TvMovieKeywords(Base):
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + "TvMovieKeywords" + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + "TvMovieKeywords" + " " + str(type(e)) + " " + str(e))
Base.metadata.create_all(engine)
@ -340,7 +340,7 @@ Base.metadata.create_all(engine)
setattr(self, column.name, data[i])
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))"""
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))"""
# def get_db():
@ -415,7 +415,7 @@ def add_tv_shows(tv_show_data):
session.add(tv_show)
session.commit()
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def add_tv_episodes(episodes):
@ -429,7 +429,7 @@ def add_tv_episodes(episodes):
else:
current_app.logger.info(f"TV episode: The TMDB id {episode.tmdb_id} for {episode.path} is already in the database.")
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def add_comics(meta, thumbnails):
@ -587,8 +587,8 @@ def comic_path_in_db(path):
if result or result2:
return True
except Exception as e:
current_app.logger.info(path)
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(path)
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return False
@ -599,8 +599,8 @@ def movie_path_in_db(path):
if result:
return True
except Exception as e:
current_app.logger.info(path)
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(path)
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return False
@ -611,8 +611,8 @@ def tv_show_path_in_db(path):
if result:
return True
except Exception as e:
current_app.logger.info(path)
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(path)
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return False
@ -623,8 +623,8 @@ def tv_episode_path_in_db(path):
if result:
return True
except Exception as e:
current_app.logger.info(path)
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(path)
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return False
@ -635,7 +635,7 @@ def game_in_db(game_id):
if result:
return True
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return False
@ -978,4 +978,4 @@ def get_user(email):
return result
return None
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))

View File

@ -4,7 +4,6 @@ import os
import pathlib
import re
from datetime import timedelta
from io import BytesIO
import enzyme
import requests
@ -13,7 +12,7 @@ from comicapi import comicarchive
from flask import current_app
from wand.image import Image
from scripts import database
import database
rpi_signals = Namespace()
comic_loaded = rpi_signals.signal("comic-loaded")
@ -28,22 +27,10 @@ API_KEY = "***REMOVED***"
# Directories
RPI_COMICS_DIRECTORY = "/usb/storage/media/Comics/"
RPI_MOVIES_DIRECTORY = "/usb/storage/media/Videos/Movies/"
RPI_TV_SHOWS_DIRECTORY = "/usb/storage/media/Videos/TV/"
RPI_VIDEOS_DIRECTORY = "/usb/storage/media/Videos/Videos/"
RPI_GAMES_DIRECTORY = "/usb/storage/Games/"
RPI_MUSIC_DIRECTORY = "/usb/storage/media/Music/"
MC_COMICS_DIRECTORY = "/mnt/c/Users/Matthew/Documents/Comics/"
MC_MOVIES_DIRECTORY = "/mnt/c/Users/Matthew/Documents/Movies/"
MC_TV_SHOWS_DIRECTORY = "/mnt/c/Users/Matthew/Documents/TV/"
MC_GAMES_DIRECTORY = "/mnt/g/Humble Bundle/rpi/"
COMICS_DIRECTORY = RPI_COMICS_DIRECTORY if os.path.exists(RPI_COMICS_DIRECTORY) else MC_COMICS_DIRECTORY
MOVIES_DIRECTORY = RPI_MOVIES_DIRECTORY if os.path.exists(RPI_MOVIES_DIRECTORY) else MC_MOVIES_DIRECTORY
TV_SHOWS_DIRECTORY = RPI_TV_SHOWS_DIRECTORY if os.path.exists(RPI_TV_SHOWS_DIRECTORY) else MC_TV_SHOWS_DIRECTORY
GAMES_DIRECTORY = RPI_GAMES_DIRECTORY if os.path.exists(RPI_GAMES_DIRECTORY) else MC_GAMES_DIRECTORY
COMICS_DIRECTORY = pathlib.Path("/srv/comics/")
MOVIES_DIRECTORY = pathlib.Path("/srv/movies/")
TV_SHOWS_DIRECTORY = pathlib.Path("/srv/tv/")
GAMES_DIRECTORY = pathlib.Path("/srv/games/")
#############
@ -59,27 +46,27 @@ def get_comics():
for f in files:
if "temp" in root:
continue
if f.endswith(".cbr"):
if f.endswith((".cbr", ".cbz")):
total_comics += 1
path = os.path.join(root, f)
if not database.comic_path_in_db(path):
path = pathlib.Path(root, f)
if not database.comic_path_in_db(str(path)):
try:
test_path = path.encode("utf8")
except Exception as e:
current_app.logger.info("encoding failed on: " + path)
current_app.logger.error("encoding failed on: " + str(path))
continue
archive = open_comic(path)
md = archive.readCIX()
if md.publisher in publishers_to_ignore:
continue
current_app.logger.info(path)
current_app.logger.info(str(path))
try:
meta.append((path, md))
meta.append((str(path), md))
thumbnails.append(get_comic_thumbnails(archive))
comics_added += 1
i += 1
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
continue
if i >= 2:
comic_loaded.send("anonymous", meta=meta.copy(), thumbnails=thumbnails.copy())
@ -101,9 +88,9 @@ def get_comic(path: pathlib.Path):
try:
test_path = str(path).encode("utf8")
except Exception as e:
current_app.logger.info(f"encoding failed on: {path}")
current_app.logger.error(f"encoding failed on: {path}")
return
archive = open_comic(str(path))
archive = open_comic(path)
md = archive.readCIX()
if md.publisher in publishers_to_ignore:
return
@ -112,7 +99,7 @@ def get_comic(path: pathlib.Path):
try:
thumbnails.append(get_comic_thumbnails(archive))
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return
comic_loaded.send("anonymous", meta=meta, thumbnails=thumbnails)
@ -123,23 +110,22 @@ def get_comic_thumbnails(comic):
new_height = 256
new_width = 256
for page in range(comic.getNumberOfPages()):
image_bytes = BytesIO(comic.getPage(page))
image = Image(file=image_bytes)
orig_height = image.height
orig_width = image.width
if orig_height >= orig_width:
width = int((orig_width / orig_height) * new_height)
height = new_height
else:
height = int((orig_height / orig_width) * new_width)
width = new_width
image.thumbnail(width, height)
thumbnails.append((image.make_blob(), "image/" + image.format))
with Image(blob=comic.getPage(page)) as image:
orig_height = image.height
orig_width = image.width
if orig_height >= orig_width:
width = int((orig_width / orig_height) * new_height)
height = new_height
else:
height = int((orig_height / orig_width) * new_width)
width = new_width
image.thumbnail(width, height)
thumbnails.append((image.make_blob(), "image/" + image.format))
return thumbnails
def open_comic(path):
archive = comicarchive.ComicArchive(path, default_image_path="static/images/icon.png")
archive = comicarchive.ComicArchive(str(path), default_image_path="static/images/icon.png")
return archive
@ -155,19 +141,21 @@ def get_movies():
for f in files:
if f.endswith(".mkv"):
total_movies += 1
path = os.path.join(root, f)
if not database.movie_path_in_db(path):
path = pathlib.Path(root, f)
if not database.movie_path_in_db(str(path)):
try:
match = re.match(pattern, f)
if not match:
current_app.logger.info(f + " did not match regex.")
continue
current_app.logger.info("movie path: " + path)
current_app.logger.info("movie path: " + str(path))
title = match.group("title")
current_app.logger.info("movie title: " + title)
year = int(match.group("year"))
extended = True if match.group("extended") else False
directors_cut = True if match.group("directors_cut") else False
res_4k_path = (path.parent / path.name.replace(f"({year})", f"({year})(4k)"))
res_4k = res_4k_path.exists()
data = {
"api_key": API_KEY,
@ -195,13 +183,12 @@ def get_movies():
backdrop_path = info["backdrop_path"]
movies_added += 1
movies.append((path, tmdb_id, title, year, description, extended, directors_cut, poster_path, backdrop_path,))
movies.append((str(path), tmdb_id, title, year, description, extended, directors_cut, poster_path, backdrop_path, res_4k,))
if len(movies) >= 20:
movie_loaded.send("anonymous", movies=movies.copy())
movies.clear()
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
# print(e)
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
movies_in_db += 1
movie_loaded.send("anonymous", movies=movies)
current_app.logger.info("finish loading movies")
@ -226,6 +213,7 @@ def get_movie(path: pathlib.Path):
year = int(match.group("year"))
extended = match.group("extended") is True
directors_cut = match.group("directors_cut") is True
res_4k = (path.parent / path.name.replace(f"({year})", f"({year})(4k)")).exists()
data = {
"api_key": API_KEY,
@ -252,12 +240,12 @@ def get_movie(path: pathlib.Path):
poster_path = info["poster_path"]
backdrop_path = info["backdrop_path"]
movies.append((str(path), tmdb_id, title, year, description, extended, directors_cut, poster_path, backdrop_path,))
movies.append((str(path), tmdb_id, title, year, description, extended, directors_cut, poster_path, backdrop_path, res_4k,))
movie_loaded.send("anonymous", movies=movies.copy())
movies.clear()
current_app.logger.info("finish loading movie")
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def get_tv_shows():
@ -265,14 +253,14 @@ def get_tv_shows():
search_url = "https://api.themoviedb.org/3/search/tv"
tv_url = "https://api.themoviedb.org/3/tv/"
current_app.logger.info("start loading tv shows")
for dir in sorted(os.listdir(TV_SHOWS_DIRECTORY)):
dir_match = re.match(dir_pattern, dir)
for dir in sorted(TV_SHOWS_DIRECTORY.iterdir()):
dir_match = re.match(dir_pattern, str(dir))
if dir_match:
path = TV_SHOWS_DIRECTORY + dir
if not database.tv_show_path_in_db(path):
path = TV_SHOWS_DIRECTORY / dir
if not database.tv_show_path_in_db(str(path)):
json_info = {}
if os.path.exists(path + "/info.json"):
with open(path + "/info.json") as f:
if (path / "info.json").exists():
with (path / "info.json").open() as f:
json_info = json.load(f)
series_name = dir_match.group("title")
series_year = int(dir_match.group("year"))
@ -306,7 +294,7 @@ def get_tv_shows():
series_year,
description,
poster_path,
path,
str(path),
)
tv_show_loaded.send("anonymous", tv_show=tv_show_data)
current_app.logger.info("finished loading tv shows.")
@ -319,11 +307,12 @@ def get_tv_episodes():
for tv_show in rows:
try:
episodes = []
for video in sorted(os.listdir(tv_show.path)):
video_match = re.match(video_pattern, video)
tv_show_path = pathlib.Path(tv_show.path)
for video in sorted(tv_show_path.iterdir()):
video_match = re.match(video_pattern, str(video))
if video_match:
path = os.path.join(tv_show.path, video)
if not database.tv_episode_path_in_db(path):
path = tv_show_path / video
if not database.tv_episode_path_in_db(str(path)):
season = int(video_match.group("season"))
episode = int(video_match.group("episode"))
episode_name = video_match.group("title")
@ -341,14 +330,14 @@ def get_tv_episodes():
episode_description = info["overview"]
episode_still_path = info["still_path"]
episodes.append(
(episode_tmdb_id, tv_show.tmdb_id, episode_name, season, episode, episode_description, episode_still_path, path,)
(episode_tmdb_id, tv_show.tmdb_id, episode_name, season, episode, episode_description, episode_still_path, str(path),)
)
if len(episodes) >= 10:
tv_episodes_loaded.send("anonymous", tv_episodes=episodes.copy())
episodes.clear()
tv_episodes_loaded.send("anonymous", tv_episodes=episodes)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.info("finished loading tv episodes")
@ -388,7 +377,7 @@ def get_chapters(path):
with open(path, "rb") as f:
mkv = enzyme.MKV(f)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return {}
mkv_info = {}
for chapter in mkv.chapters:
@ -414,7 +403,7 @@ def get_tags(path):
with open(path, "rb") as f:
mkv = enzyme.MKV(f)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
mkv_info = {}
for tag in mkv.tags:
if tag.targets.data[0].data == 70:
@ -463,12 +452,12 @@ def get_games():
}
i = 0
current_app.logger.info("start loading games")
for folder in sorted(os.listdir(GAMES_DIRECTORY), key=str.casefold):
root = os.path.join(GAMES_DIRECTORY, folder)
if os.path.isdir(os.path.join(root)):
for folder in sorted(GAMES_DIRECTORY.iterdir()):
root = folder.absolute()
if root.is_dir():
try:
path = os.path.join(root, "info.json")
with open(path, "r") as f:
path = root / "info.json"
with path.open() as f:
info = json.load(f)
game_id = info["id"]
if not database.game_in_db(game_id):
@ -498,11 +487,11 @@ def get_games():
game_id,
description,
poster_path,
root,
str(root),
windows,
mac,
linux,
folder,
folder.name,
)
games.append(game)
i += 1
@ -511,7 +500,7 @@ def get_games():
games.clear()
i = 0
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
games_loaded.send("anonymous", games=games)
current_app.logger.info("finished loading games")
@ -562,7 +551,7 @@ def get_game(path: pathlib.Path):
game_id,
description,
poster_path,
str(dir),
str(dir.relative_to(GAMES_DIRECTORY)),
windows,
mac,
linux,
@ -572,13 +561,13 @@ def get_game(path: pathlib.Path):
games_loaded.send("anonymous", games=games)
current_app.logger.info("finished loading game")
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def update_games():
current_app.logger.info("start updating game data")
for folder in sorted(os.listdir(GAMES_DIRECTORY), key=str.casefold):
root = pathlib.Path(GAMES_DIRECTORY, folder, "info.json")
for folder in sorted(GAMES_DIRECTORY.iterdir()):
root = folder / "info.json"
update_game(root)
current_app.logger.info("finished updating game data")
@ -600,4 +589,4 @@ def update_game(path: pathlib.Path):
linux = True
database.update_game((game_id, windows, mac, linux))
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))

View File

@ -5,7 +5,7 @@ import os
from flask import Blueprint, abort, current_app, jsonify, render_template, request, send_file
from flask_login import login_required
from scripts import database, func
import database
Games = Blueprint("games", __name__, template_folder="templates")
@ -21,7 +21,7 @@ def index():
end = len(games) if len(games) < max_items * page else max_items * page
return render_template("games/index.html", title="Games", games=games)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -44,7 +44,7 @@ def get_games():
}
return jsonify(games_json)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -67,7 +67,7 @@ def get_games_windows():
}
return jsonify(games_json)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -92,7 +92,7 @@ def get_games_mac():
games_json[game.game_id]["mac"] = {"executable": info["mac"]["executable"]}
return jsonify(games_json)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -115,7 +115,7 @@ def get_games_linux():
}
return jsonify(games_json)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -149,7 +149,7 @@ def get_game(game_id):
return jsonify(game_json)
abort(404)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -165,5 +165,5 @@ def download_game_hash(game_id, file_hash):
else:
abort(404)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)

View File

@ -11,15 +11,15 @@ from urllib.parse import urljoin, urlsplit, urlunsplit
import inotify.adapters
import inotify.constants
import requests
from flask import Flask, Response, current_app, flash, g, redirect, render_template, request, url_for
from flask import Flask, Response, current_app, flash, g, redirect, render_template, request, url_for, make_response
from flask_login import LoginManager, current_user, login_required, login_user, logout_user
from oauthlib.oauth2 import WebApplicationClient
import scripts.func as func
import func
from admin import admin
from comics import comics
from games import games
from scripts import database
import database
from tv_movies import tv_movies
@ -163,35 +163,35 @@ def update_comic_db(sender, **kw):
try:
database.add_comics(kw["meta"], kw["thumbnails"])
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def update_movie_db(sender, **kw):
try:
database.add_movies(kw["movies"])
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def update_tv_show_db(sender, **kw):
try:
database.add_tv_shows(kw["tv_show"])
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def update_tv_episodes_db(sender, **kw):
try:
database.add_tv_episodes(kw["tv_episodes"])
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def update_games_db(sender, **kw):
try:
database.add_games(kw["games"])
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
func.comic_loaded.connect(update_comic_db)
@ -206,28 +206,30 @@ def load_user(email):
try:
return database.get_user(email)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
@login_manager.request_loader
def load_user_from_request(request):
try:
api_key = request.headers.get("Authorization")
if api_key:
api_key = api_key.replace("Basic ", "", 1)
basic_auth = request.headers.get("Authorization")
api_key = request.args.get("api_key")
auth_key = basic_auth if basic_auth else api_key
if auth_key:
auth_key = auth_key.replace("Basic ", "", 1)
try:
api_key = base64.b64decode(api_key).decode("utf-8")
auth_key = base64.b64decode(auth_key).decode("utf-8")
except TypeError:
pass
email = api_key.split(":")[0]
password = api_key.split(":")[1]
email = auth_key.split(":")[0]
password = auth_key.split(":")[1]
user = load_user(email)
if user and user.check_password(password):
return user
return None
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
@ -264,7 +266,7 @@ def login():
return redirect(next_page)
return render_template("login.html", title="login", auth_url=request_uri)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(e)
@ -313,7 +315,7 @@ def callback():
return redirect(request.args.get("state"))
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(e)
@ -323,7 +325,7 @@ def logout():
logout_user()
return redirect(url_for("login"))
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(e)
@ -338,7 +340,7 @@ def home():
try:
return render_template("home.html", title="Home", current_user=current_user)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(e)
@ -352,7 +354,7 @@ def apply_headers(response: Response):
response.headers.set("email", user_name)
return response
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(e)
@ -367,14 +369,16 @@ def resource_not_found(e):
try:
return render_template("404.html"), 404
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(e)
@login_manager.unauthorized_handler
def handle_unauthorized():
temp = login()
return temp, 401
t = make_response(temp)
t.headers['WWW-Authenticate'] = 'Basic realm="Access to the staging site"'
return t, 401
@app.errorhandler(Exception)

View File

@ -37,14 +37,14 @@ def fix_thumbnails():
print("got list of all thumbnails\n")
for row in rows:
image = Image(file=BytesIO(row["image"]))
if image.width > new_width or image.height > new_height:
print("id:", row["id"], "pageNumber:", row["pageNumber"])
db.execute(
"UPDATE comic_thumbnails SET image=? WHERE id=? AND pageNumber=?",
[resize_image(image, new_width, new_height).make_blob(), row["id"], row["pageNumber"]],
)
db.commit()
with Image(blob=row["image"]) as image:
if image.width > new_width or image.height > new_height:
print("id:", row["id"], "pageNumber:", row["pageNumber"])
db.execute(
"UPDATE comic_thumbnails SET image=? WHERE id=? AND pageNumber=?",
[resize_image(image, new_width, new_height).make_blob(), row["id"], row["pageNumber"]],
)
db.commit()
fix_thumbnails()

View File

@ -5,10 +5,12 @@
<title>rpi - {{ title }}</title>
<link rel="icon" type="image/png" href="/static/images/icon.png" sizes="32x32">
<link href="/static/video-js-7.7.5/video-js.css" rel="stylesheet">
<script src='/static/video-js-7.7.5/video.js'></script>
<link href="/static/videojs-resolution-switcher.css" rel="stylesheet">
<link rel="stylesheet" href="/static/bootstrap.min.css">
<link rel="stylesheet" href="/static/w3.css">
<link rel="stylesheet" href="/static/style.css">
<script src='/static/video-js-7.7.5/video.js'></script>
<script src="/static/videojs-resolution-switcher.js"></script>
{% block head %}
{% endblock %}
<style>
@ -62,8 +64,8 @@
<script>
var page_num = {% if page %}{{ page }}{% else %}1{% endif %};
var max_items = {{ max_items }};
var item_count = {{ item_count }};
var max_items = {% if max_items %}{{ max_items }}{% else %}1{% endif %};
var item_count = {% if item_count %}{{ item_count }}{% else %}1{% endif %};
var start = max_items*(page_num-1);
var end;
if (item_count < max_items*page_num) {

View File

@ -29,7 +29,7 @@ def get_movie_data(imdb_id):
return movie_id, overview, poster_path, backdrop_path
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def get_tv_show_data(imdb_id):
@ -50,7 +50,7 @@ def get_tv_show_data(imdb_id):
return tv_show_id, overview, poster_path
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
def get_tv_episode_data(imdb_id):
@ -77,4 +77,4 @@ def get_tv_episode_data(imdb_id):
return tv_episode_id, overview, still_path
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))

View File

@ -7,13 +7,19 @@
<video id="player" class="video-js vjs-big-play-centered vjs-16-9" style="display: inline-block" controls preload="auto"
poster="https://image.tmdb.org/t/p/original{{ movie.backdrop_path }}" data-setup="{}">
{% if movie.extended and movie.directors_cut %}
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?extended=True&directors_cut=True" type="video/webm">
{% elif movie.extended %}
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?extended=True" type="video/webm">
{% elif movie.directors_cut %}
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?directors_cut=True" type="video/webm">
{% else %}
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}" type="video/webm">
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?extended=True&directors_cut=True" label="extended directors cut" res="1080" type="video/webm">
{% endif %}
{% if movie.extended and not movie.directors_cut %}
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?extended=True" label="extended" res="1080" type="video/webm">
{% endif %}
{% if movie.directors_cut and not movie.extended %}
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?directors_cut=True" label="directors cut" res="1080" type="video/webm">
{% endif %}
{% if not movie.directors_cut and not movie.extended %}
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}" label="HD" res="1080" type="video/webm">
{% endif %}
{% if movie.res_4k %}
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?res_4k=True" label="4k" res="2160" type="video/webm">
{% endif %}
<p class='vjs-no-js'>
To view this video please enable JavaScript, and consider upgrading to a web browser that
@ -36,6 +42,7 @@
<script>
videojs("player").ready(function(){
let myPlayer = videojs.getPlayer("player");
myPlayer.videoJsResolutionSwitcher();
let saved_time = {{ user_data.time }};
let length = -1;
let end_time = -1;

View File

@ -1,10 +1,11 @@
import datetime
import inspect
from flask import Blueprint, current_app, make_response, render_template, request, send_from_directory
from flask import Blueprint, current_app, make_response, render_template, request, send_from_directory, abort
from flask_login import login_required
from scripts import database, func
import func
import database
TV_Movies = Blueprint("tv_movies", __name__, template_folder="templates")
@ -28,7 +29,7 @@ def index():
"tv_movies/index.html", title="tv & movies", tv_shows=tv_dict, page=page, max_items=max_items, start=start, end=end, item_count=len(tv)
)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -56,7 +57,7 @@ def search():
"tv_movies/search.html", title="tv_movies", tv_shows=tv_dict, page=page, max_items=max_items, start=start, end=end, item_count=len(tv)
)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -72,7 +73,7 @@ def tv_movie_viewer(tmdb_id):
else:
return episode_viewer(tmdb_id)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -95,7 +96,7 @@ def movie_view(tmdb_id, extended=False, directors_cut=False):
"tv_movies/movieViewer.html", title="Movies: " + movie_data.title, movie=movie_data, user_data=user_data, chapters=chapters
)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -112,6 +113,8 @@ def episode_viewer(tmdb_id):
else:
tv_show = database.get_tv_show(tmdb_id)
episodes = database.get_tv_show_episodes_by_tmdb_id(tmdb_id)
if len(episodes) == 0:
abort(404)
season_num = request.args.get("season", type=int, default=None)
episode_num = request.args.get("episode", type=int, default=None)
user_tv_show_data = database.db_get_user_tv_show_episodes_data(tmdb_id)
@ -154,7 +157,7 @@ def episode_viewer(tmdb_id):
chapters=chapters,
)
except Exception as e:
current_app.logger.info(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
current_app.logger.error(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
return str(type(e)) + " " + str(e)
@ -163,8 +166,11 @@ def episode_viewer(tmdb_id):
def get_movie(tmdb_id):
extended = request.args.get("extended", default=False, type=bool)
directors_cut = request.args.get("directors_cut", default=False, type=bool)
res_4k = request.args.get("res_4k", default=False, type=bool)
movie_data = database.db_get_movie_by_tmdb_id(tmdb_id, extended=extended, directors_cut=directors_cut)
filename = movie_data.path.replace(func.MOVIES_DIRECTORY, "")
if res_4k:
filename = filename.replace(f"({movie_data.year})", f"({movie_data.year})(4K)")
response = make_response(send_from_directory(func.MOVIES_DIRECTORY, filename))
response.headers["content-type"] = "video/webm"
return response