- 论坛徽章:
- 0
|
写了个批量把ape+cue 转MP3的小脚本,刚学shell,不要取笑:
一个cue文件内容如下:
~# cat xx.cue
REM GENRE Gothic
REM DATE 2005
REM DISCID 9E11330B
REM COMMENT "ExactAudioCopy v0.95b4"
PERFORMER "Lacrimosa"
TITLE "Lichtgestalt"
FILE "Lacrimosa - Lichtgestalt.wav" WAVE
TRACK 01 AUDIO
TITLE "Sapphire"
PERFORMER "Lacrimosa"
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "Kelch der Liebe"
PERFORMER "Lacrimosa"
INDEX 01 11:15:50
TRACK 03 AUDIO
TITLE "Lichtgestalt"
PERFORMER "Lacrimosa"
INDEX 01 17:21:22
TRACK 04 AUDIO
TITLE "Nachtschatten"
PERFORMER "Lacrimosa"
INDEX 01 22:40:15
TRACK 05 AUDIO
TITLE "My Last Goodbye"
PERFORMER "Lacrimosa"
INDEX 00 29:46:37
INDEX 01 29:48:27
TRACK 06 AUDIO
TITLE "The Party Is Over"
PERFORMER "Lacrimosa"
INDEX 00 37:55:62
INDEX 01 37:59:15
TRACK 07 AUDIO
TITLE "Letzte Ausfahrt: Leben"
PERFORMER "Lacrimosa"
INDEX 01 43:28:35
TRACK 08 AUDIO
TITLE "Hohelied der Liebe"
PERFORMER "Lacrimosa"
INDEX 00 49:08:02
INDEX 01 49:12:52
TRACK 09 AUDIO
TITLE "+++ Stille +++"
PERFORMER "Lacrimosa"
INDEX 01 63:43:27
TRACK 10 AUDIO
TITLE "Hidden Track: The Party Is Over (Piano-Version)"
PERFORMER "Lacrimosa"
INDEX 01 64:43:37
现在写了脚本将里面的某些字符提取出来并作为lame的参数,因为cue不一定相同,某些字符可能不存在,要在参数传给lame前,把参数组织好,脚本如下:
~# cat ape_to_mp3_v0.11.sh
#!/bin/sh
#
# For APE & CUE file --> Mp3
#
# This script build high quality mp3 from APE.
# You just run it in the dir include APE & CUE file.
#
# Author : kevin.li823@gmail.com
#
APE_FILE=`ls *.ape`
CUE_FILE=`ls *.[cC][uU][eE]`
WAV_FILE=${APE_FILE%ape}wav
UTF_CUE_FILE='UTF.cue'
iconv -f gbk -t utf8 $CUE_FILE > $UTF_CUE_FILE
#mac $APE_FILE $WAV_FILE -d
echo "APE --> WAV Complete! "
echo "Start to split wav! "
#bchunk $WAV_FILE $CUE_FILE -w wav_
ALBUM=`grep 'TITLE' $CUE_FILE|sed -n '1p'|awk -F \" '{print $2}'|\
sed s/\ /_/g`
UTF_ALBUM=`grep 'TITLE' $UTF_CUE_FILE|sed -n '1p'|awk -F \" '{print $2}'|\
sed s/\ /_/g`
CD_ACTOR=`grep 'PERFORMER' $CUE_FILE|sed -n '1p'|awk -F \" '{print $2}'|\
sed s/\ /_/g`
GENRE=`grep ^REM $CUE_FILE|awk '{print ($2, $3)}'|grep ^GENRE |sed -n '1p'|\
awk '{print $2}'|\sed s/\ /_/g`
DATE=`grep ^REM $CUE_FILE|awk '{print ($2, $3)}'|grep ^DATE |sed -n '1p'|\
awk '{print $2}'|\sed s/\ /_/g`
[ -n $ALBUM ] && CD_INFO="--tl $ALBUM "
echo $CD_INFO
[ -n $GENRE ] && CD_INFO="${CD_INFO}""--tg ${GENRE} "
echo $CD_INFO
[ -n $DATE ] && CD_INFO="${CD_INFO}""--ty $DATA"
echo $CD_INFO
#############
echo $ALBUM
echo $GENRE
echo $DATE
echo "$ALBUM""$GENRE""$DATE"
#############
for i in `ls wav_*`
do
TRACK=`echo $i|sed s/wav_//g|sed s/.wav//g`
TITLE=`sed -n "/TRACK[\ \ ]"$TRACK"/,$"p $CUE_FILE|grep TITLE|\
sed -n '1p'|awk -F \" '{print $2}'|sed s/\ /_/g`
UTF_TITLE=`sed -n "/TRACK[\ \ ]"$TRACK"/,$"p $UTF_CUE_FILE|grep TITLE|\
sed -n '1p'|awk -F \" '{print $2}'|sed s/\ /_/g`
ACTOR=`sed -n "/TRACK[\ \ ]"$TRACK"/,$"p $CUE_FILE|grep PER|\
sed -n '1p'|awk -F \" '{print $2}'|sed s/\ /_/g`
[ -z $ACTOR ] && ACTOR=$CD_ACTOR
echo
echo "========== Now Laming $UTF_TITLE =========="
sleep 1
[ -n $TITLE ] && NAME=`echo $TRACK\_$UTF_TITLE.mp3`
[ -n $TRACK ] && LAME_INFO=" --tn $TRACK "
[ -n $TITLE ] && LAME_INFO="$LAME_INFO --tt $TITLE "
[ -n $ACTOR ] && LAME_INFO="$LAME_INFO --ta $ACTOR "
LAME_INFO="${LAME_INFO} --tc Made_by_Kevin_Li"
echo $CD_INFO
echo $LAME_INFO
# echo $a$b
# lame -b 32 -m j -h -V 0 -B 320 -q 0 --noath -k --id3v2-only --tt\
# $TITLE --ta $ACTOR --tl $ALBUM --tc Made_by_Kevin_Li --tn\
# $TRACK $i $NAME
# lame -b 32 -m j -h -V 0 -B 320 -q 0 --noath -k --id3v2-only \
# $LAME_IMFO $i $NAME
LAME_INFO=""
echo "========== Lame $UTF_TITLE Done! =========="
echo
done
#[ -n `ls *.mp3` ] && rm *.wav
#rm $UTF_CUE_FILE
#mkdir \[$UTF_ALBUM\]\_\[MP3\]
#mv *.mp3 \[$UTF_ALBUM\]\_\[MP3\]
echo
echo "===================== All Done! ======================="
执行后,打印信息为:
Start to split wav!
--tl Lichtgestalt
--tl Lichtgestalt --tg Gothic
--tyLichtgestalt --tg Gothic ###此行出现问题
Lichtgestalt
Gothic
2005
2005tgestaltGothic ###此行出现问题
========== Now Laming Sapphire ==========
--tyLichtgestalt --tg Gothic
--tn 01 --tt Sapphire --ta Lacrimosa --tc Made_by_Kevin_Li ###这一行打印也有问题
========== Lame Sapphire Done! ==========
===================== All Done! =======================
其中####框内###的打印信息为:
Lichtgestalt
Gothic
2005
2005tgestaltGothic
三个变量结合的时候却变成了2005tgestaltGothic,理论上讲应该是:LichtgestaltGothic2005
该脚本在Debian4.0,ubuntu 8.04 9.04上运行都出现同意问题,希望高手指教
ape_to_mp3.zip
(1.55 KB, 下载次数: 24)
[ 本帖最后由 jinmengshi 于 2009-5-15 16:19 编辑 ] |
|