Ubuntu 用户可以通过aptitude安装全部除了mac
sudo aptitude install mp3splt lame cuetag tofrdos
mac 要通过http://supermmx.org/resources/linux/mac/mac-3.99-u4-b5.tar.gz
来编译安装
script如下
#!/bin/bash
# wudaown 蛋疼作品 .. 其实是学习shell script时候写的
# 于是有三个缺点
# 第一:暂时只支持绝对路径,程序会询问用户ape文件在那里 .. 这个时候只能
输入绝对路径
# 于是我建议使用是把文件移动到/tmp等目录比较简单一点
# 第二:没有加入cue文件的编码处理功能,不过对 utf-8和用户读不乱码的cue完
美支持
# 第三:目前只单个ape和cue文件的处理,多个ape和cue文件处理的script正在写
PS:不知道写给谁的 ?
# 于是就这样吧 .. 有空在改改
read -p "Please enter the directory where APE file is: " apedir # 读取
ape文件目录,暂时只能输入绝对路径
if [ -e "$apedir" ] ; then # 给目录变数appdir
cd $apedir
else
echo -e "The directory does not exists" # 如果目录不存
在就退出
exit 0
fi
echo -e "Your are current at $apedir" # 显示出目录名
echo -e "Check if Ape file exists" # 检查ape存见存在与否
if test -e *.[aA][pP][eE] ; then # 用test测试存在与否
echo -e "There is Ape file and the file is"
ls | grep [aA][pP][eE]$
else
echo -e "Not Ape file"
exit 0
fi
apefile=$(ls | grep [aA][Pp][eE]$) # 定义apefile 变数
wavfile=$(echo $apefile | sed 's/[aA][pP][eE]$/wav/g') #定义wav文件变数
cuefile=$(ls | grep [Cc][Uu][Ee]$) # 定义cue变数
mp3file=$(echo $wavfile | sed 's/wav$/wav.mp3/g') # 定义mp3文件变数
#-----------------------------------------------------------------------
#This is testing on the for loop
echo -e " -------------- Start converting ape file to wav file
--------------"
mac "$(echo $apefile)" "$wavfile" -d # 用mac来转换
echo -e "--------------- Converting from ape file to wav file has
completed ---------------"
echo -e " ------------- Start converting wav file to mp3 file
---------------"
lame -h -b 320 "$wavfile" # 用lame 转 mp3
echo -e " -------------- Converting wav file to mp3 file has completed
---------------"
echo -e " -------------- Start spliting one mp3 file into mulit mp3
files -----------------"
mp3splt -c "$cuefile" -o @n.@t "$mp3file" # 用mp3splt来分割
echo -e " ------------ Spliting finished ---------------- "
rm "$mp3file" # 删除前面产生的wav.mp3
echo -e " ----------- Writing tags into mp3 file ----------- "
cuetag "$cuefile" *.mp3 # 用cuetag写入mp3 tag
echo -e " -------------- Finish writing tags into mp3 files
-----------------"
read -p "Do you want to del the wav file:[y/n]" wavdel # 询问要不要删除
刚才生成的wav文件
if [ "$wavdel" == "y" -o "$wavdel" == "Y" ] ; then
echo -e "$wavfile will be removed"
rm "$wavfile"
elif [ "$wavdel" == "n" -o "$wavdel" == "N" ] ; then
echo -e "$wavfile will be kept"
else
echo -e "Your have choosen an invaild option"
fi
read -p "Do you want to del the ape file:[y/n]" apedel #询问要不要删除
ape文件
if [ "$apedel" == "y" -o "$apedel" == "Y" ] ; then
echo -e "$apefile will be removed"
rm "$apefile"
elif [ "$apedel" == "n" -o "$apedel" == "N" ] ; then
echo -e "$apefile will be kept"
else
echo -e "You have choosen an invaild option"
fi
read -p "Do you want to del the cue file:[y/n]" cuedel # 询问要不要删除
cue文件
if [ "$cuedel" == "y" -o "$cuedel" == "Y" ] ; then
echo -e "$cuefile will be removed"
rm "$cuefile"
elif [ "$cuedel" == "n" -o "$cuedel" == "N" ] ; then
echo -e "$cuefile will be kept"
else
echo -e "You have choosen an invaild option"
fi
--------------------------------------
其实问题就是针对上面我说的缺点的
然后关于编码也有一个问题有一些gb2312编码的cue文件
不过我用什么指令转换到utf-8都继续呈现乱码
比如
iconv -f gb2312 -t utf-8 cuefile
enca -L zh_CN -x utf-8 cuefile
piconv -f gb2312-raw -t utf-8 cuefile
enconv cuefile
我附件放了一个这样的cue文件
---------------------
然后有一个还在写的script,各位看看就好
1 #!/bin/bash
2
3 apelist=$(ls | grep ape$)
4 #echo -e $apelist
5
6 echo "$apelist" | while read apefile
7 do
8 echo -e "$apefile"
9 wavlist="$(echo $apefile | sed 's/ape/wav/g')"
10 echo -e $wavlist
11 mac "$apefile" "$wavlist" -d
12 echo "$wavlist" | while read wavfile
13 do
14 lame -h -b 320
"$wavfile"
15 done
16 mp3list=$( echo $wavlist | sed 's/wav/wav.mp3/g')
17 echo -e $mp3list
18 cuelist=$(echo $apefile | sed 's/ape/cue/g')
19 echo -e $cuelist
20 mp3splt -c "$cuelist" -o @n.@t-@b "$mp3list"
21 echo "$mp3list" | while read mp3dir
22 do
23
24 rm "$mp3list"
25 cuetag "$cuelist" *.mp3
26 done
---------------------------
未完成的
谢谢
--
Sign by WD
http://wdstudio.blogbus.com
这里的问题说的是 "for apefile in $apelist" 把 $apelist 中的字符串按空格截断了,
实际上写 Shell 也有效率问题,尽量不要使用 "apelist=$(ls | grep ape$)" 这种会启动两个外部程序,事实上
$apelist 这个变量也完全没必要,直接使用 Shell 内置 "*.ape" 得到所有 ape 文件列表;你需要的功能代码直接使用
for apefile in *.ape; do echo "File is $apefile"; done
完成。多用 Shell 内置功能, 所有在 Shell 命令行可用的 trick 几乎都可以写进 Shell 脚本。
>
> Underground 5.0.ape Underground 6.0.ape
> File is Music 1.ape
> File is Music 2.ape
> 请问要怎么写呢?
> 先谢谢各位了
>
> --
> 你收到本邮件是因为订阅了 "Linux/Ubuntu 新加坡 中文用户组",
> 发送邮件请至: ubuntu...@googlegroups.com, 注意:回复邮件请使用 "回复所有人" "Reply to ALL"
> 更多消息请查看 http://groups.google.com/group/ubuntu-sg-zh
>
--
Cheng Renquan (程任全), from Singapore
2010/5/27 wd <wud...@gmail.com>:
> 某目录下有这些文件
> Underground 5.0.ape Underground 5.0.cue Underground 6.0.ape
> Underground 6.0.cue
> script如下
> 1 #!/bin/bash
> 2
> 3 apelist=$(ls | grep ape$)
> 4 #echo -e $apelist
> 5
> 6 echo "$apelist" | while read apefile
这里同样替换成 "for apefile in *.ape"
> 7 do
> 8 echo -e "$apefile"
> 9 wavlist="$(echo $apefile | sed 's/ape/wav/g')"
这句可以替换成 wavfile=${apefile/%ape/wav} 原则是能不用外部程序(sed)尽量不用
$apefile 里面存的不是单个文件吗?为什么换wav成了wavlist,你想表达什么意思?一个ape会对应多个wav文件吗?这一点我对ape格式不太了解;
具体请查阅 man bash 里面的 Parameter Expansion 节,
> 10 echo -e $wavlist
> 11 mac "$apefile" "$wavlist" -d
> 12 echo "$wavlist" | while read wavfile
> 13 do
> 14 lame -h -b 320
> "$wavfile"
> 15 done
这个循环就因为不确认一个apefile对应多个wav文件,所以才用wavlist,才用到循环?
> 16 mp3list=$( echo $wavlist | sed 's/wav/wav.mp3/g')
同样这里可以使用 mp3file=${wavfile/%wav/mp3}
> 17 echo -e $mp3list
> 18 cuelist=$(echo $apefile | sed 's/ape/cue/g')
这里对应使用 cuefile=${apefile/%ape/cue}
> 19 echo -e $cuelist
> 20 mp3splt -c "$cuelist" -o @n-@t "$mp3list"
> 21 rm "$mp3list"
> 22 fmp3="$(ls | grep mp3$)"
> 23 cuetag "$cuelist" "$(ls | grep mp3$)"
不知ape/cue/wav/mp3是否都是一一对应的,每次产生的"$mp3list"文件马上被删除了?然后再ls列出所有mp3文件一次?
> 24 done
> 25
> 26 mp3dir=$(ls | grep ape$ | sed 's/.ape//g')
> 27 echo "$mp3dir" | while read mp3fl
对应 for apefile in *.ape; do
mkdir "${apefile/%.ape}"
done
> 28 do
> 29 echo -e "$mp3fl"
> 30 mkdir "$mp3fl"
> 31 done
最后一遍循环是mkdir空目录?然后呢?
>
> 运行一路都没问题 .. 可是到了22和23行的时候问题来了
> 输出如下,前后正常输出去掉
> -----------------------------------------------------------------------
> File "6-Jigga What _ Faint (Live).mp3" created
> Processed 47709 frames - Sync errors: 0
> file split (EOF)
>
>
> +-----------------------------------------------------------------------------+
> |NOTE: When you use cddb/cue, split files might be not very precise due
> to:|
> |1) Who extracts CD tracks might use "Remove silence" option. This
> means that |
> | the large mp3 file is shorter than CD Total time. Never use this
> option. |
> |2) Who burns CD might add extra pause seconds between tracks. Never
> do it. |
> |3) Encoders might add some padding frames so that file is longer
> than CD. |
> |4) There are several entries of the same cd on CDDB, find the best for
> yours.|
> | Usually you can find the correct splitpoints, so good luck! |
>
> +-----------------------------------------------------------------------------+
> | TRY TO ADJUST SPLITS POINT WITH -a OPTION. Read man page for more
> details! |
>
> +-----------------------------------------------------------------------------+
>
> warning: number of files does not match number of tracks
> Error opening MP3: 1-Somewhere I Belong (Live).mp3
> 2-Breaking the Habit (Live).mp3
> 3-Public Service Announcement - Intro (Live).mp3
> 4-Dirt Off Your Shoulder _ Lying from You (Live).mp3
> 5-Big Pimpin' _ Papercut (Live).mp3
> 6-Jigga What _ Faint (Live).mp3: No such file or directory
> Error opening MP3: 1-Somewhere I Belong (Live).mp3
> 2-Breaking the Habit (Live).mp3
> 3-Public Service Announcement - Intro (Live).mp3
> 4-Dirt Off Your Shoulder _ Lying from You (Live).mp3
> 5-Big Pimpin' _ Papercut (Live).mp3
> 6-Jigga What _ Faint (Live).mp3: No such file or directory
> Error opening MP3: 1-Somewhere I Belong (Live).mp3
> 2-Breaking the Habit (Live).mp3
> 3-Public Service Announcement - Intro (Live).mp3
> 4-Dirt Off Your Shoulder _ Lying from You (Live).mp3
> 5-Big Pimpin' _ Papercut (Live).mp3
> 6-Jigga What _ Faint (Live).mp3: No such file or directory
> Underground 6.0.ape
> Underground 6.0.wav
> --- Monkey's Audio Console Front End (v 3.99) (c) Matthew T. Ashland ---
> -----------------------------------------------------------------
> 主要是在warning的地方 .. 用cuetag写入tag出错
> cue文件一定没有问题
> cuetag cuefile *.mp3写入没有问题
>
> 先谢谢了
>
> --
> Sign by WD
> http://wdstudio.blogbus.com
>
> --
> 你收到本邮件是因为订阅了 "Linux/Ubuntu 新加坡 中文用户组",
> 发送邮件请至: ubuntu...@googlegroups.com, 注意:回复邮件请使用 "回复所有人" "Reply to ALL"
> 更多消息请查看 http://groups.google.com/group/ubuntu-sg-zh
>
2010/5/27 wd <wud...@gmail.com>:
> 于是需要mp3splt lame mac cuetag tofrdos
>
> Ubuntu 用户可以通过aptitude安装全部除了mac
>
> sudo aptitude install mp3splt lame cuetag tofrdos
>
> mac 要通过http://supermmx.org/resources/linux/mac/mac-3.99-u4-b5.tar.gz
> 来编译安装
>
> script如下
>
> #!/bin/bash
> # wudaown 蛋疼作品 .. 其实是学习shell script时候写的
> # 于是有三个缺点
> # 第一:暂时只支持绝对路径,程序会询问用户ape文件在那里 .. 这个时候只能
> 输入绝对路径
昨天当面谈的时候我就觉得这个编程任务很常见,应该早有人解决了,今天回来帮你查了 bash manual 文档,使用 read 带 -e
参数即可,加上了 readline 支持,自动支持 filename 的 auto-completion,
read -e -p "...." var
> # 于是我建议使用是把文件移动到/tmp等目录比较简单一点
> # 第二:没有加入cue文件的编码处理功能,不过对 utf-8和用户读不乱码的cue完
> 美支持
使用 iconv 转换,
> # 第三:目前只单个ape和cue文件的处理,多个ape和cue文件处理的script正在写
多个文件不是已经写了吗?就是使用循环解决的,每次循环内处理一个文件;
> PS:不知道写给谁的 ?
> # 于是就这样吧 .. 有空在改改
>
> read -p "Please enter the directory where APE file is: " apedir # 读取
> ape文件目录,暂时只能输入绝对路径
> if [ -e "$apedir" ] ; then # 给目录变数appdir
> cd $apedir
> else
> echo -e "The directory does not exists" # 如果目录不存
> 在就退出
> exit 0
> fi
> echo -e "Your are current at $apedir" # 显示出目录名
> echo -e "Check if Ape file exists" # 检查ape存见存在与否
> if test -e *.[aA][pP][eE] ; then # 用test测试存在与否
> echo -e "There is Ape file and the file is"
> ls | grep [aA][pP][eE]$
> else
> echo -e "Not Ape file"
> exit 0
> fi
> apefile=$(ls | grep [aA][Pp][eE]$) # 定义apefile 变数
这个可以写 apefile="*.[aA][Pp][eE]"
> wavfile=$(echo $apefile | sed 's/[aA][pP][eE]$/wav/g') #定义wav文件变数
对应的, wavfile=${apefile/%[aA][pP][eE]/wav}
Yes or No 的选单式问题可以尝试使用 select
> if [ "$cuedel" == "y" -o "$cuedel" == "Y" ] ; then
> echo -e "$cuefile will be removed"
> rm "$cuefile"
> elif [ "$cuedel" == "n" -o "$cuedel" == "N" ] ; then
> echo -e "$cuefile will be kept"
> else
> echo -e "You have choosen an invaild option"
> fi
>
> --------------------------------------
>
> 其实问题就是针对上面我说的缺点的
> 然后关于编码也有一个问题有一些gb2312编码的cue文件
> 不过我用什么指令转换到utf-8都继续呈现乱码
> 比如
> iconv -f gb2312 -t utf-8 cuefile
>
> enca -L zh_CN -x utf-8 cuefile
>
> piconv -f gb2312-raw -t utf-8 cuefile
>
> enconv cuefile
>
> 我附件放了一个这样的cue文件
这个文件试过了 iconv 可以转换成功,编码要用上 GBK/GB18030 才行,
$ iconv -f GBK -t UTF-8 ~/文档/ANZB-9651~9652.cue/ANZB-9651~9652.cue; echo
TITLE "WORKING!! OPED - SOMEONE ELSE | ハートのエッジに挑もう Go to Heart Edge"
FILE "ANZB-9651~9652.ape" WAVE
TRACK 01 AUDIO
TITLE "SOMEONE ELSE"
PERFORMER "種島ぽぷら(阿澄佳奈)·伊波まひる(藤田咲)·轟八千代(喜多村英梨)"
ISRC JPE301000261
INDEX 01 00:00:00
TRACK 02 AUDIO
TITLE "ハートのエッジに挑もう Go to Heart Edge"
PERFORMER "小鳥遊宗太(福山潤)·佐藤潤(小野大輔)·相馬博臣(神谷浩史)"
ISRC JPE301000262
INDEX 01 04:37:40
TRACK 03 AUDIO
TITLE "SOMEONE ELSE(Off Vocal Version)"
PERFORMER "神前暁(MONACA)"
ISRC JPE301000263
INDEX 00 08:38:09
INDEX 01 08:39:74
TRACK 04 AUDIO
TITLE "ハートのエッジに挑もう Go to Heart Edge(Off Vocal Version)"
PERFORMER "神前暁(MONACA)"
ISRC JPE301000264
INDEX 01 13:17:34
请尝试以上改进,减少冗余。
>
> ---------------------------
> 未完成的
>
> 谢谢
> --
> Sign by WD
> http://wdstudio.blogbus.com
>
> --
> 你收到本邮件是因为订阅了 "Linux/Ubuntu 新加坡 中文用户组",
> 发送邮件请至: ubuntu...@googlegroups.com, 注意:回复邮件请使用 "回复所有人" "Reply to ALL"
> 更多消息请查看 http://groups.google.com/group/ubuntu-sg-zh
>
以上我的改进 Shell 以 openSuSE 11.2 上的 GNU bash 4.0.35 为实验环境调试通过;
suseuser@linux-machine:~/tmp> bash --version
GNU bash, version 4.0.35(1)-release (i586-suse-linux-gnu)
Copyright (C) 2009 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
wudao 还需要学习的东西多多啦,鸟哥的书当然是很经典的学习教材,但经典也同时意味着不一定能够反映今天的2010年最新Linux发行上的先进的东西,所以书上讲的要经常对照电脑再查一遍电脑上的文档,看是否有新的先进的写法,常阅读
man bash, 有很多先进的语法。中文文件编码知识 GB2312/GBK/GB18030 也有待加强。
不过有些朋友要写的 Shell 脚本要求可移植性,在旧版系统上也要能正常运行,那是例外。
wudao 同学在新加坡上中学,周围能够请教到的玩 Linux 玩编程的懂行的人非常少,即使一个人也还在坚持学习编程,颇为不易,请他的家乡上海人民多多支持。
To shlug 朋友,我没有订阅 shlug 邮件列表,有需要回复我的请加抄送。谢谢。
--
Cheng Renquan, Singapore
首先第一个
apefile=$(ls -tr *.ape)
echo -e $apefile
wavfile=${apefile//ape/wav} # 考虑到可能一串字符之用/%的话只能替换最后一
个 ,事实证明是正确的
echo -e $wavfile
输出如下
Underground 6.0.ape Underground 5.0.ape
Underground 6.0.wav Underground 5.0.wav
第二个用bash内置的*.ape
apefile=*.ape
echo -e $apefile
wavfile=${apefile//ape/wav}
echo -e $wavfile
输出结果如下
Underground 5.0.ape Underground 6.0.ape
*.wav
第三个我写成了
apefile=*.[Aa][Pp][Ee]
echo -e $apefile
wavfile=${apefile//ape/wav}
echo -e $wavfile
输出如下
Underground 5.0.ape Underground 6.0.ape
Underground 5.0.ape Underground 6.0.ape
------------------------------------------------------------------------
在for的循环中则没有问题 ..
for apefile in *.[Aa][Pp][Ee]
do
echo -e $apefile
wavfile=${apefile//ape/wav}
echo -e ${wavfile}
done
输出如下
Underground 5.0.ape
Underground 5.0.wav
Underground 6.0.ape
Underground 6.0.wav
--------------------------------------------------------------------
我想的是for循环中一次处理一个文件所以可以完美的达到效果
运用最上面的3种写法,就算在某路径下只有一个ape文件也只有第一个调用ls的可
以达到效果 ..
我又做了其他很多实验,结果都是差不多的
-----------------------------------------------------------------
另外我也写了一个select的简单选项,查了man page好像有点不太一样
如下
71 echo -e "Do you want to del the wav file"
72 select wavdel in "Yes" "No"
73 do
74 break
75 done
76 if [ "wavdel" == "Yes" ]
77 then
78 echo -e "Wav file is removed"
79 rm $wavfile
80 elif [ "wavdel" == "No" ]
81 then
82 echo -e "Wav file is kept"
83 else
84 echo -e "Invaild input"
85 fi
--------------------------------------------------------------
另外其实昨天我放的附件错了 .... 重新放一个新的附件
----------------------------------------------------------------
谢谢