Add cleanup_gopro_sidecars() function that removes associated thumbnail (THM) and low-resolution proxy (LRV) files after MP4 import completes. Enabled by default to keep imported cards clean; use --keep-gopro-sidecars flag to preserve sidecars if needed. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@@ -23,6 +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 | 27 |
CONFLICT_APPLY_ALL="" # suffix|skip after an interactive "all similar" choice |
| 27 | 28 |
RESOLVED_DESTINATION_PATH="" |
| 28 | 29 |
RESERVED_DESTINATION_PATHS=() |
@@ -109,6 +110,7 @@ Options: |
||
| 109 | 110 |
--sync-metadata Write chosen date into destination metadata (automatic for GoPro filesystem dates) |
| 110 | 111 |
--unattended Never prompt; resolve destination conflicts with numeric suffixes |
| 111 | 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) |
|
| 112 | 114 |
--keep-empty-dirs Keep empty directories after processing |
| 113 | 115 |
--dry-run Show actions without changing files |
| 114 | 116 |
-v, --verbose Verbose output |
@@ -1006,6 +1008,30 @@ find_source_files() {
|
||
| 1006 | 1008 |
fi |
| 1007 | 1009 |
} |
| 1008 | 1010 |
|
| 1011 |
+cleanup_gopro_sidecars() {
|
|
| 1012 |
+ local file="$1" |
|
| 1013 |
+ local dir base stem ext sidecar_ext sidecar |
|
| 1014 |
+ dir=$(dirname "$file") |
|
| 1015 |
+ base=$(basename "$file") |
|
| 1016 |
+ stem="${base%.*}"
|
|
| 1017 |
+ ext="${base##*.}"
|
|
| 1018 |
+ |
|
| 1019 |
+ if [[ ! "$ext" =~ ^([Mm][Pp]4)$ ]]; then |
|
| 1020 |
+ return 0 |
|
| 1021 |
+ fi |
|
| 1022 |
+ |
|
| 1023 |
+ for sidecar_ext in THM thm LRV lrv; do |
|
| 1024 |
+ sidecar="$dir/$stem.$sidecar_ext" |
|
| 1025 |
+ if [[ -f "$sidecar" ]]; then |
|
| 1026 |
+ if rm -f "$sidecar"; then |
|
| 1027 |
+ log_message "Deleted GoPro sidecar: $sidecar" "INFO" |
|
| 1028 |
+ else |
|
| 1029 |
+ log_message "Failed to delete GoPro sidecar: $sidecar" "WARNING" |
|
| 1030 |
+ fi |
|
| 1031 |
+ fi |
|
| 1032 |
+ done |
|
| 1033 |
+} |
|
| 1034 |
+ |
|
| 1009 | 1035 |
# Function to process a single file |
| 1010 | 1036 |
process_file() {
|
| 1011 | 1037 |
local file="$1" |
@@ -1156,6 +1182,9 @@ process_file() {
|
||
| 1156 | 1182 |
fi |
| 1157 | 1183 |
fi |
| 1158 | 1184 |
log_message "Copied: $file -> $dest_path" "SUCCESS" |
| 1185 |
+ if [[ $CLEANUP_GOPRO_SIDECARS -eq 1 ]]; then |
|
| 1186 |
+ cleanup_gopro_sidecars "$file" |
|
| 1187 |
+ fi |
|
| 1159 | 1188 |
PROCESSED_FILES=$((PROCESSED_FILES + 1)) |
| 1160 | 1189 |
PROCESSED_SIZE=$((PROCESSED_SIZE + file_size)) |
| 1161 | 1190 |
return 0 |
@@ -1182,6 +1211,9 @@ process_file() {
|
||
| 1182 | 1211 |
return 1 |
| 1183 | 1212 |
fi |
| 1184 | 1213 |
log_message "Moved: $file -> $dest_path" "SUCCESS" |
| 1214 |
+ if [[ $CLEANUP_GOPRO_SIDECARS -eq 1 ]]; then |
|
| 1215 |
+ cleanup_gopro_sidecars "$file" |
|
| 1216 |
+ fi |
|
| 1185 | 1217 |
PROCESSED_FILES=$((PROCESSED_FILES + 1)) |
| 1186 | 1218 |
PROCESSED_SIZE=$((PROCESSED_SIZE + file_size)) |
| 1187 | 1219 |
return 0 |
@@ -1192,6 +1224,9 @@ process_file() {
|
||
| 1192 | 1224 |
fi |
| 1193 | 1225 |
elif verified_move_file "$file" "$dest_path" "$date_str"; then |
| 1194 | 1226 |
log_message "Moved: $file -> $dest_path" "SUCCESS" |
| 1227 |
+ if [[ $CLEANUP_GOPRO_SIDECARS -eq 1 ]]; then |
|
| 1228 |
+ cleanup_gopro_sidecars "$file" |
|
| 1229 |
+ fi |
|
| 1195 | 1230 |
if [[ $sync_metadata_after_copy -eq 1 ]]; then |
| 1196 | 1231 |
if ! sync_destination_metadata_to_date "$dest_path" "$date_str"; then |
| 1197 | 1232 |
log_message "Failed to sync destination metadata timestamps: $dest_path" "WARNING" |
@@ -1330,6 +1365,10 @@ while [[ $# -gt 0 ]]; do |
||
| 1330 | 1365 |
UNATTENDED=1 |
| 1331 | 1366 |
shift |
| 1332 | 1367 |
;; |
| 1368 |
+ --keep-gopro-sidecars) |
|
| 1369 |
+ CLEANUP_GOPRO_SIDECARS=0 |
|
| 1370 |
+ shift |
|
| 1371 |
+ ;; |
|
| 1333 | 1372 |
--dry-run) |
| 1334 | 1373 |
DRY_RUN=1 |
| 1335 | 1374 |
shift |