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