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
+42 -4
View File
@@ -33,6 +33,44 @@ DEFAULT_DESTINATION = os.path.join(
os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "dash", "videos"
)
_device_lock = threading.Lock()
_local_video_state_lock = threading.Lock()
_local_videos_in_use = {}
_local_videos_deleting = set()
def begin_local_video_use(relative_path):
with _local_video_state_lock:
if relative_path in _local_videos_deleting:
return False
_local_videos_in_use[relative_path] = (
_local_videos_in_use.get(relative_path, 0) + 1
)
return True
def end_local_video_use(relative_path):
with _local_video_state_lock:
uses = _local_videos_in_use.get(relative_path, 0)
if uses <= 1:
_local_videos_in_use.pop(relative_path, None)
else:
_local_videos_in_use[relative_path] = uses - 1
def begin_local_video_delete(relative_path):
with _local_video_state_lock:
if (
relative_path in _local_videos_in_use
or relative_path in _local_videos_deleting
):
return False
_local_videos_deleting.add(relative_path)
return True
def end_local_video_delete(relative_path):
with _local_video_state_lock:
_local_videos_deleting.discard(relative_path)
def list_usb_storage_partitions():
@@ -275,7 +313,7 @@ def list_dashcam_files(mount_point=DEFAULT_MOUNT_POINT):
unmount_device(mount_point)
def _safe_video_path(source_folder, relative_path):
def safe_video_path(source_folder, relative_path):
if not isinstance(relative_path, str) or not relative_path.strip():
raise ValueError("A non-empty relative video path is required.")
if os.path.isabs(relative_path):
@@ -337,7 +375,7 @@ def delete_dashcam_files(relative_path=None, delete_all=False, mount_point=DEFAU
targets = find_video_files(source)
else:
try:
target = _safe_video_path(source, relative_path)
target = safe_video_path(source, relative_path)
except ValueError as e:
result = {"status": "invalid_path", "message": str(e)}
except FileNotFoundError:
@@ -353,7 +391,7 @@ def delete_dashcam_files(relative_path=None, delete_all=False, mount_point=DEFAU
errors = []
for _abs_path, rel_path in targets:
try:
safe_path = _safe_video_path(source, rel_path)
safe_path = safe_video_path(source, rel_path)
_remove_video_file(safe_path)
deleted.append(rel_path)
except (OSError, ValueError) as e:
@@ -413,7 +451,7 @@ def copy_files(source_folder, destination_folder, relative_paths=None):
continue
seen.add(relative_path)
try:
abs_path = _safe_video_path(source_folder, relative_path)
abs_path = safe_video_path(source_folder, relative_path)
except ValueError as e:
return {
"found": 0,