feat(user/mw_get_audiobook_chapters.sh):
authorSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 30 Apr 2024 00:10:32 +0000 (00:10 +0000)
committerSteven Baltakatei Sandoval <baltakatei@gmail.com>
Tue, 30 Apr 2024 00:10:32 +0000 (00:10 +0000)
user/mw_get_audiobook_chapters.sh [new file with mode: 0644]

diff --git a/user/mw_get_audiobook_chapters.sh b/user/mw_get_audiobook_chapters.sh
new file mode 100644 (file)
index 0000000..191b1e7
--- /dev/null
@@ -0,0 +1,24 @@
+#!/bin/bash
+# Print mediawiki code chapter headings and timecodes from audiobook file
+# Usage: mw_get_audiobook_chapters.sh [file] ([int offset])
+# Input: arg1: path to audiobook
+#        arg2: offset for chapter numbers
+# Example: mw_get_audiobook_chapters.sh input.m4b
+# Version: 0.0.1
+
+
+fin="$1";
+n=0
+while read -r line; do
+    if [[ $((n % 2)) -eq 0 ]]; then
+        chap="$(sed -e 's/^0*//' <<< "$line")"; # remove leading zero
+        printf "====%s====\n" "$chap"; # output wikicode header
+    elif [[ $((n % 2)) -eq 1 ]]; then
+        printf "%s\n\n" "$line"; # output timecode
+    fi;
+    #declare -p n line; # debug
+    ((n++));
+done < <(ffprobe -i "$fin" -print_format json -show_chapters -sexagesimal | \
+             jq \
+                 -r '.chapters[] | (.tags.title) + "\n" + (.start_time | gsub("\\.\\d+$"; "") )'
+        );