Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #55

Merged
merged 10 commits into from
Nov 9, 2021
Merged

Dev #55

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Empty file modified .dockerignore
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
36 changes: 30 additions & 6 deletions Dockerfile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,15 +1,39 @@
FROM tiangolo/uwsgi-nginx-flask:python3.9
LABEL author="Jkirkcaldy"
FROM python:3.9-buster

LABEL maintainer="JKirkcaldy"

RUN apt update && apt install mediainfo nano -y
WORKDIR /app
COPY ./app ./app
COPY ./main.py .
COPY ./requirements.txt .
COPY ./entrypoint.sh .
COPY ./start.sh .



# Install requirements

ENV STATIC_PATH /app/app/static
COPY . .
RUN pip install --no-cache-dir -r requirements.txt

EXPOSE 80
EXPOSE 443
EXPOSE 5000
VOLUME [ "/films" ]
VOLUME [ "/config" ]
VOLUME [ "/logs" ]
EXPOSE 5000

RUN apt-get update && apt-get install -y supervisor mediainfo nginx \
&& rm -rf /var/lib/apt/lists/*
COPY supervisord-debian.conf /etc/supervisor/conf.d/supervisord.conf
COPY app/static/dockerfiles/default /etc/nginx/sites-enabled/default

ENV NGINX_MAX_UPLOAD 0
ENV NGINX_WORKER_PROCESSES 1
ENV LISTEN_PORT 80
RUN chmod +x start.sh
RUN chmod +x entrypoint.sh

ENV TZ=Europe/London

ENTRYPOINT ["/app/entrypoint.sh"]
CMD ["/app/start.sh"]
Empty file modified LICENSE
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
110 changes: 60 additions & 50 deletions app/__init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,86 +2,94 @@
from flask.wrappers import Response
from flask_sqlalchemy import SQLAlchemy
from flask_bootstrap import Bootstrap
from app.scripts import posters4k, posters3d, hide4k, disney, pixar, migrate, restore_posters, fresh_hdr_posters
from app.scripts import posters4k, posters3d, hide4k, disney, pixar, migrate, restore_posters, fresh_hdr_posters, setup_logger
import os
from flask_apscheduler import APScheduler
import sqlite3
import logging
from logging.handlers import RotatingFileHandler
import shutil
from plexapi.server import PlexServer

logger = logging.getLogger()
logger.setLevel(logging.INFO)
handler = logging.FileHandler("/logs/application_log.log")
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)

setup_logger('SYS', r"/logs/application_log.log")
log = logging.getLogger('SYS')

def setup_helper():
def create_table():
shutil.copy('app/static/default_db/default_app.db', '/config/app.db')
def continue_setup():
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
c.execute("SELECT * FROM plex_utills")
config = c.fetchall()

try:
plex = PlexServer(config[0][1], config[0][2])
films = plex.library.section(config[0][3])
media_location = films.search()
filepath = os.path.dirname(os.path.dirname(media_location[0].media[0].parts[0].file))
plexpath = '/'+filepath.split('/')[1]

c.execute("UPDATE plex_utills SET plexpath = '"+plexpath+"' WHERE ID = 1;")
conn.commit()
c.close()
log.info("Setup Helper: Your plexpath has been changed to "+plexpath)

except OSError as e:
if e.errno == 111:
log.warning("Setup Helper: Cannont connect to your plex server, this may be because it is the first run and you haven't changed the config yet.")

def table_check():
database = os.path.exists('/config/app.db')
if database == True:
log.info("Setup Helper: Going though the setup helper.")
continue_setup()
else:
create_table()
table_check()

def update_scheduler():
scheduler.remove_all_jobs()
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
c.execute("SELECT * FROM plex_utills")
config = c.fetchall()
c.close()
t1 = config[0][7]
t2 = config[0][8]
t3 = config[0][9]
t4 = config[0][10]
t5 = config[0][11]
if config[0][13] == 1:
scheduler.add_job('posters4k', func=posters4k, trigger='cron', hour=t1.split(":")[0], minute=t1.split(":")[1])
logger.info("4K/HDR Posters schedule created for "+ t1)
log.info("4K/HDR Posters schedule created for "+ t1)
if config[0][16] == 1:
scheduler.add_job('posters3d', func=posters3d, trigger='cron', hour=t5.split(":")[0], minute=t5.split(":")[1])
logger.info("3D Posters schedule created for "+ t5)
log.info("3D Posters schedule created for "+ t5)
if config[0][20] == 1:
scheduler.add_job('hide4k', func=hide4k, trigger='cron', hour=t4.split(":")[0], minute=t4.split(":")[1])
logger.info("Hide 4k schedule created for "+ t4)
log.info("Hide 4k schedule created for "+ t4)
if config[0][18] == 1:
scheduler.add_job('disney', func=disney, trigger='cron', hour=t2.split(":")[0], minute=t2.split(":")[1])
logger.info("Disney Collection schedule created for "+ t2)
log.info("Disney Collection schedule created for "+ t2)
if config[0][19] == 1:
scheduler.add_job('pixar', func=pixar, trigger='cron', hour=t3.split(":")[0], minute=t3.split(":")[1])
logger.info("Pixar Collection schedule created for "+ t3)
log.info("Pixar Collection schedule created for "+ t3)
try:
plex = PlexServer(config[0][1], config[0][2])
films = plex.library.section(config[0][3])
media_location = films.search()
filepath = os.path.dirname(os.path.dirname(media_location[0].media[0].parts[0].file))
plexpath = '/'+filepath.split('/')[1]
c.execute("UPDATE plex_utills SET plexpath = '"+plexpath+"' WHERE ID = 1;")
conn.commit()
c.close()
log.info("Updater: Your plexpath has been changed to "+plexpath)

except OSError as e:
if e.errno == 111:
log.warning("Updater: Cannont connect to your plex server, this may be because it is the first run and you haven't changed the config yet.")

def setup_helper():
scheduler.remove_all_jobs()
def create_table():
shutil.copy('app/static/default_db/default_app.db', '/config/app.db')
def continue_setup():
conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
c.execute("SELECT * FROM plex_utills")
config = c.fetchall()

logger.info("Setup Helper: Going though the setup helper.")



try:
plex = PlexServer(config[0][1], config[0][2])
films = plex.library.section(config[0][3])
media_location = films.search()
filepath = os.path.dirname(os.path.dirname(media_location[0].media[0].parts[0].file))
plexpath = '/'+filepath.split('/')[1]

c.execute("UPDATE plex_utills SET plexpath = '"+plexpath+"' WHERE ID = 1;")
conn.commit()
c.close()
logger.info("Setup Helper: Your plexpath has been changed to "+plexpath)

except OSError as e:
if e.errno == 111:
logger.warning("Setup Helper: Cannont connect to your plex server, this may be because it is the first run and you haven't changed the config yet.")

def table_check():
database = os.path.exists('/config/app.db')
if database == True:
continue_setup()
else:
create_table()
table_check()
SCHEDULER_API_ENABLED = True

class Plex_utills(Flask):
Expand All @@ -92,6 +100,8 @@ def run(self, host=None, port=None, debug=None, load_dotenv=True, **options):
super(Plex_utills, self).run(host=host, port=port, debug=debug, load_dotenv=load_dotenv, **options)




app = Plex_utills(__name__)
scheduler = APScheduler()
scheduler.init_app(app)
Expand Down
Empty file modified app/forms.py
100644 → 100755
Empty file.
Empty file modified app/img/3D-Template.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/3D-mini-Template.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/4K-Template.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/4K-mini-Template.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/4k-example.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/Examples/3D_banner.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/Examples/4k_banner.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/Examples/mini3d.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/Examples/mini4k.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/Examples/new_dolby_vision.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/Examples/new_hdr.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/Examples/new_hdr10.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/Examples/old_hdr.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/chk-3D-mini.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/chk-4k.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/chk-mini-4k.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/chk-mini-4k2.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/chk_3d_wide.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/chk_dolby_vision.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/chk_hdr.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/chk_hdr10.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/chk_hdr_new.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/dolby_vision.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/hdr-poster.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/hdr.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified app/img/hdr10.png
100644 → 100755
Empty file modified app/img/library_update_console.gif
100644 → 100755
Empty file modified app/img/library_update_sm.gif
100644 → 100755
Empty file modified app/img/logo.png
100644 → 100755
Empty file modified app/img/logo.svg
100644 → 100755
Empty file modified app/img/mini-4k-example.png
100644 → 100755
10 changes: 5 additions & 5 deletions app/models.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class Plex(db.Model):
token = db.Column(db.String)
filmslibrary = db.Column(db.String)
library3d = db.Column(db.String)
#plexpath = db.Column(db.String)
#mountedpath = db.Column(db.String)
plexpath = db.Column(db.String)
mountedpath = db.Column(db.String)
# Schedules
t1 = db.Column(db.String)
t2 = db.Column(db.String)
Expand All @@ -36,13 +36,13 @@ class Plex(db.Model):
recreate_hdr = db.Column(db.Integer)
new_hdr = db.Column(db.Integer)

def __init__(self, plexurl, token, filmslibrary, library3d, t1, t2, t3, t4, t5, backup, posters4k, mini4k, hdr, posters3d, mini3d, disney, pixar, hide4k, transcode, tvlibrary, tv4kposters, films4kposters, tmdb_api, tmdb_restore, recreate_hdr, new_hdr):
def __init__(self, plexurl, token, filmslibrary, library3d, plexpath, mountedpath, t1, t2, t3, t4, t5, backup, posters4k, mini4k, hdr, posters3d, mini3d, disney, pixar, hide4k, transcode, tvlibrary, tv4kposters, films4kposters, tmdb_api, tmdb_restore, recreate_hdr, new_hdr):
self.plexurl = plexurl
self.token = token
self.filmslibrary = filmslibrary
self.library3d = library3d
#self.plexpath = plexpath
#self.mountedpath = mountedpath
self.plexpath = plexpath
self.mountedpath = mountedpath
self.t1 = t1
self.t2 = t2
self.t3 = t3
Expand Down
111 changes: 86 additions & 25 deletions app/routes.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
from app.forms import AddRecord
from app.models import Plex
from time import sleep
from app import update_scheduler, posters4k, posters3d, hide4k, disney, pixar, migrate, restore_posters, fresh_hdr_posters
from app import update_scheduler, posters4k, posters3d, hide4k, disney, pixar, migrate, restore_posters, fresh_hdr_posters, setup_logger
import threading



setup_logger('SYS', r"/logs/application_log.log")
log = logging.getLogger('SYS')



@app.route('/')
Expand All @@ -26,36 +33,43 @@ def run_scripts():


@app.route('/posters4k', methods=['GET'])
def run_posters4k():
return posters4k()
def run_posters4k():
threading.Thread(target=posters4k).start()
return render_template('script_log_viewer.html', pagetitle='Script Logs')
@app.route('/posters3d', methods=['GET'])
def run_posters3d():
return posters3d()
threading.Thread(target=posters3d).start()
return render_template('script_log_viewer.html', pagetitle='Script Logs')
@app.route('/hide4k', methods=['GET'])
def run_hide4k():
return hide4k()
threading.Thread(target=hide4k).start()
return render_template('script_log_viewer.html', pagetitle='Script Logs')
@app.route('/disney', methods=['GET'])
def run_disney():
return disney()
threading.Thread(target=disney).start()
return render_template('script_log_viewer.html', pagetitle='Script Logs')
@app.route('/pixar', methods=['GET'])
def run_pixar():
return pixar()
def run_pixar():
threading.Thread(target=pixar).start()
return(render_template('script_log_viewer.html', pagetitle='Script Logs'))
@app.route('/restore', methods=['GET'])
def run_restore():
return restore_posters()

@app.route('/recreate_hdr', methods=['GET'])
threading.Thread(target=restore_posters).start()
return render_template('script_log_viewer.html', pagetitle='Script Logs')

@app.route('/recreate_hdr')
def run_recreate_hdr():
return render_template("/recreate_hdr.html", pagetitle='Recreate HDR Posters')

@app.route('/recreate_hdr_script', methods=['GET'])
@app.route('/recreate_hdr_script')
def run_recreate_hdr_script():
return fresh_hdr_posters()

threading.Thread(target=fresh_hdr_posters).start()
return render_template('script_log_viewer.html', pagetitle='Script Logs')

@app.route('/migrate', methods=['GET', 'POST'])
@app.route('/migrate')
def run_migrate():
return render_template('migrate.html', pagetitle='Config Migration')

@app.route('/start_migrate', methods=['GET', 'POST'])
def start_migrate():
migrate()
Expand All @@ -68,21 +82,22 @@ def script_logs():
@app.route("/script_log_stream", methods=["GET"])
def script_stream():
def script_generate():
with open('/logs/script_log.log') as f:
while True:
yield f.read()
sleep(0.1)
return app.response_class(script_generate(), mimetype='text/plain')
with open('/logs/script_log.log', "rb") as f:
while chunk := f.read(1024 * 10):
yield chunk
return app.response_class(script_generate(), mimetype='text/plain')



@app.route('/view_application_logs')
def application_logs():
return render_template('application_log_viewer.html', pagetitle='Applciation Logs')
return render_template('application_log_viewer.html', pagetitle='Application Logs')
@app.route("/application_log_stream", methods=["GET"])
def stream():
def generate():
with open('/logs/application_log.log') as f:
while True:
yield f.read()
sleep(0.1)
with open('/logs/application_log.log', "rb") as f:
while chunk := f.read(1024):
yield chunk
return app.response_class(generate(), mimetype='text/plain')


Expand Down Expand Up @@ -173,3 +188,49 @@ def internal_server_error(e):
return render_template('error.html', pagetitle="500 Error - Internal Server Error", pageheading="Internal server error (500)", error=e), 500


@app.route('/help')
def help():
import sqlite3
import os
from plexapi.server import PlexServer
import re
import requests
import shutil
plex = Plex.query.filter(Plex.id == '1').all()

conn = sqlite3.connect('/config/app.db')
c = conn.cursor()
c.execute("SELECT * FROM plex_utills")
config = c.fetchall()

plexserver = PlexServer(config[0][1], config[0][2])
films = plexserver.library.section(config[0][3])
media_location = films.search()
filepath = os.path.dirname(os.path.dirname(media_location[0].media[0].parts[0].file))
convertedfilepath = re.sub(config[0][5], '/films', filepath)


def get_poster():
newdir = os.path.dirname(re.sub(config[0][5], '/films', i.media[0].parts[0].file))+'/'
backup = os.path.exists(newdir+'poster_bak.png')
imgurl = i.posterUrl
img = requests.get(imgurl, stream=True)
filename = "poster.png"
if img.status_code == 200:
img.raw.decode_content = True
with open(filename, 'wb') as f:
shutil.copyfileobj(img.raw, f)
shutil.copy(filename, './app/static/img/poster.png')
if backup == True:
poster_bak = os.path.join(newdir+'poster_bak.png')
shutil.copy(poster_bak, './app/static/img/poster_bak.png')

for i in films.search(resolution='4k'):
get_poster()
plex_filepath = i.media[0].parts[0].file
filmtitle = i.title
newdir = re.sub(config[0][5], '/films', i.media[0].parts[0].file)
break
return render_template('help.html', pagetitle='Help', plex=plex, plex_filepath=plex_filepath, filmtitle=filmtitle, newdir=newdir, pageheadding='Help')


Loading