From 709d5d2b41062d63e75af18870ab805e85c4407f Mon Sep 17 00:00:00 2001 From: Lucas Serverhost Date: Wed, 19 Aug 2026 11:23:02 +0200 Subject: [PATCH] metadata scripts rank from list: remove turtledemo and add grouping name as argument metadata scan: scan grouping of all files metadata search replace: add working dir as argument --- .../metadata_ffmpeg_series.sh | 4 +-- ...or_pdf.sh => metadata_generate_for_pdf.sh} | 0 quiethost/metadata_rank_from_list.py | 12 +++----- quiethost/metadata_scan.sh | 30 +++++++++++++++++++ quiethost/metadata_search_replace.sh | 3 +- 5 files changed, 38 insertions(+), 11 deletions(-) rename ffmpeg.sh => quiethost/metadata_ffmpeg_series.sh (84%) rename quiethost/{metadate_generate_for_pdf.sh => metadata_generate_for_pdf.sh} (100%) create mode 100644 quiethost/metadata_scan.sh diff --git a/ffmpeg.sh b/quiethost/metadata_ffmpeg_series.sh similarity index 84% rename from ffmpeg.sh rename to quiethost/metadata_ffmpeg_series.sh index bd0747a..389d1bd 100755 --- a/ffmpeg.sh +++ b/quiethost/metadata_ffmpeg_series.sh @@ -19,8 +19,8 @@ for d in */; do continue fi echo $d $num - ~/git/serverhost/.venv/bin/python \ - ~/git/serverhost/ffmpeg_handling.py \ + /home/lucas/scripts/.venv/bin/python \ + /home/lucas/scripts/ffmpeg_handling.py \ ms "$name" \ --override \ -k grouping \ diff --git a/quiethost/metadate_generate_for_pdf.sh b/quiethost/metadata_generate_for_pdf.sh similarity index 100% rename from quiethost/metadate_generate_for_pdf.sh rename to quiethost/metadata_generate_for_pdf.sh diff --git a/quiethost/metadata_rank_from_list.py b/quiethost/metadata_rank_from_list.py index 58173c9..fcd88f1 100644 --- a/quiethost/metadata_rank_from_list.py +++ b/quiethost/metadata_rank_from_list.py @@ -5,7 +5,6 @@ import re import subprocess from pathlib import Path from difflib import SequenceMatcher -from turtledemo.lindenmayer import replace AUDIO_EXTENSIONS = { ".mp3", @@ -56,7 +55,7 @@ def get_tag(path, tag): return "" -def tag_file(path: Path, rank: int, year: str, dry_run: bool): +def tag_file(path: Path, rank: int, year: str, dry_run: bool, replace_pattern: str=r"Top 100 SciFi Books" ) work = get_tag(path, "work") grouping = get_tag(path, "grouping") existing_year = get_tag(path, "year") @@ -70,10 +69,7 @@ def tag_file(path: Path, rank: int, year: str, dry_run: bool): else: tag = "grouping" existing = "" - #pattern = r"Top 100 SciFi Books #\d+(?:\.\d+)?" - pattern = r"Enderverse Publication #\d+(?:\.\d+)?" - #replace = r"Top 100 SciFi Books" - replace = r"Enderverse Publication" + pattern = f"{replace_pattern} #\d+(?:\.\d+)?" if existing: if re.search(pattern, existing): @@ -118,7 +114,7 @@ def main(): args = parser.parse_args() library = Path(args.library) - + replace_pattern=Path(args.booklist).stem found = set() with open(args.booklist, encoding="utf-8") as f: @@ -197,7 +193,7 @@ def main(): if file.suffix.lower() not in AUDIO_EXTENSIONS: continue - ret=tag_file(file, rank, year, args.dry_run) + ret=tag_file(file, rank, year, args.dry_run, replace_pattern) if ret == "skip": break #print("next") diff --git a/quiethost/metadata_scan.sh b/quiethost/metadata_scan.sh new file mode 100644 index 0000000..17b1433 --- /dev/null +++ b/quiethost/metadata_scan.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env bash + +shopt -s globstar nullglob + +root="${1:-.}" + +for file in "$root"/**/*; do + [[ -f "$file" ]] || continue + + case "${file##*.}" in + epub|EPUB) + continue + ;; + nfo|NFO) + grouping="$(grep -i 'Series Name:' "$file" 2>/dev/null | sed 's/^[Ss]eries:[[:space:]]*//')" + ;; + m4b|M4B|m4a|M4A|mp3|MP3|aac|AAC|flac|FLAC) +grouping="$(kid3-cli -c "get grouping" "$file" 2>/dev/null)" + ;; + *) + continue + ;; + esac + + if [[ ! "$grouping" =~ Publication ]]; then +echo Grouping: $grouping +echo "$file" + fi +done + diff --git a/quiethost/metadata_search_replace.sh b/quiethost/metadata_search_replace.sh index 918f6a4..3f89145 100755 --- a/quiethost/metadata_search_replace.sh +++ b/quiethost/metadata_search_replace.sh @@ -1,6 +1,7 @@ #!/usr/bin/env bash -find . \( -iname '*.mp3' -o -iname '*.m4a' -o -iname '*.m4b' \) -print0 | +root="${1:-.}" +find "$root" \( -iname '*.mp3' -o -iname '*.m4a' -o -iname '*.m4b' \) -print0 | while IFS= read -r -d '' f; do comment=$(ffprobe -v error \