feat(user/mp3s_to_mkv.sh):Enable automatic chapter metadata creation
[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
5# arg2: offset for chapter numbers
6# Example: mw_get_audiobook_chapters.sh input.m4b
7# Version: 0.0.1
8
9
10fin="$1";
11n=0
12while read -r line; do
13 if [[ $((n % 2)) -eq 0 ]]; then
14 chap="$(sed -e 's/^0*//' <<< "$line")"; # remove leading zero
15 printf "====%s====\n" "$chap"; # output wikicode header
16 elif [[ $((n % 2)) -eq 1 ]]; then
17 printf "%s\n\n" "$line"; # output timecode
18 fi;
19 #declare -p n line; # debug
20 ((n++));
21done < <(ffprobe -i "$fin" -print_format json -show_chapters -sexagesimal | \
22 jq \
23 -r '.chapters[] | (.tags.title) + "\n" + (.start_time | gsub("\\.\\d+$"; "") )'
24 );