WARNING: CURRENTLY BROKEN... updated photos.py to use exif data for thumbnails, and templates/photos.html to reflect changes
This commit is contained in:
29
photos.py
29
photos.py
@@ -10,6 +10,8 @@ import glob
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
from pymediainfo import MediaInfo
|
from pymediainfo import MediaInfo
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import exifread
|
||||||
|
import base64
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Local Class imports
|
# Local Class imports
|
||||||
@@ -39,7 +41,7 @@ class Photos(db.Model):
|
|||||||
size_MB = db.Column(db.Integer, unique=False, nullable=False)
|
size_MB = db.Column(db.Integer, unique=False, nullable=False)
|
||||||
# hash might not be unique, this could be the source of dupe problems
|
# hash might not be unique, this could be the source of dupe problems
|
||||||
hash = db.Column(db.Integer, unique=True, nullable=True)
|
hash = db.Column(db.Integer, unique=True, nullable=True)
|
||||||
thumnbnail = db.Column(db.BYTE, unique=False, nullable=False)
|
thumbnail = db.Column(db.LargeBinary, unique=False, nullable=True)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<id: {}, name: {}>".format(self.id, self.name )
|
return "<id: {}, name: {}>".format(self.id, self.name )
|
||||||
@@ -61,10 +63,14 @@ def photos():
|
|||||||
view_path = p
|
view_path = p
|
||||||
file_list.append(glob.glob(view_path + '**', recursive=True))
|
file_list.append(glob.glob(view_path + '**', recursive=True))
|
||||||
for file in file_list[0]:
|
for file in file_list[0]:
|
||||||
|
fthumbnail = None
|
||||||
|
if file == p:
|
||||||
|
continue
|
||||||
if os.path.isdir(file):
|
if os.path.isdir(file):
|
||||||
ftype = 'Directory'
|
ftype = 'Directory'
|
||||||
elif isImage(file):
|
elif isImage(file):
|
||||||
ftype = 'Image'
|
ftype = 'Image'
|
||||||
|
fthumbnail = getExif(file)
|
||||||
elif isVideo(file):
|
elif isVideo(file):
|
||||||
ftype = 'Video'
|
ftype = 'Video'
|
||||||
else:
|
else:
|
||||||
@@ -75,8 +81,13 @@ def photos():
|
|||||||
fhash=md5(file)
|
fhash=md5(file)
|
||||||
else:
|
else:
|
||||||
fhash=None
|
fhash=None
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
fsize = round(os.stat(file).st_size/(1024*1024))
|
fsize = round(os.stat(file).st_size/(1024*1024))
|
||||||
view_list.append( Photos( name=file, type=ftype, size_MB=fsize, hash=fhash ))
|
view_list.append( Photos( name=file, 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() )
|
return render_template("photos.html", page_title='View Photos', view_path=view_path, file_list=view_list, alert=st.GetAlert(), message=st.GetMessage() )
|
||||||
|
|
||||||
@@ -97,3 +108,17 @@ def isVideo(file):
|
|||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return False
|
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'])
|
||||||
|
|
||||||
|
return fthumbnail
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
{{obj.name}}
|
{{obj.name}}
|
||||||
{% if obj.type=="Image" %}
|
{% if obj.type=="Image" %}
|
||||||
<img width="64" height="64" src="data:image/gif;base64,{{obj.thumb}}"></img>
|
<img width="64" height="64" src="data:image/jpg;base64,{{obj.thumbnail}}"></img>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td></td><td>{{obj.size_MB}}</td><td>{{obj.hash}}</tr>
|
</td></td><td>{{obj.size_MB}}</td><td>{{obj.hash}}</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
Reference in New Issue
Block a user