From 12759288743bae9510b4403f4f92326acbe25c83 Mon Sep 17 00:00:00 2001 From: Colin Patrick Mccabe Date: Sat, 11 May 2013 16:12:51 -0700 Subject: [PATCH] add mp3chop.sh Signed-off-by: Colin McCabe --- mp3chop.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 57 insertions(+), 0 deletions(-) create mode 100755 mp3chop.sh 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 ***" -- 1.6.6.rc1.39.g9a42