Перекодирование одиночного lossless аудиофайла во FLAC по CUE-таблице: различия между версиями

Материал из Linux Wiki
Перейти к навигацииПерейти к поиску
Строка 7: Строка 7:
<source lang="bash">
<source lang="bash">
#!/bin/bash
#!/bin/bash
# Created: at the beginning of 2008
# By Rain ;)
# last change: 2009-01-20
# Usage: cueape2flac "AUDIO FILE.ape" "TEXT FILE.cue"
# Depends on monkeys-audio, flac, shntool, enconv, cuetag


outdir="output"
outdir="output"
Строка 16: Строка 17:
exit $2
exit $2
}
}
 
test $(which flac) || error "Error: FLAC convertor not found" 1
test $(which flac) || error "Error: FLAC convertor not found" 1


if [ ! -z "${2}" ]; then
test $(which shnsplit) || error "Please, install shntool first" 1
test $(which enconv) || error "Please, install enca first" 1
test $(which cuetag) || error "Please, install cuetools first" 1
fi
if [[ "$(file -b "${1}")" =~ "Monkey's Audio" ]]; then
if [[ "$(file -b "${1}")" =~ "Monkey's Audio" ]]; then
test $(which mac) || error "Error: Monkey Audio convertor not found" 1
test $(which mac) || error "Error: Monkey Audio convertor not found" 1
Строка 30: Строка 37:
elif [[ "$(file -b "${1}")" =~ "WAVE audio" ]]; then
elif [[ "$(file -b "${1}")" =~ "WAVE audio" ]]; then
echo "Ok, ${1} ready to splitting"
echo "Ok, ${1} ready to splitting"
elif [ "${1##*.}" == 'wv' ]; then
test $(which wvunpack) || error "Error: WavPack decompressor not found" 1
echo "Converting "$1" from WavPack to WAV-format"
wvunpack -m "${1}"
else
else
error "Can't recognize input file format"
error "Can't recognize input file format"
fi
fi
 
if [ -z "${2}" ]; then
if [ -z "${2}" ]; then
echo "CUE-sheet not specified, so we simply convert ${1} to FLAC format"
echo "CUE-sheet not specified, so we simply convert ${1} to FLAC format"
flac --best -V "${1%.*}.wav" -o "${1%.*}.flac"
flac --best -V "${1%.*}.wav" -o "${1%.*}.flac"
exit 0
exit 0
fi
fi
test $(which shnsplit) || error "Please, install shntool first" 1


[ -e $outdir ] && echo "Warning: $outdir already exist" || echo "Creating output directory"
[ -e $outdir ] && echo "Warning: $outdir already exist" || echo "Creating output directory"
mkdir -p "$outdir"
mkdir -p "$outdir"
# Converting CUE-sheet
cat "${2}" | enconv > "${outdir}/${2}.converted"


echo "Splitting "${1%.*}.wav" to multiple files"
echo "Splitting "${1%.*}.wav" to multiple FLAC files"
cd $outdir
cd $outdir
cat ../"$2" | shnsplit -t %n_:_%p_:_%a_:_%t ../"${1%.*}.wav"
cat "${2}.converted" | shnsplit -o 'flac flac --best -V - -o %f' -t %n-%p-%a-%t ../"${1%.*}.wav"
rm -f ../"${1%.*}.wav"
rm -f ../"${1%.*}.wav"


ls -1 *.wav |
cuetag "${2}.converted" *.flac
while read i;
do
tracknum=$(echo "${i%.wav}" | awk -F'_:_' '{print $1}')
artist=$(echo "${i%.wav}" | awk -F'_:_' '{print $2}')
album=$(echo "${i%.wav}" | awk -F'_:_' '{print $3}')
title=$(echo "${i%.wav}" | awk -F'_:_' '{print $4}')
$(flac --best "$i" --delete-input-file -V --replay-gain \
-T title="$title" \
-T album="$album" \
-T artist="$artist" \
-T tracknumber="$tracknum" \
-o "$tracknum-$artist-$album-$title.flac")&:
done
</source>
</source>
----
----

Версия 21:35, 5 марта 2009

Скрипт для преобразования одиночного ape-файла, представляющего собой копию диска в отдельные FLAC-файлы с заполнением тегов и именованием файлов в соответствии с CUE-таблицой

Использование
cueape2flac "AUDIO FILE.ape" "TEXT FILE.cue"
Зависимости
monkeys-audio, flac, shntool

#!/bin/bash
# By Rain ;)
# Usage: cueape2flac "AUDIO FILE.ape" "TEXT FILE.cue"
# Depends on monkeys-audio, flac, shntool, enconv, cuetag

outdir="output"
 
error() {
echo "$1"
exit $2
}
 
test $(which flac) || error "Error: FLAC convertor not found" 1

if [ ! -z "${2}" ]; then
test $(which shnsplit)	|| error "Please, install shntool first" 1
test $(which enconv)	|| error "Please, install enca first" 1
test $(which cuetag)	|| error "Please, install cuetools first" 1
fi
 
if 	[[ "$(file -b "${1}")" =~ "Monkey's Audio" ]]; then
		test $(which mac) || error "Error: Monkey Audio convertor not found" 1
		[ -e "${1%.*}.wav" ] && error "Error: "${1%.*}.wav" already exist, aborting" 1
		echo "Converting "$1" from APE to WAV-format"
		mac "$1" "${1%.*}.wav" -d
elif	[[ "$(file -b "${1}")" =~ "FLAC audio" ]]; then
		[ -e "${1%.*}.wav" ] && error "Error: "${1%.*}.wav" already exist, aborting" 1
		echo "Converting "$1" from FLAC to WAV-format"
		flac -d "${1}" -o "${1%.*}.wav"
elif	[[ "$(file -b "${1}")" =~ "WAVE audio" ]]; then
		echo "Ok, ${1} ready to splitting"
elif	[ "${1##*.}" == 'wv' ]; then
	test $(which wvunpack) || error "Error: WavPack decompressor not found" 1
	echo "Converting "$1" from WavPack to WAV-format"
	wvunpack -m "${1}"
else
	error "Can't recognize input file format"
fi
 
if [ -z "${2}" ]; then
	echo "CUE-sheet not specified, so we simply convert ${1} to FLAC format"
	flac --best -V "${1%.*}.wav" -o "${1%.*}.flac"
	exit 0
fi

[ -e $outdir ] && echo "Warning: $outdir already exist" || echo "Creating output directory"
mkdir -p "$outdir"
# Converting CUE-sheet
cat "${2}" | enconv > "${outdir}/${2}.converted"

echo "Splitting "${1%.*}.wav" to multiple FLAC files"
cd $outdir
cat "${2}.converted" | shnsplit -o 'flac flac --best -V - -o %f' -t %n-%p-%a-%t ../"${1%.*}.wav"
rm -f ../"${1%.*}.wav"

cuetag "${2}.converted" *.flac

ToDo: Сделать заполнение тегов по варианту скрипта drujebober'a, проверить, что все работает, для варианта FLAC->FLAC без CUE сделать сохранение тегов