linux 下载音乐脚本(正式版)
-
- 帖子: 21
- 注册时间: 2007-09-18 7:55
linux 下载音乐脚本(正式版)
已经对以前的那个测试版进行了很大的改进 不过只能搜索中文音乐 如果搜出来的歌曲有英文和其它符号也下载不了 我会再写一个更加完善的脚本 希望你们提出报贵的意见
代码如下:
#!bin/sh
#头部(选择下载软件和输入歌曲)
e=`which axel`
e_1=`which mid3v2`
if [ -x $e ];then
echo "检测到你已经安装了axel 将会成为你默认的下载工具"
else
echo "你还没有安装axel 多线程下载工具,将会自动选择单线程工具wget下载。如果你的系统是ubuntu你可以执行:sudo apt-get install axel 下载并安装axel."
fi
if [ -x $e_1 ];then
echo "检测到mid3v2会把你音乐的tag都删除掉,预防出现乱码"
else
echo "你还没有安装mid3v2,这个工具 可以去掉音乐里面的tag(乱码的根源),如果你的系统是ubuntu你可以执行:sudo apt-get install python-mutagen下载并安装."
fi
#核心部分(提取连接 和把中文转换成url编码)
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 5 "M</td>"|awk -F">" '{print $2}'|awk -F"<" '{print $1} ' >size #找到文件的大小
iconv -f gb2312 -t utf8 file |grep -m 5 "<td class=d><a href="|awk -F"," '{print $2}'|awk -F"&" '{print $1}'>>size # (连接里的中文
awk '{a[NR]=$0}END{for(i=1;i<=NR/2;i++)printf "(%d)\t%s\t%s\n",i,a,a[i+NR/2]}' size
read -p "请选择你要下载第几首:" c #选择你要下载的歌曲的大小
iconv -f gb2312 -t utf8 file |grep -m $c "<td class=d><a href=" >song
sed -n ''$m'p' song|awk -F"," '{print $2}'|awk -F"&" '{print $1}' >song_1
iconv -f utf8 -t gb2312 song_1 >down.file3
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 #得到你想要的最快的音乐连接
#下载部分
h=`cat down.file4`
if [ -x $e ];then
axel -n 10 -o $a.mp3 $h #在这里你可以改变你的下载路径 比如axel -n 10 -o ~/muic/ $h 就是把音乐下载到music文件里
else
wget -t 5 -c -i down.file4 -O "$a".mp3 #下载音乐
fi
if [ -x $e_1 ];then
mid3v2 -D "$a".mp3
fi
rm down.file down.file1 down.file3 file file_1 down.file4 song song_1
————————————————————————————————————————————————————
不好意思 我是硬着头皮写出来的东西 我现在正在努力学习中 下个版本将会解决中英文混输和不能下载英文歌曲这个问题 解决这两个问题意味着可以%99下载你想要的音乐(还有%1就是网络和你的电脑问题和 呵呵)希望你们能给点指导我 谢谢!
----------------------------------------------------
示例:
benqlk@benqlk-laptop:~/Documents$ sh down.sh
检测到你已经安装了axel 将会成为你默认的下载工具
检测到mid3v2会把你音乐的tag都删除掉,预防出现乱码
请输入你要搜索的音乐:爱
(1) 3.1 M 明月来看我
(2) 1.1 M 爱
(3) 2.5 M 心中喜欢就说爱 爱你爱到老
(4) 3.1 M 夜 宝玉 探 mp3
(5) 1.6 M 爱 国语合唱版 阿Sa/
请选择你要下载第几首:
代码如下:
#!bin/sh
#头部(选择下载软件和输入歌曲)
e=`which axel`
e_1=`which mid3v2`
if [ -x $e ];then
echo "检测到你已经安装了axel 将会成为你默认的下载工具"
else
echo "你还没有安装axel 多线程下载工具,将会自动选择单线程工具wget下载。如果你的系统是ubuntu你可以执行:sudo apt-get install axel 下载并安装axel."
fi
if [ -x $e_1 ];then
echo "检测到mid3v2会把你音乐的tag都删除掉,预防出现乱码"
else
echo "你还没有安装mid3v2,这个工具 可以去掉音乐里面的tag(乱码的根源),如果你的系统是ubuntu你可以执行:sudo apt-get install python-mutagen下载并安装."
fi
#核心部分(提取连接 和把中文转换成url编码)
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 5 "M</td>"|awk -F">" '{print $2}'|awk -F"<" '{print $1} ' >size #找到文件的大小
iconv -f gb2312 -t utf8 file |grep -m 5 "<td class=d><a href="|awk -F"," '{print $2}'|awk -F"&" '{print $1}'>>size # (连接里的中文
awk '{a[NR]=$0}END{for(i=1;i<=NR/2;i++)printf "(%d)\t%s\t%s\n",i,a,a[i+NR/2]}' size
read -p "请选择你要下载第几首:" c #选择你要下载的歌曲的大小
iconv -f gb2312 -t utf8 file |grep -m $c "<td class=d><a href=" >song
sed -n ''$m'p' song|awk -F"," '{print $2}'|awk -F"&" '{print $1}' >song_1
iconv -f utf8 -t gb2312 song_1 >down.file3
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 #得到你想要的最快的音乐连接
#下载部分
h=`cat down.file4`
if [ -x $e ];then
axel -n 10 -o $a.mp3 $h #在这里你可以改变你的下载路径 比如axel -n 10 -o ~/muic/ $h 就是把音乐下载到music文件里
else
wget -t 5 -c -i down.file4 -O "$a".mp3 #下载音乐
fi
if [ -x $e_1 ];then
mid3v2 -D "$a".mp3
fi
rm down.file down.file1 down.file3 file file_1 down.file4 song song_1
————————————————————————————————————————————————————
不好意思 我是硬着头皮写出来的东西 我现在正在努力学习中 下个版本将会解决中英文混输和不能下载英文歌曲这个问题 解决这两个问题意味着可以%99下载你想要的音乐(还有%1就是网络和你的电脑问题和 呵呵)希望你们能给点指导我 谢谢!
----------------------------------------------------
示例:
benqlk@benqlk-laptop:~/Documents$ sh down.sh
检测到你已经安装了axel 将会成为你默认的下载工具
检测到mid3v2会把你音乐的tag都删除掉,预防出现乱码
请输入你要搜索的音乐:爱
(1) 3.1 M 明月来看我
(2) 1.1 M 爱
(3) 2.5 M 心中喜欢就说爱 爱你爱到老
(4) 3.1 M 夜 宝玉 探 mp3
(5) 1.6 M 爱 国语合唱版 阿Sa/
请选择你要下载第几首:
上次由 benqlk 在 2007-12-03 11:48,总共编辑 1 次。
- 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
- arsui
- 帖子: 889
- 注册时间: 2007-05-06 2:01
- 来自: 特麓村->浦北->五山->罗湖
代码: 全选
sudo sh gmusic
检测到你已经安装了axel 将会成为你默认的下载工具
检测到mid3v2会把你音乐的tag都删除掉,预防出现乱码
请输入你要搜索的音乐:我们的故事
--22:09:47-- http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%ce%d2%c3%c7%b5%c4%b9%ca%ca%c2%0a&lm=-1
=> `file'
Resolving mp3.baidu.com... 220.181.38.70
Connecting to mp3.baidu.com|220.181.38.70|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [text/html]
[ <=> ] 73,806 48.54K/s
22:09:53 (48.37 KB/s) - `file' saved [73806]
(1) 2.3 M 香水有毒
(2) 5.6 M 我们的故事 SMART
(3) 4.4 M 香水有毒
(4) 5.6 M 我们的故事 Our Story
(5) 4.4 M 香水有毒
请选择你要下载第几首:2
awk: line 1: runaway string constant "%cf%e3%cb% ...
: Unsupported scheme.
gmusic: 59: axel: not found
deleting ID3 tag info in 我们的故事.mp3
Traceback (most recent call last):
File "/usr/bin/mid3v2", line 219, in <module>
main(sys.argv)
File "/usr/bin/mid3v2", line 209, in main
delete_tags(args, "v1" in options.action, "v2" in options.action)
File "/usr/bin/mid3v2", line 62, in delete_tags
mutagen.id3.delete(filename, v1, v2)
File "/usr/lib/python2.5/site-packages/mutagen/id3.py", line 473, in delete
f = open(filename, 'rb+')
IOError: [Errno 2] No such file or directory: '\xe6\x88\x91\xe4\xbb\xac\xe7\x9a\x84\xe6\x95\x85\xe4\xba\x8b.mp3'
arsui@arsui-linux:~$
原来是因为没装axel~~ 可是提示装了
好用
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
- arsui
- 帖子: 889
- 注册时间: 2007-05-06 2:01
- 来自: 特麓村->浦北->五山->罗湖
代码: 全选
[ 0%] .......... .......... .......... .......... .......... [ 5.6KB/s]
[ 1%] .......... .......... .......... .......... .......... [ 10.5KB/s]
[ 3%] .......... .......... .......... .......... .......... [ 14.9KB/s]
[ 4%] .......... .......... .......... .......... .......... [ 18.8KB/s]
[ 6%] .......... .......... .......... .......... .......... [ 22.5KB/s]
[ 8%] .......... .......... .......... .......... .......... [ 25.8KB/s]
[ 9%] ......
Connection 0 finished
,,,,,,.... .......... .......... .......... .......... [ 24.4KB/s]
[ 11%] .......... .......... .......... .......... .......... [ 26.9KB/s]
[ 13%] .......... .......... .......... .......... .......... [ 29.3KB/s]
[ 14%] .......... .......... .......... .......... .......... [ 31.6KB/s]
[ 16%] .......... .......... .......... .......... .......... [ 33.8KB/s]
[ 17%] .......... .......... .......... .......... .......... [ 35.9KB/s]
[ 19%] .......... ...
Connection 1 finished
,,,,,,,,,, ,,,....... .......... .......... .......... [ 33.7KB/s]
[ 21%] .......... .......... .......... .......... .......... [ 35.1KB/s]
[ 22%] .......... .......... .......... .......... .......... [ 36.8KB/s]
[ 24%] .......... .......... .......... .......... .......... [ 38.3KB/s]
[ 26%] .......... .......... .......... .......... .......... [ 39.7KB/s]
[ 27%] .......... .......... .......... .......... .......... [ 41.0KB/s]
[ 29%] .......... ..........
Connection 2 finished
,,,,,,,,,, ,,,,,,,,,,
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
- yangyang123
- 帖子: 61
- 注册时间: 2007-10-26 9:37
-
- 帖子: 21
- 注册时间: 2007-09-18 7:55
- chinafeiyang
- 帖子: 98
- 注册时间: 2007-04-19 19:05
- 来自: 温州,杭州
- 联系:
Re: linux 下载音乐脚本(正式版)
已经对以前的那个测试版进行了很大的改进 不过只能搜索中文音乐 如果搜出来的歌曲有英文和其它符号也下载不了 我会再写一个更加完善的脚本 希望你们提出报贵的意见
代码如下:
#!bin/sh
#头部(选择下载软件和输入歌曲)
e=`which axel`
e_1=`which mid3v2`
if [ -x $e ];then
搂住开头最好改成
#!/bin/bash
我看LZ也粗心的#!bin/sh,如果新手复制过去,可能脚本运行不了!
代码如下:
#!bin/sh
#头部(选择下载软件和输入歌曲)
e=`which axel`
e_1=`which mid3v2`
if [ -x $e ];then
搂住开头最好改成
#!/bin/bash
我看LZ也粗心的#!bin/sh,如果新手复制过去,可能脚本运行不了!
- aitilang
- 帖子: 1026
- 注册时间: 2007-04-28 21:38
-
- 帖子: 441
- 注册时间: 2006-10-26 7:02
-
- 帖子: 6
- 注册时间: 2009-02-02 9:47
Re: linux 下载音乐脚本(正式版)
iconv -f gb2312 -t utf8 file |grep -m 5 "M</td>"|awk -F">" '{print $2}'|awk -F"<" '{print $1} ' >size #找到文件的大小
iconv -f gb2312 -t utf8 file |grep -m 5 "<td class=d><a href="|awk -F"," '{print $2}'|awk -F"&" '{print $1}'>>size # (连接里的中文
我不知道是哪里出了问题,上面这两句是执行不了的,尤其是iconv执行的时候 -f指定的编码在这里好像都有问题,即使是使用enconv -g file 得出是gb2312,也是没有办法执行iconv,我的是中文环境,这个应该没有关系吧,下面是我的几个相关操作:
bash down.sh
leo@leo-laptop:/opt/app_shell$ bash down.sh
检测到你已经安装了axel 将会成为你默认的下载工具
检测到mid3v2会把你音乐的tag都删除掉,预防出现乱码
请输入你要搜索的音乐:爱
--2009-09-26 08:57:41-- http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%b0%ae%0a&lm=-1
正在解析主机 mp3.baidu.com... 220.181.43.121
正在连接 mp3.baidu.com|220.181.43.121|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 未指定 [text/html]
保存到‘file’
[ <=> ] 80,817 11.6K/s in 6.8s
2009-09-26 08:57:48 (11.6 KB/s) - `file' 被保存 [80817]
(1) 4.2 M http://219.159.196.124:8080/xuekehome/shuxue/zongming01/naGpmTU$.mp3
(2) 4.2 M HTTP://baobao.qq.com/data/k5OilpallmljZmRpbmdqbpConJiapZZqYWJrZG1naGhoZ2RoaTY$.mp3
(3) 4.2 M http://www.htgq.gov.cn/jfz/upload_file/Y2Jja21pZ3BmY2VqNQ$$.mp3
(4) 4.2 M http://www.lzlhll.cn/music/ZWcz.mp3
(5) 1.6 M http://www.cp007.com/yule/uploadfiles_2006/200601/Y2JjamVnaWpiaGNpZ2xsamEy.wma
请选择你要下载第几首:2
awk: line 1: runaway string constant "%68%74%74% ...
http://: 非法主机名称.
Usage: axel [options] url1 [url2] [url...]
--max-speed=x -s x Specify maximum speed (bytes per second)
--num-connections=x -n x Specify maximum number of connections
--output=f -o f Specify local output file
--search[=x] -S [x] Search for mirrors and download from x servers
--header=x -H x Add header string
--user-agent=x -U x Set user agent
--no-proxy -N Just don't use any proxy server
--quiet -q Leave stdout alone
--verbose -v More status information
--alternate -a Alternate progress indicator
--help -h This information
--version -V Version information
Report bugs to submit@bugs.debian.org (using reportbug)
deleting ID3 tag info in 爱.mp3
Traceback (most recent call last):
File "/usr/bin/mid3v2", line 219, in <module>
main(sys.argv)
File "/usr/bin/mid3v2", line 209, in main
delete_tags(args, "v1" in options.action, "v2" in options.action)
File "/usr/bin/mid3v2", line 62, in delete_tags
mutagen.id3.delete(filename, v1, v2)
File "/usr/lib/python2.6/dist-packages/mutagen/id3.py", line 496, in delete
f = open(filename, 'rb+')
IOError: [Errno 2] No such file or directory: '\xe7\x88\xb1.mp3'
iconv -f gb2312 -t utf8 file |grep -m 5 "<td class=d><a href="|awk -F"," '{print $2}'|awk -F"&" '{print $1}'>>size # (连接里的中文
我不知道是哪里出了问题,上面这两句是执行不了的,尤其是iconv执行的时候 -f指定的编码在这里好像都有问题,即使是使用enconv -g file 得出是gb2312,也是没有办法执行iconv,我的是中文环境,这个应该没有关系吧,下面是我的几个相关操作:
bash down.sh
leo@leo-laptop:/opt/app_shell$ bash down.sh
检测到你已经安装了axel 将会成为你默认的下载工具
检测到mid3v2会把你音乐的tag都删除掉,预防出现乱码
请输入你要搜索的音乐:爱
--2009-09-26 08:57:41-- http://mp3.baidu.com/m?f=ms&tn=baidump3&ct=134217728&lf=&rn=&word=%b0%ae%0a&lm=-1
正在解析主机 mp3.baidu.com... 220.181.43.121
正在连接 mp3.baidu.com|220.181.43.121|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度: 未指定 [text/html]
保存到‘file’
[ <=> ] 80,817 11.6K/s in 6.8s
2009-09-26 08:57:48 (11.6 KB/s) - `file' 被保存 [80817]
(1) 4.2 M http://219.159.196.124:8080/xuekehome/shuxue/zongming01/naGpmTU$.mp3
(2) 4.2 M HTTP://baobao.qq.com/data/k5OilpallmljZmRpbmdqbpConJiapZZqYWJrZG1naGhoZ2RoaTY$.mp3
(3) 4.2 M http://www.htgq.gov.cn/jfz/upload_file/Y2Jja21pZ3BmY2VqNQ$$.mp3
(4) 4.2 M http://www.lzlhll.cn/music/ZWcz.mp3
(5) 1.6 M http://www.cp007.com/yule/uploadfiles_2006/200601/Y2JjamVnaWpiaGNpZ2xsamEy.wma
请选择你要下载第几首:2
awk: line 1: runaway string constant "%68%74%74% ...
http://: 非法主机名称.
Usage: axel [options] url1 [url2] [url...]
--max-speed=x -s x Specify maximum speed (bytes per second)
--num-connections=x -n x Specify maximum number of connections
--output=f -o f Specify local output file
--search[=x] -S [x] Search for mirrors and download from x servers
--header=x -H x Add header string
--user-agent=x -U x Set user agent
--no-proxy -N Just don't use any proxy server
--quiet -q Leave stdout alone
--verbose -v More status information
--alternate -a Alternate progress indicator
--help -h This information
--version -V Version information
Report bugs to submit@bugs.debian.org (using reportbug)
deleting ID3 tag info in 爱.mp3
Traceback (most recent call last):
File "/usr/bin/mid3v2", line 219, in <module>
main(sys.argv)
File "/usr/bin/mid3v2", line 209, in main
delete_tags(args, "v1" in options.action, "v2" in options.action)
File "/usr/bin/mid3v2", line 62, in delete_tags
mutagen.id3.delete(filename, v1, v2)
File "/usr/lib/python2.6/dist-packages/mutagen/id3.py", line 496, in delete
f = open(filename, 'rb+')
IOError: [Errno 2] No such file or directory: '\xe7\x88\xb1.mp3'