#!/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."