removed debug print of video thumbnail, and made file importer look to see if file is newer than last import, if so, process it and store it in the database. If its older skip it. Then at the end of the function return the database as the list we process
This commit is contained in:
57
files.py
57
files.py
@@ -14,6 +14,7 @@ import exifread
|
||||
import base64
|
||||
import numpy
|
||||
import cv2
|
||||
import time
|
||||
|
||||
################################################################################
|
||||
# Local Class imports
|
||||
@@ -91,7 +92,6 @@ class FileData():
|
||||
bt = thumb_buf.tostring()
|
||||
fthumbnail = base64.b64encode(bt)
|
||||
fthumbnail = str(fthumbnail)[2:-1]
|
||||
print(fthumbnail)
|
||||
return fthumbnail
|
||||
|
||||
|
||||
@@ -100,8 +100,10 @@ class FileData():
|
||||
# multiple valid paths in import_path) #
|
||||
##############################################################################
|
||||
def GenerateFileData(self):
|
||||
sets = Settings.query.filter(Settings.name=="import_path").all()
|
||||
paths= sets[0].value.split("#")
|
||||
import_path = Settings.query.filter(Settings.name=="import_path").all()[0].value
|
||||
last_import_date_obj = Settings.query.filter(Settings.name=="last_import_date").all()
|
||||
last_import_date = float(last_import_date_obj[0].value)
|
||||
paths= import_path.split("#")
|
||||
|
||||
for path in paths:
|
||||
path = self.FixPath(path)
|
||||
@@ -115,28 +117,39 @@ class FileData():
|
||||
|
||||
self.file_list.append(glob.glob(self.view_path + '**', recursive=True))
|
||||
for file in self.file_list[0]:
|
||||
fthumbnail = None
|
||||
if file == path:
|
||||
continue
|
||||
if os.path.isdir(file):
|
||||
ftype = 'Directory'
|
||||
elif self.isImage(file):
|
||||
ftype = 'Image'
|
||||
fthumbnail = self.getExif(file)
|
||||
elif self.isVideo(file):
|
||||
ftype = 'Video'
|
||||
fthumbnail = self.generateVideoThumbnail(file)
|
||||
else:
|
||||
ftype = 'File'
|
||||
stat = os.stat(file)
|
||||
if last_import_date == 0 or stat.st_ctime > last_import_date:
|
||||
print( "{} - {} is newer than {}".format( file, stat.st_ctime, last_import_date ) )
|
||||
fthumbnail = None
|
||||
if os.path.isdir(file):
|
||||
ftype = 'Directory'
|
||||
elif self.isImage(file):
|
||||
ftype = 'Image'
|
||||
fthumbnail = self.getExif(file)
|
||||
elif self.isVideo(file):
|
||||
ftype = 'Video'
|
||||
fthumbnail = self.generateVideoThumbnail(file)
|
||||
else:
|
||||
ftype = 'File'
|
||||
|
||||
if ftype != "Directory":
|
||||
fhash=self.md5(file)
|
||||
else:
|
||||
fhash=None
|
||||
if ftype != "Directory":
|
||||
fhash=self.md5(file)
|
||||
else:
|
||||
fhash=None
|
||||
|
||||
fsize = round(os.stat(file).st_size/(1024*1024))
|
||||
fname=file.replace(path, "")
|
||||
self.view_list.append( Files( name=fname, type=ftype, size_mb=fsize, hash=fhash, thumbnail=fthumbnail ))
|
||||
fsize = round(os.stat(file).st_size/(1024*1024))
|
||||
fname=file.replace(path, "")
|
||||
file_obj = Files( name=fname, type=ftype, size_mb=fsize, hash=fhash, thumbnail=fthumbnail )
|
||||
print( file_obj )
|
||||
db.session.add(file_obj)
|
||||
else:
|
||||
print( "{} - {} is OLDER than {}".format( file, stat.st_ctime, last_import_date ) )
|
||||
last_import_date_obj[0].value = str(time.time())
|
||||
db.session.commit()
|
||||
file_obj = Files.query.filter().all()
|
||||
self.view_list = file_obj
|
||||
return self
|
||||
|
||||
################################################################################
|
||||
@@ -150,7 +163,7 @@ class Files(db.Model):
|
||||
size_mb = 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=True)
|
||||
thumbnail = db.Column(db.LargeBinary, unique=False, nullable=True)
|
||||
thumbnail = db.Column(db.String, unique=False, nullable=True)
|
||||
|
||||
def __repr__(self):
|
||||
return "<id: {}, name: {}>".format(self.id, self.name )
|
||||
|
||||
Reference in New Issue
Block a user