#!/bin/bash # Group media files together to make hour-long chunks # with the same sample rate. Ipods crash when things # are much longer than an hour, but also randomly skip # tracks. We want to minimize the number of tracks in # order to minimize the number of times the listening # experience is interrupted by suddenly jumping ahead # and having to fish out the device and hit back twice. # This leaves things in numbered directories, all lined # up for use with speedcode. For example: # { for a in ?;do speedcode "foo-$a.mp3" "$a"/*; done; } factor=1.7 # same as speedcode while getopts f: opt;do case $opt in f) factor=$OPTARG;; esac done shift `expr $OPTIND - 1` media-length -r "$@" | awk -v limit="$(dc <<< "3600 $factor *p")" ' BEGIN { dest=1 printf "%02d", dest | "xargs -0 mkdir -v" close("xargs -0 mkdir -v") } { if ((prevrate && $1 != prevrate) || (total && total + $2 > limit)) { print "====" print "total:", total print "" total=0 dest++ printf "%02d", dest | "xargs -0 mkdir -v" close("xargs -0 mkdir -v") } prevrate = $1 total += $2 printf "%s\t%s\t", $1, $2 printf "%s\0%02d", gensub("^[0-9]+ [0-9.]+\t", "", 1), dest | "xargs -0 mv -v " close("xargs -0 mv -v ") }'