Support both GoPro (THM/LRV) and Garmin Varia (GLV) sidecar files. Rename CLEANUP_GOPRO_SIDECARS to CLEANUP_MEDIA_SIDECARS and refactor to use device-specific detection functions. New --keep-sidecars flag replaces --keep-gopro-sidecars for broader applicability. - Add is_garmin_media_file() for VIRB*.MP4 detection - Add get_device_sidecar_extensions() for device-specific mappings - Rename cleanup_gopro_sidecars() to cleanup_media_sidecars() - Update help text and variable names for clarity Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@@ -23,7 +23,7 @@ UNATTENDED=0 # when 1, never prompt; destination conflicts get numeric su |
||
| 23 | 23 |
DRY_RUN=0 |
| 24 | 24 |
VERBOSE=0 |
| 25 | 25 |
CLEANUP_EMPTY_DIRS=1 |
| 26 |
-CLEANUP_GOPRO_SIDECARS=1 # when 1, delete THM/LRV sidecars after successful MP4 import |
|
| 26 |
+CLEANUP_MEDIA_SIDECARS=1 # when 1, delete device sidecars (GoPro THM/LRV, Garmin GLV) after successful import |
|
| 27 | 27 |
CONFLICT_APPLY_ALL="" # suffix|skip after an interactive "all similar" choice |
| 28 | 28 |
RESOLVED_DESTINATION_PATH="" |
| 29 | 29 |
RESERVED_DESTINATION_PATHS=() |
@@ -110,7 +110,7 @@ Options: |
||
| 110 | 110 |
--sync-metadata Write chosen date into destination metadata (automatic for GoPro filesystem dates) |
| 111 | 111 |
--unattended Never prompt; resolve destination conflicts with numeric suffixes |
| 112 | 112 |
--collect-unsortable Put files without dates into DEST/unsortable |
| 113 |
- --keep-gopro-sidecars Keep GoPro THM and LRV sidecar files (default: delete after import) |
|
| 113 |
+ --keep-sidecars Keep device sidecar files (default: delete after import) |
|
| 114 | 114 |
--keep-empty-dirs Keep empty directories after processing |
| 115 | 115 |
--dry-run Show actions without changing files |
| 116 | 116 |
-v, --verbose Verbose output |
@@ -476,6 +476,24 @@ is_gopro_media_file() {
|
||
| 476 | 476 |
[[ "$filename" =~ ^G[HPX][0-9]{6}\.[Mm][Pp]4$ ]]
|
| 477 | 477 |
} |
| 478 | 478 |
|
| 479 |
+is_garmin_media_file() {
|
|
| 480 |
+ local filename |
|
| 481 |
+ filename=$(basename "$1") |
|
| 482 |
+ [[ "$filename" =~ ^VIRB[0-9]{4}\.[Mm][Pp]4$ ]]
|
|
| 483 |
+} |
|
| 484 |
+ |
|
| 485 |
+get_device_sidecar_extensions() {
|
|
| 486 |
+ local file="$1" |
|
| 487 |
+ local filename |
|
| 488 |
+ filename=$(basename "$file") |
|
| 489 |
+ |
|
| 490 |
+ if is_gopro_media_file "$file"; then |
|
| 491 |
+ echo "THM thm LRV lrv" |
|
| 492 |
+ elif is_garmin_media_file "$file"; then |
|
| 493 |
+ echo "GLV glv" |
|
| 494 |
+ fi |
|
| 495 |
+} |
|
| 496 |
+ |
|
| 479 | 497 |
should_prefer_gopro_filesystem_date() {
|
| 480 | 498 |
local file="$1" |
| 481 | 499 |
|
@@ -1008,7 +1026,7 @@ find_source_files() {
|
||
| 1008 | 1026 |
fi |
| 1009 | 1027 |
} |
| 1010 | 1028 |
|
| 1011 |
-cleanup_gopro_sidecars() {
|
|
| 1029 |
+cleanup_media_sidecars() {
|
|
| 1012 | 1030 |
local file="$1" |
| 1013 | 1031 |
local dir base stem ext sidecar_ext sidecar |
| 1014 | 1032 |
dir=$(dirname "$file") |
@@ -1020,13 +1038,17 @@ cleanup_gopro_sidecars() {
|
||
| 1020 | 1038 |
return 0 |
| 1021 | 1039 |
fi |
| 1022 | 1040 |
|
| 1023 |
- for sidecar_ext in THM thm LRV lrv; do |
|
| 1041 |
+ local sidecar_exts |
|
| 1042 |
+ sidecar_exts=$(get_device_sidecar_extensions "$file") |
|
| 1043 |
+ [[ -z "$sidecar_exts" ]] && return 0 |
|
| 1044 |
+ |
|
| 1045 |
+ for sidecar_ext in $sidecar_exts; do |
|
| 1024 | 1046 |
sidecar="$dir/$stem.$sidecar_ext" |
| 1025 | 1047 |
if [[ -f "$sidecar" ]]; then |
| 1026 | 1048 |
if rm -f "$sidecar"; then |
| 1027 |
- log_message "Deleted GoPro sidecar: $sidecar" "INFO" |
|
| 1049 |
+ log_message "Deleted sidecar: $sidecar" "INFO" |
|
| 1028 | 1050 |
else |
| 1029 |
- log_message "Failed to delete GoPro sidecar: $sidecar" "WARNING" |
|
| 1051 |
+ log_message "Failed to delete sidecar: $sidecar" "WARNING" |
|
| 1030 | 1052 |
fi |
| 1031 | 1053 |
fi |
| 1032 | 1054 |
done |
@@ -1182,8 +1204,8 @@ process_file() {
|
||
| 1182 | 1204 |
fi |
| 1183 | 1205 |
fi |
| 1184 | 1206 |
log_message "Copied: $file -> $dest_path" "SUCCESS" |
| 1185 |
- if [[ $CLEANUP_GOPRO_SIDECARS -eq 1 ]]; then |
|
| 1186 |
- cleanup_gopro_sidecars "$file" |
|
| 1207 |
+ if [[ $CLEANUP_MEDIA_SIDECARS -eq 1 ]]; then |
|
| 1208 |
+ cleanup_media_sidecars "$file" |
|
| 1187 | 1209 |
fi |
| 1188 | 1210 |
PROCESSED_FILES=$((PROCESSED_FILES + 1)) |
| 1189 | 1211 |
PROCESSED_SIZE=$((PROCESSED_SIZE + file_size)) |
@@ -1211,8 +1233,8 @@ process_file() {
|
||
| 1211 | 1233 |
return 1 |
| 1212 | 1234 |
fi |
| 1213 | 1235 |
log_message "Moved: $file -> $dest_path" "SUCCESS" |
| 1214 |
- if [[ $CLEANUP_GOPRO_SIDECARS -eq 1 ]]; then |
|
| 1215 |
- cleanup_gopro_sidecars "$file" |
|
| 1236 |
+ if [[ $CLEANUP_MEDIA_SIDECARS -eq 1 ]]; then |
|
| 1237 |
+ cleanup_media_sidecars "$file" |
|
| 1216 | 1238 |
fi |
| 1217 | 1239 |
PROCESSED_FILES=$((PROCESSED_FILES + 1)) |
| 1218 | 1240 |
PROCESSED_SIZE=$((PROCESSED_SIZE + file_size)) |
@@ -1224,8 +1246,8 @@ process_file() {
|
||
| 1224 | 1246 |
fi |
| 1225 | 1247 |
elif verified_move_file "$file" "$dest_path" "$date_str"; then |
| 1226 | 1248 |
log_message "Moved: $file -> $dest_path" "SUCCESS" |
| 1227 |
- if [[ $CLEANUP_GOPRO_SIDECARS -eq 1 ]]; then |
|
| 1228 |
- cleanup_gopro_sidecars "$file" |
|
| 1249 |
+ if [[ $CLEANUP_MEDIA_SIDECARS -eq 1 ]]; then |
|
| 1250 |
+ cleanup_media_sidecars "$file" |
|
| 1229 | 1251 |
fi |
| 1230 | 1252 |
if [[ $sync_metadata_after_copy -eq 1 ]]; then |
| 1231 | 1253 |
if ! sync_destination_metadata_to_date "$dest_path" "$date_str"; then |
@@ -1365,8 +1387,8 @@ while [[ $# -gt 0 ]]; do |
||
| 1365 | 1387 |
UNATTENDED=1 |
| 1366 | 1388 |
shift |
| 1367 | 1389 |
;; |
| 1368 |
- --keep-gopro-sidecars) |
|
| 1369 |
- CLEANUP_GOPRO_SIDECARS=0 |
|
| 1390 |
+ --keep-sidecars) |
|
| 1391 |
+ CLEANUP_MEDIA_SIDECARS=0 |
|
| 1370 | 1392 |
shift |
| 1371 | 1393 |
;; |
| 1372 | 1394 |
--dry-run) |