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:
2021-01-12 13:49:05 +11:00
parent 6e67bcd803
commit 4c662b3a0e

View File

@@ -14,6 +14,7 @@ import exifread
import base64 import base64
import numpy import numpy
import cv2 import cv2
import time
################################################################################ ################################################################################
# Local Class imports # Local Class imports
@@ -91,7 +92,6 @@ class FileData():
bt = thumb_buf.tostring() bt = thumb_buf.tostring()
fthumbnail = base64.b64encode(bt) fthumbnail = base64.b64encode(bt)
fthumbnail = str(fthumbnail)[2:-1] fthumbnail = str(fthumbnail)[2:-1]
print(fthumbnail)
return fthumbnail return fthumbnail
@@ -100,8 +100,10 @@ class FileData():
# multiple valid paths in import_path) # # multiple valid paths in import_path) #
############################################################################## ##############################################################################
def GenerateFileData(self): def GenerateFileData(self):
sets = Settings.query.filter(Settings.name=="import_path").all() import_path = Settings.query.filter(Settings.name=="import_path").all()[0].value
paths= sets[0].value.split("#") 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: for path in paths:
path = self.FixPath(path) path = self.FixPath(path)
@@ -115,28 +117,39 @@ class FileData():
self.file_list.append(glob.glob(self.view_path + '**', recursive=True)) self.file_list.append(glob.glob(self.view_path + '**', recursive=True))
for file in self.file_list[0]: for file in self.file_list[0]:
fthumbnail = None
if file == path: if file == path:
continue continue
if os.path.isdir(file): stat = os.stat(file)
ftype = 'Directory' if last_import_date == 0 or stat.st_ctime > last_import_date:
elif self.isImage(file): print( "{} - {} is newer than {}".format( file, stat.st_ctime, last_import_date ) )
ftype = 'Image' fthumbnail = None
fthumbnail = self.getExif(file) if os.path.isdir(file):
elif self.isVideo(file): ftype = 'Directory'
ftype = 'Video' elif self.isImage(file):
fthumbnail = self.generateVideoThumbnail(file) ftype = 'Image'
else: fthumbnail = self.getExif(file)
ftype = 'File' elif self.isVideo(file):
ftype = 'Video'
fthumbnail = self.generateVideoThumbnail(file)
else:
ftype = 'File'
if ftype != "Directory": if ftype != "Directory":
fhash=self.md5(file) fhash=self.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))
fname=file.replace(path, "") fname=file.replace(path, "")
self.view_list.append( Files( name=fname, type=ftype, size_mb=fsize, hash=fhash, thumbnail=fthumbnail )) 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 return self
################################################################################ ################################################################################
@@ -150,7 +163,7 @@ class Files(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)
thumbnail = db.Column(db.LargeBinary, unique=False, nullable=True) thumbnail = db.Column(db.String, 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 )