分页: 1 / 1

APE转MP3 + gb2312问题

发表于 : 2010-05-26 23:10
wudaown
于是咱在学bash script
所以咱写了个ape2mp3的脚本
这个 是可以处理多个ape和cue的 .. 不过还没写好

代码: 全选

#!/bin/bash

apelist=$(ls | grep ape$)
#echo -e $apelist

echo "$apelist" | while read apefile
				do
				echo  -e "$apefile"
				wavlist="$(echo $apefile  | sed 's/ape/wav/g')"
				echo -e $wavlist
		    	mac "$apefile" "$wavlist" -d
				echo  "$wavlist" | while read wavfile
										do
												lame -h -b 320 "$wavfile"
												done
				mp3list=$( echo $wavlist | sed 's/wav/wav.mp3/g')
				echo -e $mp3list
				cuelist=$(echo $apefile | sed 's/ape/cue/g')
				echo -e $cuelist
				mp3splt -c "$cuelist" -o @b.@n.@t "$mp3list"
				rm "$mp3list"
				cuetag "$cuelist" "./*.mp3"
				done

mp3dir=$(ls | grep ape$ | sed 's/.ape//g')
echo  "$mp3dir" | while read mp3fl
		do
				echo -e "$mp3fl"
				mkdir "$mp3fl"
				done

这个处理一个APE和一个CUE基本完成了 。。 不过有一个问题就是要输入绝对路径 ..

代码: 全选

#!/bin/bash
# 读取ape文件目录,暂时只能输入绝对路径   

read -p "Please enter the directory where APE file is: " apedir
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


mac "$(echo $apefile)" "$wavfile" -d # 用mac来转换
lame -h -b 320 "$wavfile" # 用lame 转 mp3
mp3splt -c "$cuefile" -o @n.@t "$mp3file" # 用mp3splt来分割
rm "$mp3file" # 删除前面产生的wav.mp3
cuetag "$cuefile" *.mp3 # 用cuetag写入mp3 tag

read -p "Do you want to del the wav file:[y/n]" wavdel
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
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 - "You have choosen an invaild option"
				fi

第一就是read第一个读取的变量是ape文件的path
不过在运行的时候不能用tab只能写绝对路径

第二个就是如果有多个APE和CUE文件会很麻烦 ..
不过我大概想到用for来改了

最后就是有一些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
比如说下个的这个cue文件 ..
cue还是问题

Re: 于是咱丢来论坛问问了 APE转MP3

发表于 : 2010-05-26 23:35
eexpress
字符处理这么多,应该用perl了。

Re: 于是咱丢来论坛问问了 APE转MP3

发表于 : 2010-05-26 23:45
wudaown
eexpress 写了:字符处理这么多,应该用perl了。
从基础学起 。。于是先学bash script
所以 。。我相信bash是可以做到的
:em06

Re: 于是咱丢来论坛问问了 APE转MP3

发表于 : 2010-05-26 23:57
delectate
我想如果是我就用c解决了……

参考这个吧

viewtopic.php?f=74&t=211609&start=0

Re: 于是咱丢来论坛问问了 APE转MP3

发表于 : 2010-05-27 0:16
wudaown
delectate 写了:我想如果是我就用c解决了……

参考这个吧

viewtopic.php?f=74&t=211609&start=0
这些我都会 .. 其实咱的重点是透过这个来学习script但说转换其实挺简单的
话说那个编码的问题呢

Re: 于是咱丢来论坛问问了 APE转MP3

发表于 : 2010-05-27 7:33
c\nc
还是用shntool吧,bash弄这个太麻烦了。

Re: 于是咱丢来论坛问问了 APE转MP3

发表于 : 2010-05-27 9:55
wudaown
c\nc 写了:还是用shntool吧,bash弄这个太麻烦了。
那那个编码的问题呢?

Re: APE转MP3 + for语法问题

发表于 : 2010-05-27 10:10
eexpress
for i in `ls -tr *.mp4`

额,别听ls的

enca干嘛。是enconv

Re: APE转MP3 + for语法问题

发表于 : 2010-05-27 10:24
wudaown
eexpress 写了:for i in `ls -tr *.mp4`

额,别听ls的

enca干嘛。是enconv
话说enconv的语法是?
man page里没看到

另外一位告诉我这样写

代码: 全选

  1 #!/bin/bash
  2 
  3 apelist=$(ls | grep ape$)
  4 echo -e $apelist
  5 
  6 echo "$apelist" | while read apefile
  7                 do
  8                 echo  "File is $apefile"
  9                 done

Re: APE转MP3 + for语法问题

发表于 : 2010-05-27 10:28
eexpress
while嘛。那是管道的写法。你试试我的

enconv 就是enca带的命令,是自动转码的。enca本身只是判断编码,并不转码
你多man enca

Re: APE转MP3 + for语法问题

发表于 : 2010-05-27 10:37
wudaown
eexpress 写了:while嘛。那是管道的写法。你试试我的

enconv 就是enca带的命令,是自动转码的。enca本身只是判断编码,并不转码
你多man enca
我换了个新的cue附件 .. 请帮我试试 ..
不成功 .. 话说那个while 里面的read是什么?读取apefile变量?
你的我也去试试

Re: APE转MP3 + gb2312问题

发表于 : 2010-05-27 13:39
wudaown
继续等高人来解答