用来下载音乐的脚本(测试版)
发表于 : 2007-11-25 16:16
我刚学linux shell编程不久,所以不能写出很简明的代码!请多多包含!标题已经说了!这只不过是测试版!存在的问题 1:只能搜索中文音乐。2:存在不能下载的情况(原因是网页源代码的歌曲中文名存在空格,我还没处理)3:有可能出先 not found 404错误,不过你再试几次就可以了 4:没有多任务。
以上问题会在下次解决(时间不能确定),以下是源代码:如果看不清分行就把代码复制到文本上就可以了!
————————————————华丽的分界线—————————————————————————————
#!bin/bash
read -p "请输入你要搜索的音乐:" a
echo $a>down.file #/*把要搜索的音乐储存在down.file文本里*/
iconv -f utf8 -t gb2312 down.file>down.file1 #/*把down.file里的文件转换成gb2312编码再储存到down.file1*/
b=`od -t x1 down.file1|awk 'BEGIN{OFS="%"}{$1=""}NF'` # /*把down.file里面的中文转换成16进制并且把值赋给变量b*/
wget "http://mp3.baidu.com/m?f=ms&tn=baidump3 ... "$b"&lm=-1" -O file # /*把百度搜索到的音乐网页的源代码下载并保存到file文件里*/
iconv -f gb2312 -t utf8 file |grep -m 1 "<td class=d><a href="|awk -F"," '{print $2}'|awk -F"&" '{print $1}'>down.file2 # /*把file的编码转换成utf8编码并搜索里面的连接信息并保存到down.file2文件里*/
iconv -f utf8 -t gb2312 down.file2>down.file3 #/*把down.file2转换成gb2312编码并保存到down.file文件里*/
url=`od -t x1 down.file3|awk 'BEGIN{OFS="%"}{$1=""}NF'|awk -F"%0a" '{print $1}'` #寻找你想要的音乐连接
url_1=`iconv -f gb2312 -t utf8 file |grep -m 1 "<td class=d><a href="|awk -F"\"" '{print $2}'|awk -F"," 'BEGIN{OFS=","}{$2="'$url'&word=mp3"}NF'`
wget "$url_1" -O file_1
iconv -f gb2312 -t utf8 file_1 |grep -m 1 "<a href" |awk -F"\"" '{print $2}'>down.file4 #得到你想要的最快的音乐连接
wget -t 5 -c -i down.file4 -O "$a".mp3 #下载音乐
rm down.file down.file1 down.file2 down.file3 file file_1 down.file4
刚建立的linux群 群号:39610328 欢迎你们加入
以上问题会在下次解决(时间不能确定),以下是源代码:如果看不清分行就把代码复制到文本上就可以了!
————————————————华丽的分界线—————————————————————————————
#!bin/bash
read -p "请输入你要搜索的音乐:" a
echo $a>down.file #/*把要搜索的音乐储存在down.file文本里*/
iconv -f utf8 -t gb2312 down.file>down.file1 #/*把down.file里的文件转换成gb2312编码再储存到down.file1*/
b=`od -t x1 down.file1|awk 'BEGIN{OFS="%"}{$1=""}NF'` # /*把down.file里面的中文转换成16进制并且把值赋给变量b*/
wget "http://mp3.baidu.com/m?f=ms&tn=baidump3 ... "$b"&lm=-1" -O file # /*把百度搜索到的音乐网页的源代码下载并保存到file文件里*/
iconv -f gb2312 -t utf8 file |grep -m 1 "<td class=d><a href="|awk -F"," '{print $2}'|awk -F"&" '{print $1}'>down.file2 # /*把file的编码转换成utf8编码并搜索里面的连接信息并保存到down.file2文件里*/
iconv -f utf8 -t gb2312 down.file2>down.file3 #/*把down.file2转换成gb2312编码并保存到down.file文件里*/
url=`od -t x1 down.file3|awk 'BEGIN{OFS="%"}{$1=""}NF'|awk -F"%0a" '{print $1}'` #寻找你想要的音乐连接
url_1=`iconv -f gb2312 -t utf8 file |grep -m 1 "<td class=d><a href="|awk -F"\"" '{print $2}'|awk -F"," 'BEGIN{OFS=","}{$2="'$url'&word=mp3"}NF'`
wget "$url_1" -O file_1
iconv -f gb2312 -t utf8 file_1 |grep -m 1 "<a href" |awk -F"\"" '{print $2}'>down.file4 #得到你想要的最快的音乐连接
wget -t 5 -c -i down.file4 -O "$a".mp3 #下载音乐
rm down.file down.file1 down.file2 down.file3 file file_1 down.file4
刚建立的linux群 群号:39610328 欢迎你们加入