diff --git a/app.py b/app.py index cda93ff..d8d6d73 100644 --- a/app.py +++ b/app.py @@ -410,10 +410,14 @@ def camera_list_of_videos(esn=None): for v in camera.videos: try: + 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() + + if check_video is None: + logging.debug(f"creating a new record for {db_camera.id} {v['startTimestamp']}") new_video = Download(url=v['mp4Url'],\ camera_id=db_camera.id,\ start_timestamp=datetime.fromisoformat(v['startTimestamp']),\ @@ -422,7 +426,7 @@ def camera_list_of_videos(esn=None): error=None) new_video.save() except Exception as e: - logging.warn(f"saving videos to db: {e}") + logging.warn(f"Exception saving videos to db: {e}") values = { "current_user": een.current_user, diff --git a/download_worker.py b/download_worker.py index 7fde3f2..c84467e 100644 --- a/download_worker.py +++ b/download_worker.py @@ -54,27 +54,33 @@ def download(args): 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_code = save_result['response_http_status'] - save_result = cam.save_video_to_file(url=row[1], filename=fname) - - match save_result['response_http_status']: - case 200: - save_status = 'done' - case 400 | 404 | 409: - save_status = 'client failure' - case 401 | 403: - save_status = 'auth failure' - case 500 | 502 | 503 | 504: - save_status = 'cloud failure' - case _: - save_status = 'unknown failure' + match save_code: + case 200: + save_status = 'done' + case 400 | 404 | 409: + save_status = 'client failure' + case 401 | 403: + save_status = 'auth failure' + case 500 | 502 | 503 | 504: + save_status = 'cloud failure' + case _: + 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.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() - return (save_result['response_http_status'], row[0]) + return (save_code, row[0])