Add local dashcam video library

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-09 19:04:47 -04:00
co-authored by Copilot
parent c57457b934
commit 3a981f5c6d
14 changed files with 659 additions and 29 deletions
+20 -6
View File
@@ -43,7 +43,7 @@ import requests
from dotenv import load_dotenv
from requests_toolbelt import MultipartEncoder
from modules import app_sql, app_dash, app_cellular
from modules import app_sql, app_dash, app_cellular, app_video
_BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
load_dotenv(os.path.join(_BASE_DIR, "db", "upload_creds.env"))
@@ -253,13 +253,20 @@ def _upload_dashcam_files():
uploaded_count = 0
for abs_path, rel_path in app_dash.find_video_files(app_dash.DEFAULT_DESTINATION):
sha256 = _hash_dashcam_file(abs_path, rel_path)
if app_sql.dashcam_file_marked_uploaded(rel_path, sha256):
if not app_dash.begin_local_video_use(rel_path):
continue
try:
if not os.path.isfile(abs_path):
continue
sha256 = _hash_dashcam_file(abs_path, rel_path)
if app_sql.dashcam_file_marked_uploaded(rel_path, sha256):
continue
_upload_video_chunked(abs_path, rel_path, sha256)
app_sql.mark_dashcam_file_uploaded(rel_path, sha256)
uploaded_count += 1
_upload_video_chunked(abs_path, rel_path, sha256)
app_sql.mark_dashcam_file_uploaded(rel_path, sha256)
uploaded_count += 1
finally:
app_dash.end_local_video_use(rel_path)
# Re-check between files so flipping the toggle off mid-run stops
# further uploads promptly without waiting for the next cycle.
@@ -281,8 +288,15 @@ def _upload_loop():
try:
sent = _upload_tracking_batch()
uploaded = _upload_dashcam_files()
cleanup = app_video.cleanup_uploaded_videos()
if sent or uploaded:
print(f"Upload: sent {sent} tracking rows, {uploaded} dashcam files")
if cleanup["deleted"]:
print(
f"Retention: deleted {len(cleanup['deleted'])} uploaded local videos"
)
if cleanup["errors"]:
print("Retention cleanup errors:", "; ".join(cleanup["errors"]))
_last_error = None
_last_success_at = _dt.datetime.now().isoformat()
backoff = BACKOFF_INITIAL