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
@@ -70,9 +70,11 @@ def tag_file(path: Path, rank: int, year: str, dry_run: bool):
|
|||||||
else:
|
else:
|
||||||
tag = "grouping"
|
tag = "grouping"
|
||||||
existing = ""
|
existing = ""
|
||||||
pattern = r"Top 100 SciFi Books #\d+"
|
#pattern = r"Top 100 SciFi Books #\d+(?:\.\d+)?"
|
||||||
# pattern = r"Enderverse"
|
pattern = r"Enderverse Publication #\d+(?:\.\d+)?"
|
||||||
replace = r"Top 100 SciFi Books"
|
#replace = r"Top 100 SciFi Books"
|
||||||
|
replace = r"Enderverse Publication"
|
||||||
|
|
||||||
if existing:
|
if existing:
|
||||||
if re.search(pattern, existing):
|
if re.search(pattern, existing):
|
||||||
new_group = re.sub(
|
new_group = re.sub(
|
||||||
@@ -142,9 +144,9 @@ def main():
|
|||||||
parts = line.split(" - ")
|
parts = line.split(" - ")
|
||||||
|
|
||||||
if len(parts) == 4:
|
if len(parts) == 4:
|
||||||
rank, author, title, year = parts
|
rank, title, author, year = parts
|
||||||
elif len(parts) == 3:
|
elif len(parts) == 3:
|
||||||
rank, author, title = parts
|
rank, title, author = parts
|
||||||
year = None
|
year = None
|
||||||
else:
|
else:
|
||||||
raise ValueError(f"Invalid line: {line}")
|
raise ValueError(f"Invalid line: {line}")
|
||||||
@@ -186,7 +188,7 @@ def main():
|
|||||||
|
|
||||||
found.add(rank)
|
found.add(rank)
|
||||||
|
|
||||||
print(f"{GREEN}FOUND{RESET} #{int(rank):3} {title} in {book_dir}")
|
print(f"{GREEN}FOUND{RESET} #{rank:3} {title} in {book_dir}")
|
||||||
|
|
||||||
if args.find_missing:
|
if args.find_missing:
|
||||||
continue
|
continue
|
||||||
@@ -195,10 +197,10 @@ def main():
|
|||||||
if file.suffix.lower() not in AUDIO_EXTENSIONS:
|
if file.suffix.lower() not in AUDIO_EXTENSIONS:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ret=tag_file(file, int(rank), year, args.dry_run)
|
ret=tag_file(file, rank, year, args.dry_run)
|
||||||
if ret == "skip":
|
if ret == "skip":
|
||||||
break
|
break
|
||||||
# print("next")
|
#print("next")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
@@ -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