我刚学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 欢迎你们加入
用来下载音乐的脚本(测试版)
-
- 帖子: 21
- 注册时间: 2007-09-18 7:55
- arsui
- 帖子: 889
- 注册时间: 2007-05-06 2:01
- 来自: 特麓村->浦北->五山->罗湖
顶一下勤劳而无私的银~~~
顶呱呱~
顶呱呱~
Ubuntu 9.04 & Win Xp
------------------------------------------------------
Company: http://www.mazingtech.com
HomePage: http://www.arsui.com
------------------------------------------------------
Company: http://www.mazingtech.com
HomePage: http://www.arsui.com
- percy
- 帖子: 508
- 注册时间: 2006-09-10 8:19
- 系统: Gentoo/Mac OS X
- 来自: Shanghai,China
- 联系:
- arsui
- 帖子: 889
- 注册时间: 2007-05-06 2:01
- 来自: 特麓村->浦北->五山->罗湖
好用~,不过写个保存路径就更好~防止我这个新手不会自己写
Ubuntu 9.04 & Win Xp
------------------------------------------------------
Company: http://www.mazingtech.com
HomePage: http://www.arsui.com
------------------------------------------------------
Company: http://www.mazingtech.com
HomePage: http://www.arsui.com
- aitilang
- 帖子: 1026
- 注册时间: 2007-04-28 21:38
-
- 帖子: 22
- 注册时间: 2007-03-01 15:22
- 来自: 广州
代码: 全选
#!/bin/bash
if [ $# -ne 2 ] ; then
echo "Usage: `basename $0` THE_SONG_TO_DOWN No."
exit 192
else
SONG=`echo $1 | iconv -f utf8 -t gbk | sed -e 's/_/+/g'`
SRC='http://mp3.baidu.com/m?f=ms&rn=&tn=baidump3&ct=134217728&word='
wget -O ./temp/down.html ${SRC}${SONG}\&lm=0
grep "m?ct=134217728&tn=baidusg" ./temp/down.html |\
sed -e 's/<td class=d>//g' -e 's/<a href=\"//g' | sed -e 's/\ target.*//g' | sed -e 's/"//g' > ./temp/url.txt
url=`head -$2 ./temp/url.txt | tail -1`
wget -O ./temp/url.html "$url"
realurl=`grep "margin-right" ./temp/url.html |\
sed -e 's/<li class=\"li\" style=\"margin-right:10px;\"><a href=\"//g' |\
sed -e 's/\ target.*//g' | sed -e 's/"//g'`
#wget -O $1.mp3 -c -t 3 $realurl
axel -o $1.mp3 -a "${realurl}"
exit 0
fi
代码: 全选
./downsong.sh 至少还有你 1
./downsong.sh yesterday_once_more 1
-
- 帖子: 21
- 注册时间: 2007-09-18 7:55
我已经写了个改良版的 viewtopic.php?p=545811#545811