checking for duplicates and existing files
parent
c5a8280b19
commit
58d6332748
8
app.py
8
app.py
|
@ -410,10 +410,14 @@ def camera_list_of_videos(esn=None):
|
||||||
|
|
||||||
for v in camera.videos:
|
for v in camera.videos:
|
||||||
try:
|
try:
|
||||||
|
|
||||||
check_video = Download.query.filter(Download.camera_id == db_camera.id)\
|
check_video = Download.query.filter(Download.camera_id == db_camera.id)\
|
||||||
.filter(Download.start_timestamp == v['startTimestamp'])\
|
.filter(Download.start_timestamp == datetime.fromisoformat(v['startTimestamp']))\
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
|
|
||||||
if check_video is None:
|
if check_video is None:
|
||||||
|
logging.debug(f"creating a new record for {db_camera.id} {v['startTimestamp']}")
|
||||||
new_video = Download(url=v['mp4Url'],\
|
new_video = Download(url=v['mp4Url'],\
|
||||||
camera_id=db_camera.id,\
|
camera_id=db_camera.id,\
|
||||||
start_timestamp=datetime.fromisoformat(v['startTimestamp']),\
|
start_timestamp=datetime.fromisoformat(v['startTimestamp']),\
|
||||||
|
@ -422,7 +426,7 @@ def camera_list_of_videos(esn=None):
|
||||||
error=None)
|
error=None)
|
||||||
new_video.save()
|
new_video.save()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.warn(f"saving videos to db: {e}")
|
logging.warn(f"Exception saving videos to db: {e}")
|
||||||
|
|
||||||
values = {
|
values = {
|
||||||
"current_user": een.current_user,
|
"current_user": een.current_user,
|
||||||
|
|
|
@ -54,11 +54,12 @@ def download(args):
|
||||||
|
|
||||||
fname = f"{path}/{camera_device_id}_{start}-{end}.mp4"
|
fname = f"{path}/{camera_device_id}_{start}-{end}.mp4"
|
||||||
|
|
||||||
|
if os.path.isfile(fname) == False:
|
||||||
|
|
||||||
save_result = cam.save_video_to_file(url=row[1], filename=fname)
|
save_result = cam.save_video_to_file(url=row[1], filename=fname)
|
||||||
|
save_code = save_result['response_http_status']
|
||||||
|
|
||||||
match save_result['response_http_status']:
|
match save_code:
|
||||||
case 200:
|
case 200:
|
||||||
save_status = 'done'
|
save_status = 'done'
|
||||||
case 400 | 404 | 409:
|
case 400 | 404 | 409:
|
||||||
|
@ -70,11 +71,16 @@ def download(args):
|
||||||
case _:
|
case _:
|
||||||
save_status = 'unknown failure'
|
save_status = 'unknown failure'
|
||||||
|
|
||||||
|
else:
|
||||||
|
# file exists, don't do anything and mark as done
|
||||||
|
save_status = 'already exists'
|
||||||
|
save_code = None
|
||||||
|
|
||||||
new_cur = con.cursor()
|
new_cur = con.cursor()
|
||||||
new_cur.execute("update download set status = ?, error = ? where download.id == ?;", (save_status, save_result['response_http_status'], row[0]))
|
new_cur.execute("update download set status = ?, error = ? where download.id == ?;", (save_status, save_code, row[0]))
|
||||||
con.commit()
|
con.commit()
|
||||||
|
|
||||||
return (save_result['response_http_status'], row[0])
|
return (save_code, row[0])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue