Chinaunix首页 | 论坛 | 博客
  • 博客访问: 116151
  • 博文数量: 32
  • 博客积分: 2067
  • 博客等级: 大尉
  • 技术积分: 383
  • 用 户 组: 普通用户
  • 注册时间: 2009-05-08 07:47
文章分类

全部博文(32)

文章存档

2011年(1)

2010年(14)

2009年(17)

我的朋友

分类: LINUX

2009-12-13 21:42:10

下载songtaste的音乐比较麻烦,以前用mozilla-mplayer听歌,可以直接用右键获取音乐地址
现在debian sid的源里没有mozilla-mplayer,只有一个gmplayer的插件,质量很差,听到一半常常断掉
换xine的插件稍微好些,但没法获取下载地址了,所以只好写个脚本专门来下载收听
我水平太次,脚本丑陋不堪,而且不是100%的歌都能正常收听下载,辉耀出品必属废品,谅解..

先要装:
links,也可以用其他的lynx,w3m之类,感觉links稍微快些(也许是错觉)
wget,rayfile只能单线程下载,自然首选wget,好在速度不慢
iconv,转换编码,我用xterm编码UTF-8,系统的locale也是en_US.UTF-8,而songtaste的页面源代码是gb2312
mplayer,听音乐用


########################################################
#!/bin/bash
#get music from
if [ $# != 2 ]
  then
    echo   "Usage:   stmusic.sh   URL  l"
    echo   "         stmusic.sh   URL  d"
    exit
    else
      URL=$1
fi
TOP=/home/stesen/music
NUM=`echo ${URL}|sed -e "s/http:\/\/songtaste.com\/song\///g" -e "s/\///g"`
links -source "}" |grep "preview" > ${TOP}/.stmusic.tmp
#ip 60.10.96.74 即songtaste.com,用ip可以减少dns解析时间
#但是今天它换ip了,估计是服务器出问题,变成115.100.249.248
#所以,换回还是直接用ip自己斟酌吧

if [ $2 = d ]
        then
NAME=`iconv -f gb2312 -t utf-8 ${TOP}/.stmusic.tmp|cut -d"\""  -f4|sed -e 's/\ /-/g' -e 's/\./-/g' -e 's/(//g' -e 's/)//g' -e 's/…//g' -e 's/\ //g' `
TP=`iconv -f gb2312 -t utf-8 ${TOP}/.stmusic.tmp|cut -d"\""  -f12 |cut -d"." -f5`
FULLNAME=`echo ${NAME}.${TP}|sed -e "s/-././g"`
wget -c `iconv -f gb2312 -t utf-8 ${TOP}/.stmusic.tmp|cut -d"\""  -f12` -O ${TOP}/${FULLNAME}
elif [ $2 = l ]
then
        mplayer `iconv -f gb2312 -t utf-8 ${TOP}/.stmusic.tmp|cut -d"\"" -f12`
fi
rm ${TOP}/.stmusic.tmp
exit
#######################################################
 

用法:
./stmusic.sh url l #listen
./stmusic.sh url d #download
 
url即类似这样的页面

由于songtaste重写了网页,将链接拆散了,所以这个脚本没用了,正在学习perl,等几天试试用perl写

阅读(858) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~