From 95f4c85f329c9924e190643d62322cf07b107b5b Mon Sep 17 00:00:00 2001 From: Tangent Date: Sat, 8 Aug 2026 02:06:44 -0600 Subject: [PATCH] Upload files to "/" This better fucking recognize that it was chmodded but I don't expect it to. --- mp3s-to-m4b.sh | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 mp3s-to-m4b.sh diff --git a/mp3s-to-m4b.sh b/mp3s-to-m4b.sh new file mode 100644 index 0000000..729671f --- /dev/null +++ b/mp3s-to-m4b.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +set -e + +OUTPUT="audiobook.m4b" +FILES="files.txt" +CHAPTERS="chapters.txt" + +# list of MP3 files in filename order +find . -maxdepth 1 -name '*.mp3' -print0 | + sort -z | + while IFS= read -r -d '' file; do + file="${file#./}" + printf "file '%s'\n" "$file" + done > "$FILES" + +# start chapter metadata file +{ + echo ";FFMETADATA1" +} > "$CHAPTERS" + +START=0 + +while IFS= read -r line; do + FILE="${line#file \'}" + FILE="${FILE%\'}" + + # duration in milliseconds + DURATION=$(ffprobe \ + -v error \ + -show_entries format=duration \ + -of csv=p=0 \ + "$FILE") + + DURATION_MS=$(awk "BEGIN {printf \"%.0f\", $DURATION * 1000}") + END=$((START + DURATION_MS)) + + # filename as the chapter title + TITLE="${FILE%.mp3}" + + cat >> "$CHAPTERS" <