dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit 533c7bd19977fd918ae5da44b85cf78a99c93026
parent aa13a1fd67b1d55db4e2fe134414859dee832643
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Tue,  9 Jun 2020 16:09:33 +0200

Add script to split and tag media file based on timestamps in file

Diffstat:
A.local/bin/ffmpeg-split | 64++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 64 insertions(+), 0 deletions(-)

diff --git a/.local/bin/ffmpeg-split b/.local/bin/ffmpeg-split @@ -0,0 +1,64 @@ +#!/bin/sh + +usage() { + printf 'usage: %s [-aA] TIMESTAMPSFILE MEDIAFILE\n' "${0##*/}" >&2 + printf 'OPTIONS:\n' + printf ' -a ARTIST\n' + printf ' -A ALBUM\n' + exit 1 +} + +die() { + printf 'error: %s\n' >&2 + exit 1 +} + +if [ $# -ne 2 ]; then + usage +fi + +if [ "$(file -ib "$1")" != "text/plain" ]; then + usage +fi + +if [ ! -e "$1" ] || [ ! -e "$2" ]; then + die "could not read $1 or $2" +fi + +artist="" +album="" +while :; do + case "$1" in + -a) artist="$2"; shift;; + -A) album="$2"; shift;; + *) break + esac + shift +done + +i=1 +tracks="$(awk 'END{ print NR }' "$1")" +while [ "$i" -le "$tracks" ]; do + printf 'track %d: ' "$i" + t_start="$(awk -v i="$i" '{ + if (NR==i) { + match($0, /[0-9]*:*[0-9]+:[0-5][0-9]/) + print(substr($0, RSTART, RLENGTH)) + }}' "$1")" + t_end="$(awk -v i="$i" '{ + if (NR==i+1) { + match($0, /[0-9]+:[0-5][0-9]/) + print(substr($0, RSTART, RLENGTH)) + }}' "$1")" + title="$(sed -n "s/ *(*[0-9]*:*[0-9]*[0-9]:[0-9][0-9])*//;${i}p" "$1")" + if [ -z "$t_end" ]; then + t_end="$(ffprobe "$2" 2>&1 | grep 'Duration: ' |\ + sed 's/,.*//;s/.* //')" + fi + printf '%s to %s\n' "$t_start" "$t_end" + out="$(printf '%02d %s - %s.%s' "$i" "${2%.*}" "$title" "${2##*.}")" + ffmpeg -y -ss "$t_start" -to "$t_end" -i "$2" "$out" + id3tag --track="$i" --song="$title" --artist="$artist" --album="$album"\ + "$out" + i=$(( i + 1 )) +done