feat(unitproc/bkt-get_path_hierarchy_level):Add bash function
[BK-2020-03.git] / user / mw_get_audiobook_chapters.sh
CommitLineData
e51dd5e5
SBS
1#!/bin/bash
2# Print mediawiki code chapter headings and timecodes from audiobook file
3# Usage: mw_get_audiobook_chapters.sh [file] ([int offset])
4# Input: arg1: path to audiobook
e51dd5e5 5# Example: mw_get_audiobook_chapters.sh input.m4b
4b807ed1 6# Version: 0.1.0
e51dd5e5
SBS
7
8
9fin="$1";
10n=0
11while read -r line; do
12 if [[ $((n % 2)) -eq 0 ]]; then
13 chap="$(sed -e 's/^0*//' <<< "$line")"; # remove leading zero
14 printf "====%s====\n" "$chap"; # output wikicode header
15 elif [[ $((n % 2)) -eq 1 ]]; then
16 printf "%s\n\n" "$line"; # output timecode
17 fi;
18 #declare -p n line; # debug
19 ((n++));
20done < <(ffprobe -i "$fin" -print_format json -show_chapters -sexagesimal | \
21 jq \
22 -r '.chapters[] | (.tags.title) + "\n" + (.start_time | gsub("\\.\\d+$"; "") )'
23 );