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:
parent
bb697eb320
commit
c4e6824a8a
@ -8,7 +8,8 @@ import pytz
|
|||||||
from flask import Blueprint, current_app, make_response, render_template, request
|
from flask import Blueprint, current_app, make_response, render_template, request
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
from scripts import database, func
|
import func
|
||||||
|
import database
|
||||||
|
|
||||||
Comics = Blueprint("comics", __name__, template_folder="templates")
|
Comics = Blueprint("comics", __name__, template_folder="templates")
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ def index():
|
|||||||
item_count=len(publishers),
|
item_count=len(publishers),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ def search():
|
|||||||
comics_end=comics_end,
|
comics_end=comics_end,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -149,7 +150,7 @@ def comics_publisher(publisher):
|
|||||||
item_count=len(publisher_series),
|
item_count=len(publisher_series),
|
||||||
)
|
)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -176,7 +177,7 @@ def comic_gallery(comic_id):
|
|||||||
item_count=meta.pagecount,
|
item_count=meta.pagecount,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -184,6 +185,8 @@ def comic_gallery(comic_id):
|
|||||||
@login_required
|
@login_required
|
||||||
def get_comic_page(comic_id, page_number):
|
def get_comic_page(comic_id, page_number):
|
||||||
meta = database.db_get_comic_by_id(comic_id)
|
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)
|
comic = func.open_comic(meta.path)
|
||||||
byte_image = comic.getPage(page_number)
|
byte_image = comic.getPage(page_number)
|
||||||
type = filetype.guess(byte_image).mime
|
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)
|
thumb = database.db_get_thumbnail_by_id_page(comic_id, page_number)
|
||||||
response = make_response(thumb.image)
|
response = make_response(thumb.image)
|
||||||
response.headers["cache-control"] = "public"
|
response.headers["cache-control"] = "public"
|
||||||
date = pytz.utc.localize(datetime.datetime.utcfromtimestamp(os.path.getmtime(meta.path)))
|
if os.path.exists(meta.path):
|
||||||
response.headers["last-modified"] = date.strftime("%a, %d %b %Y %H:%M:%S %Z")
|
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-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
|
return response
|
||||||
|
46
database.py
46
database.py
@ -76,7 +76,7 @@ class Comic(Base):
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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):
|
def __repr__(self):
|
||||||
return "<Comic: {series} {issue}>".format(series=self.series, issue=self.issuetext)
|
return "<Comic: {series} {issue}>".format(series=self.series, issue=self.issuetext)
|
||||||
@ -100,7 +100,7 @@ class ComicThumbnail(Base):
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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):
|
class Movie(Base):
|
||||||
@ -124,7 +124,7 @@ class Movie(Base):
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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):
|
class TvShow(Base):
|
||||||
@ -144,7 +144,7 @@ class TvShow(Base):
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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):
|
class TvEpisode(Base):
|
||||||
@ -166,7 +166,7 @@ class TvEpisode(Base):
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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):
|
class DupComic(Base):
|
||||||
@ -219,7 +219,7 @@ class DupComic(Base):
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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):
|
class Game(Base):
|
||||||
@ -242,7 +242,7 @@ class Game(Base):
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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):
|
class User(Base, UserMixin):
|
||||||
@ -262,7 +262,7 @@ class User(Base, UserMixin):
|
|||||||
i += 1
|
i += 1
|
||||||
pass
|
pass
|
||||||
except Exception as e:
|
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):
|
def get_id(self):
|
||||||
return self.email
|
return self.email
|
||||||
@ -297,7 +297,7 @@ class UserTvMovieData(Base):
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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):
|
class TvMovieKeywords(Base):
|
||||||
@ -319,7 +319,7 @@ class TvMovieKeywords(Base):
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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)
|
Base.metadata.create_all(engine)
|
||||||
@ -340,7 +340,7 @@ Base.metadata.create_all(engine)
|
|||||||
setattr(self, column.name, data[i])
|
setattr(self, column.name, data[i])
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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():
|
# def get_db():
|
||||||
@ -415,7 +415,7 @@ def add_tv_shows(tv_show_data):
|
|||||||
session.add(tv_show)
|
session.add(tv_show)
|
||||||
session.commit()
|
session.commit()
|
||||||
except Exception as e:
|
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):
|
def add_tv_episodes(episodes):
|
||||||
@ -429,7 +429,7 @@ def add_tv_episodes(episodes):
|
|||||||
else:
|
else:
|
||||||
current_app.logger.info(f"TV episode: The TMDB id {episode.tmdb_id} for {episode.path} is already in the database.")
|
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:
|
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):
|
def add_comics(meta, thumbnails):
|
||||||
@ -587,8 +587,8 @@ def comic_path_in_db(path):
|
|||||||
if result or result2:
|
if result or result2:
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.info(path)
|
current_app.logger.error(path)
|
||||||
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
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -599,8 +599,8 @@ def movie_path_in_db(path):
|
|||||||
if result:
|
if result:
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.info(path)
|
current_app.logger.error(path)
|
||||||
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
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -611,8 +611,8 @@ def tv_show_path_in_db(path):
|
|||||||
if result:
|
if result:
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.info(path)
|
current_app.logger.error(path)
|
||||||
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
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -623,8 +623,8 @@ def tv_episode_path_in_db(path):
|
|||||||
if result:
|
if result:
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.info(path)
|
current_app.logger.error(path)
|
||||||
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
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -635,7 +635,7 @@ def game_in_db(game_id):
|
|||||||
if result:
|
if result:
|
||||||
return True
|
return True
|
||||||
except Exception as e:
|
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
|
return False
|
||||||
|
|
||||||
|
|
||||||
@ -978,4 +978,4 @@ def get_user(email):
|
|||||||
return result
|
return result
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
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))
|
||||||
|
@ -4,7 +4,6 @@ import os
|
|||||||
import pathlib
|
import pathlib
|
||||||
import re
|
import re
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from io import BytesIO
|
|
||||||
|
|
||||||
import enzyme
|
import enzyme
|
||||||
import requests
|
import requests
|
||||||
@ -13,7 +12,7 @@ from comicapi import comicarchive
|
|||||||
from flask import current_app
|
from flask import current_app
|
||||||
from wand.image import Image
|
from wand.image import Image
|
||||||
|
|
||||||
from scripts import database
|
import database
|
||||||
|
|
||||||
rpi_signals = Namespace()
|
rpi_signals = Namespace()
|
||||||
comic_loaded = rpi_signals.signal("comic-loaded")
|
comic_loaded = rpi_signals.signal("comic-loaded")
|
||||||
@ -28,22 +27,10 @@ API_KEY = "***REMOVED***"
|
|||||||
|
|
||||||
# Directories
|
# Directories
|
||||||
|
|
||||||
RPI_COMICS_DIRECTORY = "/usb/storage/media/Comics/"
|
COMICS_DIRECTORY = pathlib.Path("/srv/comics/")
|
||||||
RPI_MOVIES_DIRECTORY = "/usb/storage/media/Videos/Movies/"
|
MOVIES_DIRECTORY = pathlib.Path("/srv/movies/")
|
||||||
RPI_TV_SHOWS_DIRECTORY = "/usb/storage/media/Videos/TV/"
|
TV_SHOWS_DIRECTORY = pathlib.Path("/srv/tv/")
|
||||||
RPI_VIDEOS_DIRECTORY = "/usb/storage/media/Videos/Videos/"
|
GAMES_DIRECTORY = pathlib.Path("/srv/games/")
|
||||||
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
|
|
||||||
|
|
||||||
#############
|
#############
|
||||||
|
|
||||||
@ -59,27 +46,27 @@ def get_comics():
|
|||||||
for f in files:
|
for f in files:
|
||||||
if "temp" in root:
|
if "temp" in root:
|
||||||
continue
|
continue
|
||||||
if f.endswith(".cbr"):
|
if f.endswith((".cbr", ".cbz")):
|
||||||
total_comics += 1
|
total_comics += 1
|
||||||
path = os.path.join(root, f)
|
path = pathlib.Path(root, f)
|
||||||
if not database.comic_path_in_db(path):
|
if not database.comic_path_in_db(str(path)):
|
||||||
try:
|
try:
|
||||||
test_path = path.encode("utf8")
|
test_path = path.encode("utf8")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.info("encoding failed on: " + path)
|
current_app.logger.error("encoding failed on: " + str(path))
|
||||||
continue
|
continue
|
||||||
archive = open_comic(path)
|
archive = open_comic(path)
|
||||||
md = archive.readCIX()
|
md = archive.readCIX()
|
||||||
if md.publisher in publishers_to_ignore:
|
if md.publisher in publishers_to_ignore:
|
||||||
continue
|
continue
|
||||||
current_app.logger.info(path)
|
current_app.logger.info(str(path))
|
||||||
try:
|
try:
|
||||||
meta.append((path, md))
|
meta.append((str(path), md))
|
||||||
thumbnails.append(get_comic_thumbnails(archive))
|
thumbnails.append(get_comic_thumbnails(archive))
|
||||||
comics_added += 1
|
comics_added += 1
|
||||||
i += 1
|
i += 1
|
||||||
except Exception as e:
|
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
|
continue
|
||||||
if i >= 2:
|
if i >= 2:
|
||||||
comic_loaded.send("anonymous", meta=meta.copy(), thumbnails=thumbnails.copy())
|
comic_loaded.send("anonymous", meta=meta.copy(), thumbnails=thumbnails.copy())
|
||||||
@ -101,9 +88,9 @@ def get_comic(path: pathlib.Path):
|
|||||||
try:
|
try:
|
||||||
test_path = str(path).encode("utf8")
|
test_path = str(path).encode("utf8")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
current_app.logger.info(f"encoding failed on: {path}")
|
current_app.logger.error(f"encoding failed on: {path}")
|
||||||
return
|
return
|
||||||
archive = open_comic(str(path))
|
archive = open_comic(path)
|
||||||
md = archive.readCIX()
|
md = archive.readCIX()
|
||||||
if md.publisher in publishers_to_ignore:
|
if md.publisher in publishers_to_ignore:
|
||||||
return
|
return
|
||||||
@ -112,7 +99,7 @@ def get_comic(path: pathlib.Path):
|
|||||||
try:
|
try:
|
||||||
thumbnails.append(get_comic_thumbnails(archive))
|
thumbnails.append(get_comic_thumbnails(archive))
|
||||||
except Exception as e:
|
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
|
return
|
||||||
comic_loaded.send("anonymous", meta=meta, thumbnails=thumbnails)
|
comic_loaded.send("anonymous", meta=meta, thumbnails=thumbnails)
|
||||||
|
|
||||||
@ -123,23 +110,22 @@ def get_comic_thumbnails(comic):
|
|||||||
new_height = 256
|
new_height = 256
|
||||||
new_width = 256
|
new_width = 256
|
||||||
for page in range(comic.getNumberOfPages()):
|
for page in range(comic.getNumberOfPages()):
|
||||||
image_bytes = BytesIO(comic.getPage(page))
|
with Image(blob=comic.getPage(page)) as image:
|
||||||
image = Image(file=image_bytes)
|
orig_height = image.height
|
||||||
orig_height = image.height
|
orig_width = image.width
|
||||||
orig_width = image.width
|
if orig_height >= orig_width:
|
||||||
if orig_height >= orig_width:
|
width = int((orig_width / orig_height) * new_height)
|
||||||
width = int((orig_width / orig_height) * new_height)
|
height = new_height
|
||||||
height = new_height
|
else:
|
||||||
else:
|
height = int((orig_height / orig_width) * new_width)
|
||||||
height = int((orig_height / orig_width) * new_width)
|
width = new_width
|
||||||
width = new_width
|
image.thumbnail(width, height)
|
||||||
image.thumbnail(width, height)
|
thumbnails.append((image.make_blob(), "image/" + image.format))
|
||||||
thumbnails.append((image.make_blob(), "image/" + image.format))
|
|
||||||
return thumbnails
|
return thumbnails
|
||||||
|
|
||||||
|
|
||||||
def open_comic(path):
|
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
|
return archive
|
||||||
|
|
||||||
|
|
||||||
@ -155,19 +141,21 @@ def get_movies():
|
|||||||
for f in files:
|
for f in files:
|
||||||
if f.endswith(".mkv"):
|
if f.endswith(".mkv"):
|
||||||
total_movies += 1
|
total_movies += 1
|
||||||
path = os.path.join(root, f)
|
path = pathlib.Path(root, f)
|
||||||
if not database.movie_path_in_db(path):
|
if not database.movie_path_in_db(str(path)):
|
||||||
try:
|
try:
|
||||||
match = re.match(pattern, f)
|
match = re.match(pattern, f)
|
||||||
if not match:
|
if not match:
|
||||||
current_app.logger.info(f + " did not match regex.")
|
current_app.logger.info(f + " did not match regex.")
|
||||||
continue
|
continue
|
||||||
current_app.logger.info("movie path: " + path)
|
current_app.logger.info("movie path: " + str(path))
|
||||||
title = match.group("title")
|
title = match.group("title")
|
||||||
current_app.logger.info("movie title: " + title)
|
current_app.logger.info("movie title: " + title)
|
||||||
year = int(match.group("year"))
|
year = int(match.group("year"))
|
||||||
extended = True if match.group("extended") else False
|
extended = True if match.group("extended") else False
|
||||||
directors_cut = True if match.group("directors_cut") 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 = {
|
data = {
|
||||||
"api_key": API_KEY,
|
"api_key": API_KEY,
|
||||||
@ -195,13 +183,12 @@ def get_movies():
|
|||||||
backdrop_path = info["backdrop_path"]
|
backdrop_path = info["backdrop_path"]
|
||||||
movies_added += 1
|
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:
|
if len(movies) >= 20:
|
||||||
movie_loaded.send("anonymous", movies=movies.copy())
|
movie_loaded.send("anonymous", movies=movies.copy())
|
||||||
movies.clear()
|
movies.clear()
|
||||||
except Exception as e:
|
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))
|
||||||
# print(e)
|
|
||||||
movies_in_db += 1
|
movies_in_db += 1
|
||||||
movie_loaded.send("anonymous", movies=movies)
|
movie_loaded.send("anonymous", movies=movies)
|
||||||
current_app.logger.info("finish loading movies")
|
current_app.logger.info("finish loading movies")
|
||||||
@ -226,6 +213,7 @@ def get_movie(path: pathlib.Path):
|
|||||||
year = int(match.group("year"))
|
year = int(match.group("year"))
|
||||||
extended = match.group("extended") is True
|
extended = match.group("extended") is True
|
||||||
directors_cut = match.group("directors_cut") is True
|
directors_cut = match.group("directors_cut") is True
|
||||||
|
res_4k = (path.parent / path.name.replace(f"({year})", f"({year})(4k)")).exists()
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"api_key": API_KEY,
|
"api_key": API_KEY,
|
||||||
@ -252,12 +240,12 @@ def get_movie(path: pathlib.Path):
|
|||||||
poster_path = info["poster_path"]
|
poster_path = info["poster_path"]
|
||||||
backdrop_path = info["backdrop_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())
|
movie_loaded.send("anonymous", movies=movies.copy())
|
||||||
movies.clear()
|
movies.clear()
|
||||||
current_app.logger.info("finish loading movie")
|
current_app.logger.info("finish loading movie")
|
||||||
except Exception as e:
|
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():
|
def get_tv_shows():
|
||||||
@ -265,14 +253,14 @@ def get_tv_shows():
|
|||||||
search_url = "https://api.themoviedb.org/3/search/tv"
|
search_url = "https://api.themoviedb.org/3/search/tv"
|
||||||
tv_url = "https://api.themoviedb.org/3/tv/"
|
tv_url = "https://api.themoviedb.org/3/tv/"
|
||||||
current_app.logger.info("start loading tv shows")
|
current_app.logger.info("start loading tv shows")
|
||||||
for dir in sorted(os.listdir(TV_SHOWS_DIRECTORY)):
|
for dir in sorted(TV_SHOWS_DIRECTORY.iterdir()):
|
||||||
dir_match = re.match(dir_pattern, dir)
|
dir_match = re.match(dir_pattern, str(dir))
|
||||||
if dir_match:
|
if dir_match:
|
||||||
path = TV_SHOWS_DIRECTORY + dir
|
path = TV_SHOWS_DIRECTORY / dir
|
||||||
if not database.tv_show_path_in_db(path):
|
if not database.tv_show_path_in_db(str(path)):
|
||||||
json_info = {}
|
json_info = {}
|
||||||
if os.path.exists(path + "/info.json"):
|
if (path / "info.json").exists():
|
||||||
with open(path + "/info.json") as f:
|
with (path / "info.json").open() as f:
|
||||||
json_info = json.load(f)
|
json_info = json.load(f)
|
||||||
series_name = dir_match.group("title")
|
series_name = dir_match.group("title")
|
||||||
series_year = int(dir_match.group("year"))
|
series_year = int(dir_match.group("year"))
|
||||||
@ -306,7 +294,7 @@ def get_tv_shows():
|
|||||||
series_year,
|
series_year,
|
||||||
description,
|
description,
|
||||||
poster_path,
|
poster_path,
|
||||||
path,
|
str(path),
|
||||||
)
|
)
|
||||||
tv_show_loaded.send("anonymous", tv_show=tv_show_data)
|
tv_show_loaded.send("anonymous", tv_show=tv_show_data)
|
||||||
current_app.logger.info("finished loading tv shows.")
|
current_app.logger.info("finished loading tv shows.")
|
||||||
@ -319,11 +307,12 @@ def get_tv_episodes():
|
|||||||
for tv_show in rows:
|
for tv_show in rows:
|
||||||
try:
|
try:
|
||||||
episodes = []
|
episodes = []
|
||||||
for video in sorted(os.listdir(tv_show.path)):
|
tv_show_path = pathlib.Path(tv_show.path)
|
||||||
video_match = re.match(video_pattern, video)
|
for video in sorted(tv_show_path.iterdir()):
|
||||||
|
video_match = re.match(video_pattern, str(video))
|
||||||
if video_match:
|
if video_match:
|
||||||
path = os.path.join(tv_show.path, video)
|
path = tv_show_path / video
|
||||||
if not database.tv_episode_path_in_db(path):
|
if not database.tv_episode_path_in_db(str(path)):
|
||||||
season = int(video_match.group("season"))
|
season = int(video_match.group("season"))
|
||||||
episode = int(video_match.group("episode"))
|
episode = int(video_match.group("episode"))
|
||||||
episode_name = video_match.group("title")
|
episode_name = video_match.group("title")
|
||||||
@ -341,14 +330,14 @@ def get_tv_episodes():
|
|||||||
episode_description = info["overview"]
|
episode_description = info["overview"]
|
||||||
episode_still_path = info["still_path"]
|
episode_still_path = info["still_path"]
|
||||||
episodes.append(
|
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:
|
if len(episodes) >= 10:
|
||||||
tv_episodes_loaded.send("anonymous", tv_episodes=episodes.copy())
|
tv_episodes_loaded.send("anonymous", tv_episodes=episodes.copy())
|
||||||
episodes.clear()
|
episodes.clear()
|
||||||
tv_episodes_loaded.send("anonymous", tv_episodes=episodes)
|
tv_episodes_loaded.send("anonymous", tv_episodes=episodes)
|
||||||
except Exception as e:
|
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")
|
current_app.logger.info("finished loading tv episodes")
|
||||||
|
|
||||||
|
|
||||||
@ -388,7 +377,7 @@ def get_chapters(path):
|
|||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
mkv = enzyme.MKV(f)
|
mkv = enzyme.MKV(f)
|
||||||
except Exception as e:
|
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 {}
|
return {}
|
||||||
mkv_info = {}
|
mkv_info = {}
|
||||||
for chapter in mkv.chapters:
|
for chapter in mkv.chapters:
|
||||||
@ -414,7 +403,7 @@ def get_tags(path):
|
|||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
mkv = enzyme.MKV(f)
|
mkv = enzyme.MKV(f)
|
||||||
except Exception as e:
|
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 = {}
|
mkv_info = {}
|
||||||
for tag in mkv.tags:
|
for tag in mkv.tags:
|
||||||
if tag.targets.data[0].data == 70:
|
if tag.targets.data[0].data == 70:
|
||||||
@ -463,12 +452,12 @@ def get_games():
|
|||||||
}
|
}
|
||||||
i = 0
|
i = 0
|
||||||
current_app.logger.info("start loading games")
|
current_app.logger.info("start loading games")
|
||||||
for folder in sorted(os.listdir(GAMES_DIRECTORY), key=str.casefold):
|
for folder in sorted(GAMES_DIRECTORY.iterdir()):
|
||||||
root = os.path.join(GAMES_DIRECTORY, folder)
|
root = folder.absolute()
|
||||||
if os.path.isdir(os.path.join(root)):
|
if root.is_dir():
|
||||||
try:
|
try:
|
||||||
path = os.path.join(root, "info.json")
|
path = root / "info.json"
|
||||||
with open(path, "r") as f:
|
with path.open() as f:
|
||||||
info = json.load(f)
|
info = json.load(f)
|
||||||
game_id = info["id"]
|
game_id = info["id"]
|
||||||
if not database.game_in_db(game_id):
|
if not database.game_in_db(game_id):
|
||||||
@ -498,11 +487,11 @@ def get_games():
|
|||||||
game_id,
|
game_id,
|
||||||
description,
|
description,
|
||||||
poster_path,
|
poster_path,
|
||||||
root,
|
str(root),
|
||||||
windows,
|
windows,
|
||||||
mac,
|
mac,
|
||||||
linux,
|
linux,
|
||||||
folder,
|
folder.name,
|
||||||
)
|
)
|
||||||
games.append(game)
|
games.append(game)
|
||||||
i += 1
|
i += 1
|
||||||
@ -511,7 +500,7 @@ def get_games():
|
|||||||
games.clear()
|
games.clear()
|
||||||
i = 0
|
i = 0
|
||||||
except Exception as e:
|
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)
|
games_loaded.send("anonymous", games=games)
|
||||||
current_app.logger.info("finished loading games")
|
current_app.logger.info("finished loading games")
|
||||||
|
|
||||||
@ -562,7 +551,7 @@ def get_game(path: pathlib.Path):
|
|||||||
game_id,
|
game_id,
|
||||||
description,
|
description,
|
||||||
poster_path,
|
poster_path,
|
||||||
str(dir),
|
str(dir.relative_to(GAMES_DIRECTORY)),
|
||||||
windows,
|
windows,
|
||||||
mac,
|
mac,
|
||||||
linux,
|
linux,
|
||||||
@ -572,13 +561,13 @@ def get_game(path: pathlib.Path):
|
|||||||
games_loaded.send("anonymous", games=games)
|
games_loaded.send("anonymous", games=games)
|
||||||
current_app.logger.info("finished loading game")
|
current_app.logger.info("finished loading game")
|
||||||
except Exception as e:
|
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():
|
def update_games():
|
||||||
current_app.logger.info("start updating game data")
|
current_app.logger.info("start updating game data")
|
||||||
for folder in sorted(os.listdir(GAMES_DIRECTORY), key=str.casefold):
|
for folder in sorted(GAMES_DIRECTORY.iterdir()):
|
||||||
root = pathlib.Path(GAMES_DIRECTORY, folder, "info.json")
|
root = folder / "info.json"
|
||||||
update_game(root)
|
update_game(root)
|
||||||
current_app.logger.info("finished updating game data")
|
current_app.logger.info("finished updating game data")
|
||||||
|
|
||||||
@ -600,4 +589,4 @@ def update_game(path: pathlib.Path):
|
|||||||
linux = True
|
linux = True
|
||||||
database.update_game((game_id, windows, mac, linux))
|
database.update_game((game_id, windows, mac, linux))
|
||||||
except Exception as e:
|
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))
|
@ -5,7 +5,7 @@ import os
|
|||||||
from flask import Blueprint, abort, current_app, jsonify, render_template, request, send_file
|
from flask import Blueprint, abort, current_app, jsonify, render_template, request, send_file
|
||||||
from flask_login import login_required
|
from flask_login import login_required
|
||||||
|
|
||||||
from scripts import database, func
|
import database
|
||||||
|
|
||||||
Games = Blueprint("games", __name__, template_folder="templates")
|
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
|
end = len(games) if len(games) < max_items * page else max_items * page
|
||||||
return render_template("games/index.html", title="Games", games=games)
|
return render_template("games/index.html", title="Games", games=games)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ def get_games():
|
|||||||
}
|
}
|
||||||
return jsonify(games_json)
|
return jsonify(games_json)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ def get_games_windows():
|
|||||||
}
|
}
|
||||||
return jsonify(games_json)
|
return jsonify(games_json)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ def get_games_mac():
|
|||||||
games_json[game.game_id]["mac"] = {"executable": info["mac"]["executable"]}
|
games_json[game.game_id]["mac"] = {"executable": info["mac"]["executable"]}
|
||||||
return jsonify(games_json)
|
return jsonify(games_json)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ def get_games_linux():
|
|||||||
}
|
}
|
||||||
return jsonify(games_json)
|
return jsonify(games_json)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ def get_game(game_id):
|
|||||||
return jsonify(game_json)
|
return jsonify(game_json)
|
||||||
abort(404)
|
abort(404)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -165,5 +165,5 @@ def download_game_hash(game_id, file_hash):
|
|||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
50
rpiWebApp.py
50
rpiWebApp.py
@ -11,15 +11,15 @@ from urllib.parse import urljoin, urlsplit, urlunsplit
|
|||||||
import inotify.adapters
|
import inotify.adapters
|
||||||
import inotify.constants
|
import inotify.constants
|
||||||
import requests
|
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 flask_login import LoginManager, current_user, login_required, login_user, logout_user
|
||||||
from oauthlib.oauth2 import WebApplicationClient
|
from oauthlib.oauth2 import WebApplicationClient
|
||||||
|
|
||||||
import scripts.func as func
|
import func
|
||||||
from admin import admin
|
from admin import admin
|
||||||
from comics import comics
|
from comics import comics
|
||||||
from games import games
|
from games import games
|
||||||
from scripts import database
|
import database
|
||||||
from tv_movies import tv_movies
|
from tv_movies import tv_movies
|
||||||
|
|
||||||
|
|
||||||
@ -163,35 +163,35 @@ def update_comic_db(sender, **kw):
|
|||||||
try:
|
try:
|
||||||
database.add_comics(kw["meta"], kw["thumbnails"])
|
database.add_comics(kw["meta"], kw["thumbnails"])
|
||||||
except Exception as e:
|
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):
|
def update_movie_db(sender, **kw):
|
||||||
try:
|
try:
|
||||||
database.add_movies(kw["movies"])
|
database.add_movies(kw["movies"])
|
||||||
except Exception as e:
|
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):
|
def update_tv_show_db(sender, **kw):
|
||||||
try:
|
try:
|
||||||
database.add_tv_shows(kw["tv_show"])
|
database.add_tv_shows(kw["tv_show"])
|
||||||
except Exception as e:
|
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):
|
def update_tv_episodes_db(sender, **kw):
|
||||||
try:
|
try:
|
||||||
database.add_tv_episodes(kw["tv_episodes"])
|
database.add_tv_episodes(kw["tv_episodes"])
|
||||||
except Exception as e:
|
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):
|
def update_games_db(sender, **kw):
|
||||||
try:
|
try:
|
||||||
database.add_games(kw["games"])
|
database.add_games(kw["games"])
|
||||||
except Exception as e:
|
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)
|
func.comic_loaded.connect(update_comic_db)
|
||||||
@ -206,28 +206,30 @@ def load_user(email):
|
|||||||
try:
|
try:
|
||||||
return database.get_user(email)
|
return database.get_user(email)
|
||||||
except Exception as e:
|
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))
|
return str(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
||||||
|
|
||||||
|
|
||||||
@login_manager.request_loader
|
@login_manager.request_loader
|
||||||
def load_user_from_request(request):
|
def load_user_from_request(request):
|
||||||
try:
|
try:
|
||||||
api_key = request.headers.get("Authorization")
|
basic_auth = request.headers.get("Authorization")
|
||||||
if api_key:
|
api_key = request.args.get("api_key")
|
||||||
api_key = api_key.replace("Basic ", "", 1)
|
auth_key = basic_auth if basic_auth else api_key
|
||||||
|
if auth_key:
|
||||||
|
auth_key = auth_key.replace("Basic ", "", 1)
|
||||||
try:
|
try:
|
||||||
api_key = base64.b64decode(api_key).decode("utf-8")
|
auth_key = base64.b64decode(auth_key).decode("utf-8")
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
email = api_key.split(":")[0]
|
email = auth_key.split(":")[0]
|
||||||
password = api_key.split(":")[1]
|
password = auth_key.split(":")[1]
|
||||||
user = load_user(email)
|
user = load_user(email)
|
||||||
if user and user.check_password(password):
|
if user and user.check_password(password):
|
||||||
return user
|
return user
|
||||||
return None
|
return None
|
||||||
except Exception as e:
|
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))
|
return str(inspect.stack()[0][3] + " " + str(type(e)) + " " + str(e))
|
||||||
|
|
||||||
|
|
||||||
@ -264,7 +266,7 @@ def login():
|
|||||||
return redirect(next_page)
|
return redirect(next_page)
|
||||||
return render_template("login.html", title="login", auth_url=request_uri)
|
return render_template("login.html", title="login", auth_url=request_uri)
|
||||||
except Exception as e:
|
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)
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -313,7 +315,7 @@ def callback():
|
|||||||
|
|
||||||
return redirect(request.args.get("state"))
|
return redirect(request.args.get("state"))
|
||||||
except Exception as e:
|
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)
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -323,7 +325,7 @@ def logout():
|
|||||||
logout_user()
|
logout_user()
|
||||||
return redirect(url_for("login"))
|
return redirect(url_for("login"))
|
||||||
except Exception as e:
|
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)
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -338,7 +340,7 @@ def home():
|
|||||||
try:
|
try:
|
||||||
return render_template("home.html", title="Home", current_user=current_user)
|
return render_template("home.html", title="Home", current_user=current_user)
|
||||||
except Exception as e:
|
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)
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -352,7 +354,7 @@ def apply_headers(response: Response):
|
|||||||
response.headers.set("email", user_name)
|
response.headers.set("email", user_name)
|
||||||
return response
|
return response
|
||||||
except Exception as e:
|
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)
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -367,14 +369,16 @@ def resource_not_found(e):
|
|||||||
try:
|
try:
|
||||||
return render_template("404.html"), 404
|
return render_template("404.html"), 404
|
||||||
except Exception as e:
|
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)
|
return str(e)
|
||||||
|
|
||||||
|
|
||||||
@login_manager.unauthorized_handler
|
@login_manager.unauthorized_handler
|
||||||
def handle_unauthorized():
|
def handle_unauthorized():
|
||||||
temp = login()
|
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)
|
@app.errorhandler(Exception)
|
||||||
|
@ -37,14 +37,14 @@ def fix_thumbnails():
|
|||||||
print("got list of all thumbnails\n")
|
print("got list of all thumbnails\n")
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
image = Image(file=BytesIO(row["image"]))
|
with Image(blob=row["image"]) as image:
|
||||||
if image.width > new_width or image.height > new_height:
|
if image.width > new_width or image.height > new_height:
|
||||||
print("id:", row["id"], "pageNumber:", row["pageNumber"])
|
print("id:", row["id"], "pageNumber:", row["pageNumber"])
|
||||||
db.execute(
|
db.execute(
|
||||||
"UPDATE comic_thumbnails SET image=? WHERE id=? AND pageNumber=?",
|
"UPDATE comic_thumbnails SET image=? WHERE id=? AND pageNumber=?",
|
||||||
[resize_image(image, new_width, new_height).make_blob(), row["id"], row["pageNumber"]],
|
[resize_image(image, new_width, new_height).make_blob(), row["id"], row["pageNumber"]],
|
||||||
)
|
)
|
||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
|
|
||||||
fix_thumbnails()
|
fix_thumbnails()
|
||||||
|
@ -5,10 +5,12 @@
|
|||||||
<title>rpi - {{ title }}</title>
|
<title>rpi - {{ title }}</title>
|
||||||
<link rel="icon" type="image/png" href="/static/images/icon.png" sizes="32x32">
|
<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">
|
<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/bootstrap.min.css">
|
||||||
<link rel="stylesheet" href="/static/w3.css">
|
<link rel="stylesheet" href="/static/w3.css">
|
||||||
<link rel="stylesheet" href="/static/style.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 %}
|
{% block head %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
<style>
|
<style>
|
||||||
@ -62,8 +64,8 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
var page_num = {% if page %}{{ page }}{% else %}1{% endif %};
|
var page_num = {% if page %}{{ page }}{% else %}1{% endif %};
|
||||||
var max_items = {{ max_items }};
|
var max_items = {% if max_items %}{{ max_items }}{% else %}1{% endif %};
|
||||||
var item_count = {{ item_count }};
|
var item_count = {% if item_count %}{{ item_count }}{% else %}1{% endif %};
|
||||||
var start = max_items*(page_num-1);
|
var start = max_items*(page_num-1);
|
||||||
var end;
|
var end;
|
||||||
if (item_count < max_items*page_num) {
|
if (item_count < max_items*page_num) {
|
||||||
|
@ -29,7 +29,7 @@ def get_movie_data(imdb_id):
|
|||||||
|
|
||||||
return movie_id, overview, poster_path, backdrop_path
|
return movie_id, overview, poster_path, backdrop_path
|
||||||
except Exception as e:
|
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):
|
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
|
return tv_show_id, overview, poster_path
|
||||||
except Exception as e:
|
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):
|
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
|
return tv_episode_id, overview, still_path
|
||||||
except Exception as e:
|
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))
|
@ -7,13 +7,19 @@
|
|||||||
<video id="player" class="video-js vjs-big-play-centered vjs-16-9" style="display: inline-block" controls preload="auto"
|
<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="{}">
|
poster="https://image.tmdb.org/t/p/original{{ movie.backdrop_path }}" data-setup="{}">
|
||||||
{% if movie.extended and movie.directors_cut %}
|
{% 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">
|
<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">
|
||||||
{% elif movie.extended %}
|
{% endif %}
|
||||||
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?extended=True" type="video/webm">
|
{% if movie.extended and not movie.directors_cut %}
|
||||||
{% elif movie.directors_cut %}
|
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?extended=True" label="extended" res="1080" type="video/webm">
|
||||||
<source src="{{ url_for("tv_movies.index") }}/get_movie/{{ movie.tmdb_id }}?directors_cut=True" type="video/webm">
|
{% endif %}
|
||||||
{% else %}
|
{% if movie.directors_cut and not movie.extended %}
|
||||||
<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 }}?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 %}
|
{% endif %}
|
||||||
<p class='vjs-no-js'>
|
<p class='vjs-no-js'>
|
||||||
To view this video please enable JavaScript, and consider upgrading to a web browser that
|
To view this video please enable JavaScript, and consider upgrading to a web browser that
|
||||||
@ -36,6 +42,7 @@
|
|||||||
<script>
|
<script>
|
||||||
videojs("player").ready(function(){
|
videojs("player").ready(function(){
|
||||||
let myPlayer = videojs.getPlayer("player");
|
let myPlayer = videojs.getPlayer("player");
|
||||||
|
myPlayer.videoJsResolutionSwitcher();
|
||||||
let saved_time = {{ user_data.time }};
|
let saved_time = {{ user_data.time }};
|
||||||
let length = -1;
|
let length = -1;
|
||||||
let end_time = -1;
|
let end_time = -1;
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import datetime
|
import datetime
|
||||||
import inspect
|
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 flask_login import login_required
|
||||||
|
|
||||||
from scripts import database, func
|
import func
|
||||||
|
import database
|
||||||
|
|
||||||
TV_Movies = Blueprint("tv_movies", __name__, template_folder="templates")
|
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)
|
"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:
|
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)
|
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)
|
"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:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -72,7 +73,7 @@ def tv_movie_viewer(tmdb_id):
|
|||||||
else:
|
else:
|
||||||
return episode_viewer(tmdb_id)
|
return episode_viewer(tmdb_id)
|
||||||
except Exception as e:
|
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)
|
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
|
"tv_movies/movieViewer.html", title="Movies: " + movie_data.title, movie=movie_data, user_data=user_data, chapters=chapters
|
||||||
)
|
)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -112,6 +113,8 @@ def episode_viewer(tmdb_id):
|
|||||||
else:
|
else:
|
||||||
tv_show = database.get_tv_show(tmdb_id)
|
tv_show = database.get_tv_show(tmdb_id)
|
||||||
episodes = database.get_tv_show_episodes_by_tmdb_id(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)
|
season_num = request.args.get("season", type=int, default=None)
|
||||||
episode_num = request.args.get("episode", 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)
|
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,
|
chapters=chapters,
|
||||||
)
|
)
|
||||||
except Exception as e:
|
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)
|
return str(type(e)) + " " + str(e)
|
||||||
|
|
||||||
|
|
||||||
@ -163,8 +166,11 @@ def episode_viewer(tmdb_id):
|
|||||||
def get_movie(tmdb_id):
|
def get_movie(tmdb_id):
|
||||||
extended = request.args.get("extended", default=False, type=bool)
|
extended = request.args.get("extended", default=False, type=bool)
|
||||||
directors_cut = request.args.get("directors_cut", 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)
|
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, "")
|
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 = make_response(send_from_directory(func.MOVIES_DIRECTORY, filename))
|
||||||
response.headers["content-type"] = "video/webm"
|
response.headers["content-type"] = "video/webm"
|
||||||
return response
|
return response
|
||||||
|
Loading…
Reference in New Issue
Block a user