Template
fix: scan albums before cleanup deletion
This commit is contained in:
@@ -83,15 +83,27 @@ delete_sidecars() {
|
||||
}
|
||||
|
||||
removed=0
|
||||
sidecars=0
|
||||
extracted=0
|
||||
declare -a audio_files=()
|
||||
declare -A covered_dirs=()
|
||||
while IFS= read -r -d '' audio; do
|
||||
audio_files+=("$audio")
|
||||
done < <(find "$LIBRARY" -type f -print0 | while IFS= read -r -d '' f; do is_audio "$f" && printf '%s\0' "$f"; done)
|
||||
|
||||
# Phase 1: discover/extract one embedded cover for each album before deleting anything.
|
||||
for audio in "${audio_files[@]}"; do
|
||||
album_dir="${audio%/*}"
|
||||
if has_cover_file "$album_dir"; then continue; fi
|
||||
if has_cover_file "$album_dir" || [[ -n "${covered_dirs[$album_dir]:-}" ]]; then continue; fi
|
||||
if extract_cover "$audio" "$album_dir"; then
|
||||
covered_dirs["$album_dir"]=1
|
||||
((extracted += 1)) || true
|
||||
continue
|
||||
fi
|
||||
done
|
||||
|
||||
# Phase 2: only albums that still have no directory or embedded cover are removed.
|
||||
for audio in "${audio_files[@]}"; do
|
||||
album_dir="${audio%/*}"
|
||||
if has_cover_file "$album_dir" || [[ -n "${covered_dirs[$album_dir]:-}" ]]; then continue; fi
|
||||
if [[ "$MODE" == "dry-run" ]]; then
|
||||
echo "WOULD DELETE AUDIO $audio"
|
||||
else
|
||||
@@ -99,6 +111,6 @@ while IFS= read -r -d '' audio; do
|
||||
fi
|
||||
delete_sidecars "$audio"
|
||||
((removed += 1)) || true
|
||||
done < <(find "$LIBRARY" -type f -print0 | while IFS= read -r -d '' f; do is_audio "$f" && printf '%s\0' "$f"; done)
|
||||
done
|
||||
|
||||
echo "mode=$MODE extracted=$extracted audio_removed=$removed"
|
||||
|
||||
Reference in New Issue
Block a user