利用百度音乐的API播放音乐的bash脚本

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

#!/bin/bash
#脚本作用,调用mplayer播放百度音乐,需要预装mplayer

#定义各种变量
title=${1:-'大约在冬季'} #歌曲名
performer=${2:-'齐秦'}   #歌手名

getmp3url(){
    url='http://box.zhangmen.baidu.com/x?op=12&count=1&title='$title'$$'$performer'$$$$'
    xml=`curl -s ''$url''`
    count=`echo $xml | xmllint --xpath '/result/count/text()' - `
    if [ "$count" -eq 0 ]
    then
        exit 1
    fi
    encode=`echo $xml | xmllint --xpath '/result/url[1]/encode[1]/text()' - | sed -r 's/<\!\[CDATA\[(.+)\]\]>/\1/g'`
    decode=`echo $xml | xmllint --xpath '/result/url[1]/decode[1]/text()' - | sed -r 's/<\!\[CDATA\[(.+)\]\]>/\1/g'`
    echo `dirname $encode`/$decode
}
url=`getmp3url` && mplayer $url || echo "检索结果不存在,请选用别的歌曲名和歌手检索!" && exit 1

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

系ubuntu 下面打开终端输入:sudo apt-get install sendmail...
依家我有1个软件goagent目录(大家懂得) 放在/home/gateman/...
其实我想讲的是 cp -L关于-L参数的解释:-L, --dereferenc...
原地址:http://www.rjgc.net/control/content/content.php?...
chroot,即 change root directory (更改 root 目录)。在 li...
简单解析下, stdin就是标准输入, stdout就是标准。举个例子...