From 57bb58564456d19fbee99dd25e87edd4cbc01e24 Mon Sep 17 00:00:00 2001 From: alf Date: Thu, 26 Mar 2026 10:52:34 +0000 Subject: [PATCH] =?UTF-8?q?m4b=5Fmp3.sh=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- m4b_mp3.sh | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 m4b_mp3.sh diff --git a/m4b_mp3.sh b/m4b_mp3.sh new file mode 100644 index 0000000..7013644 --- /dev/null +++ b/m4b_mp3.sh @@ -0,0 +1,64 @@ +#!/bin/bash +# +# sudo apt-get install id3v2 ffmpeg +# +# USAGE: +# cd /book title/ +# bash ~/this_script_path.sh +# rm *.m4b (you need to manually remove the original in case something goes wrong) +# +# +# EXAMPLE: +# +# $ ls +# The Wheel of Time - Book 11 - Knife of Dreams, Part 1.m4b The Wheel of Time - Book 11 - Knife of Dreams, Part 2.m4b +# $ ~/convert_m4b.sh +# ..... +# +# [OUTPUT]: +# +# File: Knife of Dreams - 01 - Chapter 18 - News for the Dragon.mp3 +# Metadata: ID3v2.3 +# Title: Chapter 18 - News for the Dragon +# Artist: Robert Jordan +# Album: Knife of Dreams +# Track: 1 +# Genre: Audiobooks +#initial track number +track=1 +#assumes ( if there are multiple files Part 01/Part 02) that they are in alphabetical order +for i in *.m4b; +do + name=`echo $i | cut -d'.' -f1`; + echo $name; + ffmpeg -i "$i" -acodec libmp3lame -ar 22050 -ab 64k "$name.mp3" + full_file_path="$name.mp3" + #split chapters + title=$(pwd | sed 's,^\(.*/\)\?\([^/]*\),\2,' | cut -d , -f 1) + ffmpeg -i "$full_file_path" 2> tmp.txt + while read -r first _ _ start _ end; do + if [[ "${first}" = "Chapter" ]] + then + read # discard line with Metadata: + read _ _ chapter + chapter=$(sed -re ":r;s/\b[0-9]{1,$((1))}\b/0&/g;tr" <<<$chapter) + track_padded=$(printf "%02d" "$track") # <-- neu: nullgepaddet + base_name="${title} - ${track_padded} - ${chapter}" # <-- geƤndert + chapter_file="${base_name}.mp3" + suffix=1 + while [[ -e "$chapter_file" ]]; do + chapter_file="${base_name}_(${suffix}).mp3" + suffix=$((suffix+1)) + done + echo "processing $chapter" +