From: Steven Baltakatei Sandoval Date: Tue, 30 Apr 2024 00:10:32 +0000 (+0000) Subject: feat(user/mw_get_audiobook_chapters.sh): X-Git-Url: https://zdv2.bktei.com/gitweb/BK-2020-03.git/commitdiff_plain/e51dd5e563c61b4652c3ec1fbbba9eae60f69785?hp=ddcb78b71ab49dc48d484a63bba85a4a827b71cd feat(user/mw_get_audiobook_chapters.sh): --- diff --git a/user/mw_get_audiobook_chapters.sh b/user/mw_get_audiobook_chapters.sh new file mode 100644 index 0000000..191b1e7 --- /dev/null +++ b/user/mw_get_audiobook_chapters.sh @@ -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+$"; "") )' + );