From: Colin Patrick Mccabe Date: Sat, 11 May 2013 23:12:51 +0000 (-0700) Subject: add mp3chop.sh X-Git-Url: http://club.cc.cmu.edu/~cmccabe/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=12759288743bae9510b4403f4f92326acbe25c83;p=cmccabe-bin add mp3chop.sh Signed-off-by: Colin McCabe --- diff --git a/mp3chop.sh b/mp3chop.sh new file mode 100755 index 0000000..6af88f7 --- /dev/null +++ b/mp3chop.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +die() { + echo $@ + exit 1 +} + +usage() { + cat < + +options: +-h: show this help message. +-o [dir]: output directory to use. +-s [size]: segment size to use (default: 5minutes). +EOF +} + +which mp3splt &> /dev/null || die "you must have mp3splt installed" + +segment_size=5.0 +output_dir="./out" +while getopts "ho:s:" flag; do + case $flag in + h) usage; exit 0;; + o) output_dir=$OPTARG;; + s) segment_size=$OPTARG;; + *) echo "getopts error" + echo + usage + exit 1;; + esac + #echo "$flag" $OPTIND $OPTARG +done + +shift $(( OPTIND-1 )) + +mkdir -p "$output_dir" || die "failed to create $output_dir" + +for file in "$@"; do + absfile="$(readlink -f "${file}")" + mkdir -p "${output_dir}/${file}.dir" + pushd "${output_dir}/${file}.dir" &>/dev/null \ + || die "failed to pushd to ${output_dir}/file" + ln "$absfile" || die "failed to hardlink ${absfile}" + mp3splt -t "${segment_size}" "${file}" \ + || die "mp3splt failed on file ${file}" + rm -f "$file" + mv * .. + cd .. + rmdir "${file}.dir" || die "rmdir ${file}.dir failed" + popd &> /dev/null || die "popd failed" +done + +echo "*** SUCCESSFULLY SPLIT ALL ***"