metadata script
metadata remove genre: script to remove keywords ie audiobook from genre rank from list: change pattern and separate author and title, rank is str now
This commit is contained in:
1 parent
0dca4be1f3
commit
fe68810e0f
2 files changed
+113
-8
No files matched your search
@@ -0,0 +1,103 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
LIBRARY="$1"
|
||||
MODE="${2:-}"
|
||||
REPORT="${3:-/home/lucas/audiobook_genre_cleanup.txt}"
|
||||
|
||||
if [[ -z "$LIBRARY" ]]; then
|
||||
echo "Usage: $0 <library_path> [--delete] [report_file]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mapfile -t FILES < <(
|
||||
find "$LIBRARY" -type f \( \
|
||||
-iname "*.mp3" -o \
|
||||
-iname "*.m4b" -o \
|
||||
-iname "*.m4a" \
|
||||
\)
|
||||
)
|
||||
|
||||
TOTAL=${#FILES[@]}
|
||||
PROCESSED=0
|
||||
MATCHES=0
|
||||
MODIFIED=0
|
||||
|
||||
{
|
||||
echo "Audiobook Genre Cleanup Report"
|
||||
echo "Generated: $(date)"
|
||||
echo "Library: $LIBRARY"
|
||||
echo "Total files: $TOTAL"
|
||||
echo
|
||||
} > "$REPORT"
|
||||
|
||||
for file in "${FILES[@]}"; do
|
||||
((PROCESSED++))
|
||||
|
||||
if (( PROCESSED % 100 == 0 )); then
|
||||
echo "Progress: $PROCESSED/$TOTAL files processed"
|
||||
fi
|
||||
genre=$(kid3-cli -c "get genre" "$file" 2>/dev/null)
|
||||
|
||||
[[ -z "$genre" ]] && continue
|
||||
cleaned=$(printf '%s\n' "$genre" | sed -E '
|
||||
s/[Aa]udio[[:space:]]*[Bb]ooks?//g
|
||||
|
||||
# Normalize genre names
|
||||
s/\b(Sci[ -]?Fi|Science Fiction|SF)\b/SciFi/Ig
|
||||
s/\bnonfiction\b/NonFiction/Ig
|
||||
|
||||
# Normalize separators (&, :, / -> ;)
|
||||
s/[[:space:]]*[,&:\/][[:space:]]*/;/g
|
||||
|
||||
# Normalize commas
|
||||
s/[[:space:]]*;[[:space:]]*/; /g
|
||||
|
||||
# Trim leading/trailing punctuation and whitespace
|
||||
s/^[[:space:],;:-]+//
|
||||
s/[[:space:],;-]+$//
|
||||
')
|
||||
# s/.*//;
|
||||
|
||||
if [[ "$genre" != "$cleaned" ]]; then
|
||||
((MATCHES++))
|
||||
|
||||
status="MATCH"
|
||||
|
||||
if [[ "$MODE" == "--delete" ]]; then
|
||||
printf "D "
|
||||
kid3-cli \
|
||||
-c "select-tag 1" \
|
||||
-c "set genre \"$cleaned\"" \
|
||||
-c "select-tag 2" \
|
||||
-c "set genre \"$cleaned\"" \
|
||||
-c save \
|
||||
"$file" >/dev/null
|
||||
|
||||
((MODIFIED++))
|
||||
status="UPDATED"
|
||||
fi
|
||||
|
||||
printf '[%d/%d] [%s] %s | OLD="%s" | NEW="%s"\n' \
|
||||
"$PROCESSED" "$TOTAL" "$status" "$file" "$genre" "$cleaned"
|
||||
|
||||
printf '[%d/%d] [%s] %s | OLD="%s" | NEW="%s"\n' \
|
||||
"$PROCESSED" "$TOTAL" "$status" "$file" "$genre" "$cleaned" >> "$REPORT"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
{
|
||||
echo
|
||||
echo "========== SUMMARY =========="
|
||||
echo "Files scanned : $TOTAL"
|
||||
echo "Matches found : $MATCHES"
|
||||
echo "Files updated : $MODIFIED"
|
||||
} >> "$REPORT"
|
||||
|
||||
echo
|
||||
echo "========== SUMMARY =========="
|
||||
echo "Files scanned : $TOTAL"
|
||||
echo "Matches found : $MATCHES"
|
||||
echo "Files updated : $MODIFIED"
|
||||
echo "Report written to: $REPORT"
|
||||
|
||||
Reference in new issue
Block a user