try/except for video thumb, it fails on 2 videos so far, also fixed same name diff file in AddFile()

This commit is contained in:
2021-01-28 13:11:02 +11:00
parent 5a8e139263
commit 9f2943a4d6

View File

@@ -250,6 +250,7 @@ def ProcessImportDirs(parent_job=None):
job2.extra.append(jex2)
session.add(job2)
session.commit()
"""
if parent_job:
AddLogForJob(parent_job, "adding <a href='/job/{}'>job id={} {}</a> (wait for: {})".format( job2.id, job2.id, job2.name, job2.wait_for ) )
jex3=JobExtra( name="path", value=path )
@@ -259,6 +260,7 @@ def ProcessImportDirs(parent_job=None):
session.commit()
if parent_job:
AddLogForJob(parent_job, "adding <a href='/job/{}'>job id={} {}</a> (wait for: {})".format( job3.id, job3.id, job3.name, job3.wait_for ) )
"""
HandleJobs()
return
@@ -414,10 +416,8 @@ def AddDir(job, dirname, path_prefix, in_dir):
return dir
def AddFile(job, fname, type_str, fsize, in_dir ):
# see if this exists already
e=session.query(Entry).filter(Entry.name==fname).first()
e=session.query(Entry).join(EntryDirLink).join(Dir).filter(Entry.name==fname,Dir.eid==in_dir.eid).first()
if e:
print(f"in theory we reset file: {e.name} back to on fs")
e.exists_on_fs=True
return e
ftype = session.query(FileType).filter(FileType.name==type_str).first()
@@ -714,7 +714,6 @@ def isImage(file):
return False
def GenImageThumbnail(job, file):
thumbnail=None
AddLogForJob( job, "Generate Thumbnail from Image file: {}".format( file ), file )
try:
im_orig = Image.open(file)
@@ -725,23 +724,27 @@ def GenImageThumbnail(job, file):
img_bytearray = img_bytearray.getvalue()
thumbnail = base64.b64encode(img_bytearray)
thumbnail = str(thumbnail)[2:-1]
except:
except Exception as e:
print('WARNING: NO EXIF TAGS?!?!?!?')
AddLogForJob(job, "WARNING: No EXIF TAF found for: {}".format(file))
AddLogForJob(job, f"WARNING: No EXIF TAF found for: {file} - error={e}")
return None
return thumbnail
def GenVideoThumbnail(job, file):
AddLogForJob( job, "Generate Thumbnail from Video file: {}".format( file ), file )
vcap = cv2.VideoCapture(file)
res, im_ar = vcap.read()
while im_ar.mean() < 15 and res:
try:
vcap = cv2.VideoCapture(file)
res, im_ar = vcap.read()
im_ar = cv2.resize(im_ar, (160, 90), 0, 0, cv2.INTER_LINEAR)
res, thumb_buf = cv2.imencode('.jpeg', im_ar)
bt = thumb_buf.tobytes()
thumbnail = base64.b64encode(bt)
thumbnail = str(thumbnail)[2:-1]
while im_ar.mean() < 15 and res:
res, im_ar = vcap.read()
im_ar = cv2.resize(im_ar, (160, 90), 0, 0, cv2.INTER_LINEAR)
res, thumb_buf = cv2.imencode('.jpeg', im_ar)
bt = thumb_buf.tobytes()
thumbnail = base64.b64encode(bt)
thumbnail = str(thumbnail)[2:-1]
except Exception as e:
AddLogForJob( job, f"ERROR: Failed to Generate thumbnail for video file: {file} - error={e}" )
return None
return thumbnail
if __name__ == "__main__":