扔个抓百度音乐API的js。有想用的拿走。。
发布于 13 年前 作者 xiaojue 11292 次预览 最后一次回复是 11 年前 来自
https://gist.github.com/3938110
api写好了。。不过貌似这个接口必须写准作者和歌曲标题。。大家有更好的音乐api吗。。?求推荐,要有带试听的。。
4 回复
https://gist.github.com/3938110
api写好了。。不过貌似这个接口必须写准作者和歌曲标题。。大家有更好的音乐api吗。。?求推荐,要有带试听的。。
貌似没法用
以前年轻不懂事抓过百度掌门人的接口,不过当时是用C#写的,现在也懒得回去弄了:
https://zmenfm.codeplex.com/SourceControl/latest#ZMenFM.Network/ZMConstUrl.cs
修改了下 可以用了
var xml2js = require(‘xml2js’), http = require(‘http’);
var baiduZm = function() { this.root = ‘box.zhangmen.baidu.com’; };
baiduZm.prototype = { constructor: baiduZm, get: function (uri, callback) { var req = http.request({ host: this.root, port: 80, path: uri, method: ‘GET’ }, function(res) { var ret = ‘’; res.setEncoding(‘utf8’); res.on(‘data’, function (chunk) { ret += chunk; }); res.on(‘end’, function () { callback(null, ret); }); });
req.on(‘error’, function (err) { callback(err); });
req.end(); }, getUri: function(param) { return ‘/x?op=12&count=1&title=’ + encodeURIComponent(param.title) + ‘$$’ + encodeURIComponent(param.author) + ‘$$$$’; }, searchTrack: function(param, callback) { var uri = this.getUri(param); this.get(uri, function(err, xml) { if (err) callback(err); else {
} }); } };
(new baiduZm()).searchTrack({ author: ‘温岚’, title: ‘屋顶’ }, function (err, data){ if (err) { throw err; } else { if (data.ret) { console.log(data); } else { console.log(“没有找到这首歌”); } } });
赞