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

Материал из Linux Wiki
Перейти к навигацииПерейти к поиску
Строка 9: Строка 9:
# By Rain ;)
# By Rain ;)
# Usage: cueape2flac "AUDIO FILE.ape" "TEXT FILE.cue"
# Usage: cueape2flac "AUDIO FILE.ape" "TEXT FILE.cue"
# Depends on monkeys-audio, flac, shntool, enconv, cuetag
# Depends on monkeys-audio, flac, shntool
 
outdir='output'
direct='0'


outdir="output"
error() {
error() {
echo "$1"
echo "$1"
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
if [ ! -z "${2}" ]; then
test $(which shnsplit) || error "Please, install shntool first" 1
test $(which shnsplit) || error "Please, install shntool first" 1
test $(which enconv) || error "Please, install enca first" 1
test $(which enconv) || error "Please, install enca first" 1
test $(which cuetag) || error "Please, install cuetools first" 1
test $(which cuetag) || error "Please, install cuetools first" 1
else
direct='0'
echo "CUE-sheet not specified, so we simply convert ${1} to FLAC format"
fi
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
[ -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
elif [ "${1##*.}" == 'wv' ]; then
test $(which wvunpack) || error "Error: WavPack decompressor not found" 1
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
fi


[ -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
tempfile="$(date +tempfile.%s)"
cat "${2}" | enconv > "${outdir}/${2}.converted"


echo "Splitting "${1%.*}.wav" to multiple FLAC files"
if [ "${direct}" == '0' ]; then
cd $outdir
if [[ "$(file -b "${1}")" =~ "Monkey's Audio" ]]; then
cat "${2}.converted" | shnsplit -o 'flac ext=flac flac --best -V - -o %f' -t %n-%p-%a-%t ../"${1%.*}.wav"
echo "Converting "$1" from APE to WAV-format"
rm -f ../"${1%.*}.wav"
mac "$1" "${outdir}/${tempfile}.wav" -d
elif [[ "$(file -b "${1}")" =~ "FLAC audio" ]]; then
echo "Converting "$1" from FLAC to WAV-format"
flac -d "${1}" -o "${outdir}/${tempfile}.wav"
elif [[ "$(file -b "${1}")" =~ "WAVE audio" ]]; then
echo "Ok, ${1} ready to splitting, linking to ${outdir}"
ln "${1}" "${outdir}/${tempfile}.wav"
elif [ "${1##*.}" == 'wv' ]; then
echo "Converting "$1" from WavPack to WAV-format"
wvunpack -m "${1}"
mv "${1%.*}.wav" "${outdir}/${tempfile}.wav"
else
error "Can't recognize input file format" 1
fi
else
if [ "${1##*.}" == 'wv' ]; then
echo "Converting "$1" from WavPack to WAV-format"
wvunpack -m "${1}"
mv "${1%.*}.wav" "${outdir}/${tempfile}.wav"
else
ln "${1}" "${outdir}/${tempfile}.${1##*.}"
fi
fi
 
cd "${outdir}"
 
if [ -z "${2}" ]; then
flac --best -V "${tempfile}.wav" -o "${1%.*}.flac"
else
# Converting CUE-sheet
cat ../"${2}" | enconv > "${2}"
echo "Splitting "${1}" to multiple FLAC files"
cat "${2}" | shnsplit -o 'flac ext=flac flac --best -V - -o %f' -t %n-%p-%a-%t "${tempfile}"*
 
cuetag "${2}" *.flac
fi


cuetag "${2}.converted" *.flac
rm -f "${tempfile}"*
exit 0
</source>
</source>
----
----

Версия 17:27, 6 марта 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

outdir='output'
direct='0'

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
else
	direct='0'
	echo "CUE-sheet not specified, so we simply convert ${1} to FLAC format"
fi

if	[[ "$(file -b "${1}")" =~ "Monkey's Audio" ]]; then
		test $(which mac)	|| error "Error: Monkey Audio convertor not found" 1
elif	[ "${1##*.}" == 'wv' ]; then
		test $(which wvunpack)	|| error "Error: WavPack decompressor not found" 1
fi

[ -e $outdir ] && echo "Warning: $outdir already exist" || echo "Creating output directory"
mkdir -p "$outdir"
tempfile="$(date +tempfile.%s)"

if [ "${direct}" == '0' ]; then
	if 	[[ "$(file -b "${1}")" =~ "Monkey's Audio" ]]; then
			echo "Converting "$1" from APE to WAV-format"
			mac "$1" "${outdir}/${tempfile}.wav" -d
	elif	[[ "$(file -b "${1}")" =~ "FLAC audio" ]]; then
			echo "Converting "$1" from FLAC to WAV-format"
			flac -d "${1}" -o "${outdir}/${tempfile}.wav"
	elif	[[ "$(file -b "${1}")" =~ "WAVE audio" ]]; then
			echo "Ok, ${1} ready to splitting, linking to ${outdir}"
			ln "${1}" "${outdir}/${tempfile}.wav"
	elif	[ "${1##*.}" == 'wv' ]; then
		echo "Converting "$1" from WavPack to WAV-format"
		wvunpack -m "${1}"
		mv "${1%.*}.wav" "${outdir}/${tempfile}.wav"
	else
		error "Can't recognize input file format" 1
	fi
else
	if 	[ "${1##*.}" == 'wv' ]; then
		echo "Converting "$1" from WavPack to WAV-format"
		wvunpack -m "${1}"
		mv "${1%.*}.wav" "${outdir}/${tempfile}.wav"
	else
		ln "${1}" "${outdir}/${tempfile}.${1##*.}"
	fi
fi

cd "${outdir}"

if [ -z "${2}" ]; then
	flac --best -V "${tempfile}.wav" -o "${1%.*}.flac"
else
	# Converting CUE-sheet
	cat ../"${2}" | enconv > "${2}"
	
	echo "Splitting "${1}" to multiple FLAC files"
	cat "${2}" | shnsplit -o 'flac ext=flac flac --best -V - -o %f' -t %n-%p-%a-%t "${tempfile}"*

	cuetag "${2}" *.flac
fi

rm -f "${tempfile}"*
exit 0

ToDo: для варианта FLAC->FLAC без CUE сделать сохранение тегов, добавить вытягивание CUE из FLAC