提交 774de65c 编写于 作者: zhuangtongfa's avatar zhuangtongfa

update

上级 51bb4023
......@@ -19,17 +19,17 @@ api.search('年度之歌')
# api
## search
```js
api.search(name:String, [limit:Nnumber default:3, offset:Number default:0])
api.search(name:String, [callback:function,limit:Nnumber default:3, offset:Number default:0])
```
## lrc
```js
api.lrc(id:Number, [lv:Number default:-1])
api.lrc(id:Number, [callback:function,lv:Number default:-1])
```
## song
```js
api.song(id:Number)
api.song(id:Number,[callback:function])
```
[github](https://github.com/Binaryify/NeteaseCloudMusicApi)
......
......@@ -13,34 +13,42 @@ let globalOption = {
}
let api = {
search: (name = null, limit = 3, offset = 0) => {
search: (name = null,callback=null, limit = 3, offset = 0) => {
let option = deepCopy(globalOption);
let url = origin + '/api/search/suggest/web'
let body = 's=' + name + '&limit=' + limit + '&type=1&offset=' + offset
let method = 'POST'
Object.assign(option, { url, body, method })
request(option, callback);
request(option, (error, response, body)=>{
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
callback&&callback(JSON.stringify(info, '', 2))
}
})
},
song: (id) => {
song: (id,callback=null) => {
let option = deepCopy(globalOption);
let url = origin + '/api/song/detail?ids=%5B' + id + '%5d'
let method = 'GET'
Object.assign(option, { url, method })
request(option, callback);
request(option, (error, response, body)=>{
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
callback&&callback(JSON.stringify(info, '', 2))
}
})
},
lrc: (id, lv = -1) => {
lrc: (id,callback=null, lv = -1) => {
let option = deepCopy(globalOption);
let url = origin + '/api/song/lyric?lv=' + lv + '&id=' + id
let method = 'GET'
Object.assign(option, { url, method })
request(option, callback);
}
}
function callback(error, response, body) {
// console.log('callback')
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
console.log(JSON.stringify(info, '', 2))
request(option, (error, response, body)=>{
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
callback&&callback(JSON.stringify(info, '', 2))
}
})
}
}
export {api}
\ No newline at end of file
......@@ -27,38 +27,50 @@ var globalOption = {
var api = {
search: function search() {
var name = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
var limit = arguments.length <= 1 || arguments[1] === undefined ? 3 : arguments[1];
var offset = arguments.length <= 2 || arguments[2] === undefined ? 0 : arguments[2];
var callback = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var limit = arguments.length <= 2 || arguments[2] === undefined ? 3 : arguments[2];
var offset = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3];
var option = deepCopy(globalOption);
var url = origin + '/api/search/suggest/web';
var body = 's=' + name + '&limit=' + limit + '&type=1&offset=' + offset;
var method = 'POST';
Object.assign(option, { url: url, body: body, method: method });
(0, _request2.default)(option, callback);
(0, _request2.default)(option, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2));
}
});
},
song: function song(id) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var option = deepCopy(globalOption);
var url = origin + '/api/song/detail?ids=%5B' + id + '%5d';
var method = 'GET';
Object.assign(option, { url: url, method: method });
(0, _request2.default)(option, callback);
(0, _request2.default)(option, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2));
}
});
},
lrc: function lrc(id) {
var lv = arguments.length <= 1 || arguments[1] === undefined ? -1 : arguments[1];
var callback = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var lv = arguments.length <= 2 || arguments[2] === undefined ? -1 : arguments[2];
var option = deepCopy(globalOption);
var url = origin + '/api/song/lyric?lv=' + lv + '&id=' + id;
var method = 'GET';
Object.assign(option, { url: url, method: method });
(0, _request2.default)(option, callback);
(0, _request2.default)(option, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2));
}
});
}
};
function callback(error, response, body) {
// console.log('callback')
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
console.log(JSON.stringify(info, '', 2));
}
}
exports.api = api;
{
"name": "NeteaseCloudMusicApi",
"version": "1.0.1",
"description": "",
"version": "1.0.8",
"description": "网易云音乐nodejs版接口模块",
"main": "build/app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel app.js -o build/app.js",
"check": "node build/test.js"
},
"keywords": [],
"keywords": ["NeteaseCloudMusic","网易云音乐"],
"author": "traveller",
"license": "ISC",
"dependencies": {
......
import {api }from './app.js'
api.search("远方")
api.song('5243023')
api.lrc('5243023')
\ No newline at end of file
api.search("年度之歌",(data)=>{
console.log(data)
})
api.song('308169',(data)=>{
console.log(data)
})
api.lrc('5243023',(data)=>{
console.log(data)
})
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册