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
This commit is contained in:
76
photos.py
76
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/<filename>")
|
||||
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
|
||||
1
static/images_to_process
Symbolic link
1
static/images_to_process
Symbolic link
@@ -0,0 +1 @@
|
||||
../images_to_process/
|
||||
@@ -17,6 +17,9 @@
|
||||
{% endif %}
|
||||
{{obj.name}}
|
||||
{% if obj.type=="Image" %}
|
||||
<!--
|
||||
<img width="64" height="64" src="{{obj.name}}"></img>
|
||||
-->
|
||||
<img width="64" height="64" src="data:image/jpeg;base64,{{obj.thumbnail}}"></img>
|
||||
{% endif %}
|
||||
</td></td><td>{{obj.size_MB}}</td><td>{{obj.hash}}</tr>
|
||||
|
||||
Reference in New Issue
Block a user