From aa537c5ae7e69bcc007ee5ecdda93589ba32fc49 Mon Sep 17 00:00:00 2001 From: Damien De Paoli Date: Sun, 10 Jan 2021 20:16:12 +1100 Subject: [PATCH] moved funcs around so routes are at the bottom of photos.py, created a static route will have to use symlinks to get it to work, but trying this first on windows to see --- photos.py | 76 ++++++++++++++++++++-------------------- static/images_to_process | 1 + templates/photos.html | 3 ++ 3 files changed, 42 insertions(+), 38 deletions(-) create mode 120000 static/images_to_process diff --git a/photos.py b/photos.py index 3996022..8976b34 100644 --- a/photos.py +++ b/photos.py @@ -1,6 +1,6 @@ from wtforms import SubmitField, StringField, HiddenField, validators, Form from flask_wtf import FlaskForm -from flask import request, render_template, redirect +from flask import request, render_template, redirect, send_from_directory from main import db, app, ma from sqlalchemy import Sequence from sqlalchemy.exc import SQLAlchemyError @@ -29,6 +29,38 @@ def md5(fname): hash_md5.update(chunk) return hash_md5.hexdigest() +def isImage(file): + try: + img = Image.open(file) + return True + except: + return False + +def isVideo(file): + try: + fileInfo = MediaInfo.parse(file) + for track in fileInfo.tracks: + if track.track_type == "Video": + return True + return False + except Exception as e: + return False + +def getExif(file): + f = open(file, 'rb') + try: + tags = exifread.process_file(f) + except: + print('NO EXIF TAGS?!?!?!?') + f.close() + raise + f.close() + + fthumbnail = base64.b64encode(tags['JPEGThumbnail']) + fthumbnail = str(fthumbnail)[2:-1] + + return fthumbnail + ################################################################################ # Class describing Photos in the database, and via sqlalchemy, connected to the DB as well ################################################################################ @@ -76,50 +108,18 @@ def photos(): else: ftype = 'File' - if ftype != "Directory": fhash=md5(file) else: fhash=None - - fsize = round(os.stat(file).st_size/(1024*1024)) - view_list.append( Photos( name=file, type=ftype, size_MB=fsize, hash=fhash, thumbnail=fthumbnail )) - - + fname=file.replace(p, "") + view_list.append( Photos( name=fname, type=ftype, size_MB=fsize, hash=fhash, thumbnail=fthumbnail )) return render_template("photos.html", page_title='View Photos', view_path=view_path, file_list=view_list, alert=st.GetAlert(), message=st.GetMessage() ) +@app.route("/static/") +def custom_static(filename): + return send_from_directory("static/", filename) -def isImage(file): - try: - img = Image.open(file) - return True - except: - return False - -def isVideo(file): - try: - fileInfo = MediaInfo.parse(file) - for track in fileInfo.tracks: - if track.track_type == "Video": - return True - return False - except Exception as e: - return False - -def getExif(file): - f = open(file, 'rb') - try: - tags = exifread.process_file(f) - except: - print('NO EXIF TAGS?!?!?!?') - f.close() - raise - f.close() - - fthumbnail = base64.b64encode(tags['JPEGThumbnail']) - fthumbnail = str(fthumbnail)[2:-2] - - return fthumbnail \ No newline at end of file diff --git a/static/images_to_process b/static/images_to_process new file mode 120000 index 0000000..ac0a0a8 --- /dev/null +++ b/static/images_to_process @@ -0,0 +1 @@ +../images_to_process/ \ No newline at end of file diff --git a/templates/photos.html b/templates/photos.html index 8ef4ad6..f2719f8 100644 --- a/templates/photos.html +++ b/templates/photos.html @@ -17,6 +17,9 @@ {% endif %}  {{obj.name}} {% if obj.type=="Image" %} + {% endif %} {{obj.size_MB}}{{obj.hash}}