m4b_mp3_egal.sh hinzugefügt

This commit is contained in:
alf
2026-03-28 11:57:44 +00:00
parent 05c62e3a56
commit 426b406f3c

70
m4b_mp3_egal.sh Normal file
View File

@ -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"
</dev/null ffmpeg -loglevel error -stats \
-i "$full_file_path" \
-ss "${start%?}" \
-to "$end" \
-codec:a copy \
-metadata title="$chapter" \
-metadata album="$title" \
-metadata track="$track" \
"$chapter_file"
track=$((track + 1))
fi
done < tmp.txt
rm "$full_file_path"
else
gum spin --title "Konvertiere: $name ..." -- \
ffmpeg -i "$i" \
-acodec libmp3lame \
-b:a 128k \
-map_metadata 0 \
-id3v2_version 3 \
"${name}.mp3"
echo " -> ${name}.mp3"
track=$((track + 1))
fi
rm -f tmp.txt
done
echo "==> Fertig."