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

update

上级 8270c731
# NeteaseCloudMusicApi
<a href="https://www.npmjs.com/package/NeteaseCloudMusicApi"><img src="https://img.shields.io/npm/v/NeteaseCloudMusicApi.svg" alt="Version"></a>
一个调用网易云音乐 API 的 node 模块
![](http://binaryify.github.io/images/api.jpg)
......
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
exports.api = undefined;
......@@ -16,57 +16,63 @@ var _util = require('./util');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var api = {
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];
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 option = (0, _util.deepCopy)(_config.globalOption);
var url = _config.origin + '/api/search/suggest/web';
var form = {
s: name,
limit: limit,
type: 1,
offset: offset
};
var method = 'POST';
Object.assign(option, { url: url, form: form, method: method });
(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 = (0, _util.deepCopy)(_config.globalOption);
var url = _config.origin + '/api/search/suggest/web';
var form = {
s: name,
limit: limit,
type: 1,
offset: offset
};
var method = 'POST';
Object.assign(option, { url: url, form: form, method: method });
(0, _request2.default)(option, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2));
} else {
console.log(error);
}
});
},
song: function song(id) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var option = (0, _util.deepCopy)(_config.globalOption);
var url = _config.origin + '/api/song/detail?ids=%5B' + id + '%5d';
var method = 'GET';
Object.assign(option, { url: url, method: method });
(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 callback = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var lv = arguments.length <= 2 || arguments[2] === undefined ? -1 : arguments[2];
var option = (0, _util.deepCopy)(_config.globalOption);
var url = _config.origin + '/api/song/detail?ids=%5B' + id + '%5d';
var method = 'GET';
Object.assign(option, { url: url, method: method });
(0, _request2.default)(option, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2));
} else {
console.log(error);
}
});
},
lrc: function lrc(id) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var lv = arguments.length <= 2 || arguments[2] === undefined ? -1 : arguments[2];
var option = (0, _util.deepCopy)(_config.globalOption);
var url = _config.origin + '/api/song/lyric?lv=' + lv + '&id=' + id;
var method = 'GET';
Object.assign(option, { url: url, method: method });
(0, _request2.default)(option, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2));
}
});
}
var option = (0, _util.deepCopy)(_config.globalOption);
var url = _config.origin + '/api/song/lyric?lv=' + lv + '&id=' + id;
var method = 'GET';
Object.assign(option, { url: url, method: method });
(0, _request2.default)(option, function (error, response, body) {
if (!error && response.statusCode == 200) {
var info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2));
} else {
console.log(error);
}
});
}
};
exports.api = api;
exports.api = api;
\ No newline at end of file
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
value: true
});
var origin = 'http://music.163.com';
var globalOption = {
headers: {
'Origin': origin,
'Referer': origin,
'Content-Type': 'application/x-www-form-urlencoded'
}
headers: {
'Origin': origin,
'Referer': origin,
'Content-Type': 'application/x-www-form-urlencoded'
},
proxy: false
};
exports.origin = origin;
......
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'test' ]
2 info using npm@3.9.5
3 info using node@v6.2.2
4 verbose run-script [ 'pretest', 'test', 'posttest' ]
5 info lifecycle NeteaseCloudMusicApi@1.2.2~pretest: NeteaseCloudMusicApi@1.2.2
6 silly lifecycle NeteaseCloudMusicApi@1.2.2~pretest: no script for pretest, continuing
7 info lifecycle NeteaseCloudMusicApi@1.2.2~test: NeteaseCloudMusicApi@1.2.2
8 verbose lifecycle NeteaseCloudMusicApi@1.2.2~test: unsafe-perm in lifecycle true
9 verbose lifecycle NeteaseCloudMusicApi@1.2.2~test: PATH: C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin;C:\Users\ztf\Desktop\NeteaseCloudMusicApi\node_modules\.bin;C:\Program Files\nodejs;C:\Users\ztf\bin;C:\Program Files (x86)\Git\mingw32\bin;C:\Program Files (x86)\Git\usr\local\bin;C:\Program Files (x86)\Git\usr\bin;C:\Program Files (x86)\Git\usr\bin;C:\Program Files (x86)\Git\mingw32\bin;C:\Program Files (x86)\Git\usr\bin;C:\Users\ztf\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Users\ztf\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm;C:\Program Files\Microsoft SQL Server\130\Tools\Binn;C:\Program Files\Java\jdk1.8.0_92\bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\OpenVPN\bin;C:\Program Files\nodejs;C:\Program Files (x86)\Tesseract-OCR;C:\Users\ztf\AppData\Local\Microsoft\WindowsApps;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Users\ztf\AppData\Local\atom\bin;C:\ProgramData\chocolatey\bin;C:\Users\ztf\AppData\Local\Android\sdk\tools;C:\Users\ztf\AppData\Local\Android\sdk\platform-tools;C:\Users\ztf\AppData\Local\Microsoft\WindowsApps;C:\Python34;C:\Python34\Scripts;C:\Program Files (x86)\Git\cmd;D:\software\aria2\aria2c.exe;C:\Program Files (x86)\Git;C:\Users\ztf\AppData\Roaming\npm;C:\Program Files (x86)\WinRAR;C:\Program Files (x86)\Git\usr\bin\vendor_perl;C:\Program Files (x86)\Git\usr\bin\core_perl
10 verbose lifecycle NeteaseCloudMusicApi@1.2.2~test: CWD: C:\Users\ztf\Desktop\NeteaseCloudMusicApi
11 silly lifecycle NeteaseCloudMusicApi@1.2.2~test: Args: [ '/d /s /c', 'babel-node test/test.js' ]
12 silly lifecycle NeteaseCloudMusicApi@1.2.2~test: Returned: code: 1 signal: null
13 info lifecycle NeteaseCloudMusicApi@1.2.2~test: Failed to exec test script
14 verbose stack Error: NeteaseCloudMusicApi@1.2.2 test: `babel-node test/test.js`
14 verbose stack Exit status 1
14 verbose stack at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\lifecycle.js:245:16)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at EventEmitter.emit (events.js:191:7)
14 verbose stack at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\lib\utils\spawn.js:24:14)
14 verbose stack at emitTwo (events.js:106:13)
14 verbose stack at ChildProcess.emit (events.js:191:7)
14 verbose stack at maybeClose (internal/child_process.js:852:16)
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:5)
15 verbose pkgid NeteaseCloudMusicApi@1.2.2
16 verbose cwd C:\Users\ztf\Desktop\NeteaseCloudMusicApi
17 error Windows_NT 10.0.14376
18 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "test"
19 error node v6.2.2
20 error npm v3.9.5
21 error code ELIFECYCLE
22 error NeteaseCloudMusicApi@1.2.2 test: `babel-node test/test.js`
22 error Exit status 1
23 error Failed at the NeteaseCloudMusicApi@1.2.2 test script 'babel-node test/test.js'.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the NeteaseCloudMusicApi package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error babel-node test/test.js
23 error You can get information on how to open an issue for this project with:
23 error npm bugs NeteaseCloudMusicApi
23 error Or if that isn't available, you can get their info via:
23 error npm owner ls NeteaseCloudMusicApi
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]
{
"name": "NeteaseCloudMusicApi",
"version": "1.2.1",
"version": "1.2.3",
"description": "网易云音乐nodejs版接口模块",
"main": "build/app.js",
"scripts": {
"test": "babel-node test/test.js",
"build": "babel src/ -d build/"
},
"keywords": ["NeteaseCloudMusic","网易云音乐"],
"keywords": ["NeteaseCloudMusic","网易云音乐","网易云"],
"author": "traveller",
"license": "ISC",
"dependencies": {
......
......@@ -4,32 +4,30 @@ import { deepCopy } from './util'
let api = {
search: (name = null, callback = null, limit = 3, offset = 0) => {
let option = deepCopy(globalOption)
let url = origin + '/api/search/suggest/web'
let form = {
s: name,
limit,
type: 1,
offset
}
let method = 'POST'
let proxy = false
Object.assign(option, { url, form, method, proxy })
request(option, (error, response, body) => {
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2))
} else {
console.log(error)
let option = deepCopy(globalOption)
let url = origin + '/api/search/suggest/web'
let form = {
s: name,
limit,
type: 1,
offset
}
})
let method = 'POST'
Object.assign(option, { url, form, method })
request(option, (error, response, body) => {
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2))
} else {
console.log(error)
}
})
},
song: (id, callback = null) => {
let option = deepCopy(globalOption)
let url = origin + '/api/song/detail?ids=%5B' + id + '%5d'
let method = 'GET'
let proxy = false
Object.assign(option, { url, method, proxy })
Object.assign(option, { url, method })
request(option, (error, response, body) => {
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
......@@ -43,8 +41,7 @@ let api = {
let option = deepCopy(globalOption)
let url = origin + '/api/song/lyric?lv=' + lv + '&id=' + id
let method = 'GET'
let proxy = false
Object.assign(option, { url, method, proxy })
Object.assign(option, { url, method })
request(option, (error, response, body) => {
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
......
......@@ -5,7 +5,8 @@ const globalOption = {
'Origin': origin,
'Referer': origin,
'Content-Type': 'application/x-www-form-urlencoded'
}
},
proxy:false
}
export { origin, globalOption }
const deepCopy = (obj) => JSON.parse(JSON.stringify(obj))
const deepCopy = obj => JSON.parse(JSON.stringify(obj))
export { deepCopy }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册