#! /bin/bash set -e : ${JBDIR=/mnt/jb} while getopts i: opt; do case "$opt" in 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 : ${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: this isn't going to work" exit 1 ;; *) echo "Found $npress pressings" ;; esac 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) else echo >&2 "$0: warning: track $l missing; using silence" fi if ((t == ntr)); then flags="${flags+$flags }-l" elif [ -f "$hh"[-.\ ]*.flac ]; then after=$(echo "$hh"[-.\ ]*.flac) else echo >&2 "$0: warning: track $h missing; using silence" fi echo "T $t" cks="" while read arty art arconf arck; do case "$arty,$art" in T,$t) cks="${cks:+$cks }$arck" echo "C $arck $arconf" ;; esac done < c) MC[m] = c; } END { for (m in MM) print m " " MM[m] " " MC[m]; }' | sort -rn -k2 -k3