#! /bin/bash set -e : ${JBDIR=/mnt/jb} force=nil while getopts fo:i: opt; do case "$opt" in o) offset=$OPTARG ;; f) force=t ;; i) id=$OPTARG ;; *) exit 1 ;; esac done shift $((OPTIND - 1)) dir=$1; shift; cd "$dir" case $# in 0) set $(ls | sed ' /^\([0-9][0-9]\)[-.\ ].*\.flac$/!d s//\1/ ') ;; esac case "${offset+t}" in t) ;; *) if [ -r .offset ]; then read offset <.offset; else offset=0; fi ;; esac : ${id=$($JBDIR/bin/flaccrip-discid -a .)} ntr=$(echo "$id" | sed 's:^0*\([1-9][0-9]*\)-.*$:\1:') ar=$($JBDIR/bin/flaccrip-arfetch $id) npress=0 while read type rest; do case "$type" in H) npress=$((npress + 1)) ;; *) ;; esac done <&2 "$0: no AccurateRip record found" exit 1 ;; *) echo "Found $npress pressings" ;; esac cks="" ntrack=$# ngood=0 for t in "$@"; do while :; do case "$t" in 0*) t=${t#0} ;; *) break ;; esac; done l=$((t - 1)) h=$((t + 1)) tt=$(printf %02d "$t") ll=$(printf %02d "$l") hh=$(printf %02d "$h") flags="" unset before after if ((t == 1)); then flags="${flags+$flags }-f" elif [ -f "$ll"[-.\ ]*.flac ]; then before=$(echo "$ll"[-.\ ]*.flac) elif ((offset < 0)); then echo >&2 "$0: warning: -ve offset, but track $l missing; using silence" fi if ((t == ntr)); then flags="${flags+$flags }-l" elif [ -f "$hh"[-.\ ]*.flac ]; then after=$(echo "$hh"[-.\ ]*.flac) elif ((offset > 0)); then echo >&2 "$0: warning: +ve offset, but track $h missing; using silence" fi ck=$($JBDIR/bin/flaccrip-offset -o"$offset" \ $flags ${before+-b "$before"} ${after+-a "$after"} "$tt"[-.\ ]*.flac | $JBDIR/bin/flaccrip-compute) press=0 found=nil while read arty art arconf arck; do case "$arty" in H) press=$((press + 1)) ;; T) case $art,$arck in $t,$ck) found=t printf "Track %2d (%s): match pressing %d; confidence %d\n" \ $t $ck $press $arconf ngood=$((ngood + 1)) break ;; esac ;; esac done <