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

'update'

上级 0c6f105e
......@@ -35,8 +35,9 @@ api.search('年度之歌',data => {
### search
``` javascript
api.search(name:String,[callback:function,limit:Number default:3, offset:Number default:0])
api.search(name:String,[callback:function,onlySong:Boolean default:true,limit:Number default:3, offset:Number default:0])
```
说明:onlySong默认为true,如果为false,则返回一个对象,包含songs和mvs,songs和mvs均为数组
### lrc
``` javascript
......
......@@ -24,6 +24,5 @@ var api = {
getArtistAlbums: _getArtistAlbums.getArtistAlbums,
getAlbums: _getAlbums.getAlbums,
getPlaylists: _getPlaylists.getPlaylists
};
exports.api = api;
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getAlbums = undefined;
var _request = require('request');
var _request2 = _interopRequireDefault(_request);
var _config = require('../config');
var _util = require('../util');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var getPlaylists = function getPlaylists(id, callback) {
var option = (0, _util.deepCopy)(_config.globalOption);
var url = _config.origin + '/api/playlist/detail?id=' + id;
var method = 'get';
Object.assign(option, { url: url, method: method });
(0, _request2.default)(option, function (err, res, body) {
if (!err && res.statusCode == 200) {
var info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2));
} else {
console.error(err);
}
});
};
exports.getPlaylists = getPlaylists;
......@@ -18,8 +18,9 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
var search = function search() {
var name = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
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 onlySong = arguments.length <= 2 || arguments[2] === undefined ? true : arguments[2];
var limit = arguments.length <= 3 || arguments[3] === undefined ? 3 : arguments[3];
var offset = arguments.length <= 4 || arguments[4] === undefined ? 0 : arguments[4];
var option = (0, _util.deepCopy)(_config.globalOption);
var url = _config.origin + '/api/search/suggest/web';
......@@ -34,7 +35,13 @@ var search = function search() {
(0, _request2.default)(option, function (err, res, body) {
if (!err && res.statusCode == 200) {
var info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2));
var data = void 0;
if (onlySong) {
data = info.result.songs;
} else {
data = { songs: info.result.songs, mvs: info.result.mvs };
}
callback && callback(JSON.stringify(data, '', 2));
} else {
console.error(err);
}
......
{
"name": "NeteaseCloudMusicApi",
"version": "1.2.9",
"version": "1.5.0",
"description": "网易云音乐nodejs版接口模块",
"main": "build/app.js",
"scripts": {
......
......@@ -12,6 +12,5 @@ let api = {
getArtistAlbums: getArtistAlbums,
getAlbums: getAlbums,
getPlaylists: getPlaylists
}
export {api}
......@@ -12,7 +12,7 @@ const getAlbums = (id, callback) => {
let info = JSON.parse(body)
callback && callback(JSON.stringify(info, '', 2))
} else {
console.error(err);
console.error(err)
}
})
}
......
......@@ -12,7 +12,7 @@ const getArtistAlbums = (id, callback, limit = 3, offset = 0) => {
let info = JSON.parse(body)
callback && callback(JSON.stringify(info, '', 2))
} else {
console.error(err);
console.error(err)
}
})
}
......
......@@ -5,14 +5,14 @@ import { deepCopy } from '../util'
const getPlaylists = (id, callback) => {
const option = deepCopy(globalOption)
const url = `${origin}/api/playlist/detail?id=${id}`
const method = 'GET'
const method = 'get'
Object.assign(option, {url, method})
request(option, (err, res, body) => {
if(!err && res.statusCode == 200) {
let info = JSON.parse(body)
callback && callback(JSON.stringify(info, '', 2))
} else {
console.error(err);
console.error(err)
}
})
}
......
......@@ -2,7 +2,7 @@ import request from 'request'
import { origin, globalOption } from '../config'
import { deepCopy } from '../util'
const search = (name = null, callback = null, limit = 3, offset = 0) => {
const search = (name = null, callback = null,onlySong=true, limit = 3, offset = 0) => {
const option = deepCopy(globalOption)
const url = `${origin}/api/search/suggest/web`
const form = {
......@@ -15,8 +15,14 @@ const search = (name = null, callback = null, limit = 3, offset = 0) => {
Object.assign(option, { url, form, method })
request(option, (err, res, body) => {
if (!err && res.statusCode == 200) {
let info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2))
let info = JSON.parse(body)
let data
if(onlySong){
data=info.result.songs
}else{
data={songs:info.result.songs,mvs:info.result.mvs}
}
callback&&callback(JSON.stringify(data,'',2))
} else {
console.error(err)
}
......
// import { api } from '../src/app.js'
const api=require('../build/app.js').api
const {api}=require('../build/app.js')
api.search("年度之歌",data => {
console.log("################Search API#################")
console.log(data)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册