From f6fe7f53b30d1176e45edca6118640b6e0ce6978 Mon Sep 17 00:00:00 2001 From: Octavio Ruiz Date: Tue, 20 Oct 2009 18:57:15 -0500 Subject: [PATCH] You can now choose a destination and source directory --- yaflac2mp3.sh | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) mode change 100644 => 100755 yaflac2mp3.sh diff --git a/yaflac2mp3.sh b/yaflac2mp3.sh old mode 100644 new mode 100755 index d55f376..9faae5b --- a/yaflac2mp3.sh +++ b/yaflac2mp3.sh @@ -23,9 +23,10 @@ # See the GNU General Public License for more details. LAME_OPTS="-V 0 --vbr-new" -LAME="lame" -FLAC="flac" -DIR="." +LAME=$(which lame) +FLAC=$(which flac) +SOURCE="." +DEST="." ID3="" usage() @@ -34,14 +35,15 @@ usage() cat<] [-f ] [-x ] [-d ] [-i] +Usage: $0 [-l ] [-f ] [-x ] [-s ] [-d ] [-i] Usage: $0 -h Default options: = ${LAME_OPTS} = ${LAME} = ${FLAC} - = ${DIR} + = ${SOURCE} + = ${DEST} = ${ID3} If you use -i, id3_tool is set to id3v2. @@ -52,7 +54,8 @@ EOF exit ${EXIT} } -while getopts l:f:x:d:hi name; do +while getopts l:f:x:d:s:hi name; do + case "${name}" in l) LAME="${OPTARG}" @@ -63,11 +66,11 @@ while getopts l:f:x:d:hi name; do x) LAME_OPTS="${OPTARG}" ;; - d) - DIR="${OPTARG}" + s) + SOURCE="${OPTARG}" ;; - h) - usage 0 + d) + DEST="${OPTARG}" ;; i) ID3="$(which id3v2 || echo '')" @@ -75,18 +78,25 @@ while getopts l:f:x:d:hi name; do printf "Requested id3v2 but not found. Only using lame.\n\n" fi ;; + h) + usage 0 + ;; ?) usage 1 ;; esac done -[[ ! -d "${DIR}" ]] && printf "\"${DIR}\" is not a directory\n\n" && usage 1 +if [[ ! -d "${DEST}" ]]; then + mkdir -p "${DEST}" + [[ "$?" != "0" ]] && exit 2 +fi +[[ ! -d "${SOURCE}" ]] && printf "\"${SOURCE}\" is not a directory\n\n" && usage 1 old_IFS=${IFS} IFS=' ' -files=( `find "${DIR}" \( -type f -o -type l \) -a -name '*.flac'` ) +files=( `find "${SOURCE}" \( -type f -o -type l \) -a -name '*.flac'` ) for N_files in ${!files[@]} do @@ -110,7 +120,7 @@ for N_files in ${!files[@]} ${date:+--ty} ${date} \ ${genre:+--tg} ${genre} \ ${comment:+--tc} ${comment} \ - - "${files[${N_files}]/\.flac/.mp3}" + - "${DEST}/${files[${N_files}]/\.flac/.mp3}" # User should only run this if they know their version of lame doesn't tag # properly. Does this happen in practice? LAME 3.98 supports id3 v1 and v2 @@ -122,7 +132,7 @@ for N_files in ${!files[@]} ${date:+--year} ${date} \ ${genre:+--genre} ${genre} \ ${comment:+--comment} ${comment} \ - "${files[${N_files}]/\.flac/.mp3}" + "${DEST}/${files[${N_files}]/\.flac/.mp3}" done IFS=${old_IFS}