updated readme and gitignore, and also update the photos.py file to check what file types everything are, then return back a python dict with the absolute path to a file and the type. also updated the sqlalchemy model class to better fit all of our changes (added some fields that correspond to our file types and such).
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
||||
__pycache__/
|
||||
photos/
|
||||
5
README
5
README
@@ -1 +1,6 @@
|
||||
In here we can put instructions on how to run this / any general info
|
||||
|
||||
pip packages:
|
||||
* pymediainfo
|
||||
* PIL (should be there by default)
|
||||
*
|
||||
45
photos.py
45
photos.py
@@ -7,6 +7,9 @@ from sqlalchemy.exc import SQLAlchemyError
|
||||
from status import st, Status
|
||||
import os
|
||||
from os import path
|
||||
import glob
|
||||
from PIL import Image
|
||||
from pymediainfo import MediaInfo
|
||||
|
||||
from settings import Settings
|
||||
|
||||
@@ -14,9 +17,15 @@ from settings import Settings
|
||||
################################################################################
|
||||
# Class describing Author in the database, and via sqlalchemy, connected to the DB as well
|
||||
################################################################################
|
||||
|
||||
# photos might not be the best name... more than just photos live in this class currently
|
||||
class Photos(db.Model):
|
||||
id = db.Column(db.Integer, db.Sequence('photos_id_seq'), primary_key=True )
|
||||
name = db.Column(db.String, unique=True, nullable=True )
|
||||
name = db.Column(db.String, unique=True, nullable=False )
|
||||
type = db.Column(db.String, unique=False, nullable=False)
|
||||
size = db.Column(db.Integer, unique=False, nullable=False)
|
||||
# hash might not be unique, this could be the source of dupe problems
|
||||
hash = db.Column(db.Integer, unique=True, nullable=False)
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, name: {}>".format(self.id, self.name )
|
||||
@@ -28,11 +37,43 @@ class Photos(db.Model):
|
||||
def photos():
|
||||
sets = Settings.query.filter(Settings.name=="import_path").all()
|
||||
paths= sets[0].value.split("#")
|
||||
image_list=""
|
||||
file_list=[]
|
||||
file_types = {}
|
||||
view_path=""
|
||||
for p in paths:
|
||||
if p.startswith('c:'):
|
||||
p = p.replace('/', '\\')
|
||||
if( path.exists( p ) ):
|
||||
view_path = p
|
||||
file_list.append(glob.glob(view_path + '**', recursive=True))
|
||||
for file in file_list[0]:
|
||||
if os.path.isdir(file):
|
||||
file_types[file] = 'Directory'
|
||||
elif isImage(file):
|
||||
file_types[file] = 'Image'
|
||||
elif isVideo(file):
|
||||
file_types[file] = 'Video'
|
||||
else:
|
||||
file_types[file] = 'File'
|
||||
print(file_types)
|
||||
|
||||
return render_template("photos.html", page_title='View Photos', view_path=view_path, alert=st.GetAlert(), message=st.GetMessage() )
|
||||
|
||||
|
||||
def isImage(file):
|
||||
try:
|
||||
img = Image.open(file)
|
||||
return True
|
||||
except:
|
||||
print('not an image')
|
||||
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:
|
||||
return False
|
||||
Reference in New Issue
Block a user