From 426b406f3c667fc1ef611026d38f377b4d6d7b4e Mon Sep 17 00:00:00 2001 From: alf Date: Sat, 28 Mar 2026 11:57:44 +0000 Subject: [PATCH] =?UTF-8?q?m4b=5Fmp3=5Fegal.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- m4b_mp3_egal.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 m4b_mp3_egal.sh diff --git a/m4b_mp3_egal.sh b/m4b_mp3_egal.sh new file mode 100644 index 0000000..34b037f --- /dev/null +++ b/m4b_mp3_egal.sh @@ -0,0 +1,70 @@ +#!/bin/bash +# MIT GUM-Darstellung +# Abhängigkeiten: sudo apt-get install ffmpeg id3v2 +# https://github.com/charmbracelet/gum + +track=1 + +for i in *.m4b; do + name="${i%.m4b}" + + ffmpeg -i "$i" 2> tmp.txt + chapter_count=$(grep -c "Chapter #" tmp.txt || true) + + if [[ "$chapter_count" -gt 0 ]]; then + title=$(basename "$(pwd)") + full_file_path="${name}.mp3" + + gum spin --title "Konvertiere: $name ..." -- \ + ffmpeg -i "$i" \ + -acodec libmp3lame \ + -b:a 128k \ + -map_metadata 0 \ + -id3v2_version 3 \ + "$full_file_path" + + echo "Splitte nach Kapiteln: $name" + while read -r first _ _ start _ end; do + if [[ "${first}" = "Chapter" ]]; then + read + read _ _ chapter + track_padded=$(printf "%02d" "$track") + base_name="${title} - ${track_padded} - ${chapter}" + chapter_file="${base_name}.mp3" + suffix=1 + while [[ -e "$chapter_file" ]]; do + chapter_file="${base_name}_(${suffix}).mp3" + suffix=$((suffix + 1)) + done + echo " -> $chapter_file" + ${name}.mp3" + track=$((track + 1)) + fi + + rm -f tmp.txt +done + +echo "==> Fertig." \ No newline at end of file