суббота, 30 мая 2009 г.

Конвертация flac в mp3,wav etc

#!/bin/bash

(($# > 0)) || { echo “Error”; exit 1; }
DIR_NAME=$(dirname “$1″)
[ -d “$DIR_NAME” ] || { echo “Error: Dir \”$DIR_NAME\” not found”; exit 2; }
pushd “$DIR_NAME” > /dev/null
CUE_FILE=$(basename “$1″)
PRFX_NAME=${CUE_FILE%.[cC][uU][eE]}
APE_FILE=$(find . -type f -iname “$PRFX_NAME.ape”)
WAV_FILE=$(find . -type f -iname “$PRFX_NAME.wav”)
[ -n “$APE_FILE” -a -z “$WAV_FILE” -o -z “$APE_FILE” -a -n “$WAV_FILE” ] || { echo “Error:” ; exit 3; }
[ -n “$CUE_FILE” -a -s “$CUE_FILE” ] || { echo “Error: CUE file \”$CUE_FILE\” XY*”; exit 4; }
[ -n “$APE_FILE” -a -s “$APE_FILE” -o -z “$APE_FILE” ] || { echo “Error:”; exit 5; }
[ -n “$WAV_FILE” -a -s “$WAV_FILE” -o -z “$WAV_FILE” ] || { echo “Error:; exit 6; }
recode 1251..utf8 < “$CUE_FILE” > tmp.cue
if [ -n “$APE_FILE” ]; then
shnconv -i ape -o ‘flac flac -V -8 -e -p -o %f -’ “$APE_FILE”
elif [ -n “$WAV_FILE” ]; then
shnconv -i wav -o ‘flac flac -V -8 -e -p -o %f -’ “$WAV_FILE”
fi
cueprint -d ‘ARRANGER=%A\nCOMPOSER=%C\nGENRE=%G\nMESSAGE=%M\nPERFORMER=%P\nSONGWRITER=%S\nTITLE=%T\nEAN/UPN=%U\n’ tmp.cue |
egrep -v ‘=$’ |
metaflac –add-replay-gain –import-tags-from=- –import-cuesheet-from=tmp.cue “$PRFX_NAME.flac”rm tmp.cue
popd > /dev/null


Запускать в той же директории где и файл .flac и .cue в качестве аргумента к скрипту указываем файл .cue

Зависимости:

cuetools, shntool, flac, libmac, recode

1 комментарий: