提交 9798e969 编写于 作者: B binaryify 提交者: GitHub

Merge pull request #3 from rccoder/master

Update README & Fix proxy bug & plan directory
# EditorConfig helps developers define and maintain consistent
# coding styles between different editors and IDEs
# editorconfig.org
root = true
[*]
# Change these settings to your own preference
indent_style = space
indent_size = 2
# We recommend you to keep these unchanged
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false
一个调用网易云音乐API的node模块 # NeteaseCloudMusicApi
一个调用网易云音乐 API 的 node 模块
![](http://binaryify.github.io/images/api.jpg) ![](http://binaryify.github.io/images/api.jpg)
# start
``` ## Start
``` shell
npm install NeteaseCloudMusicApi npm install NeteaseCloudMusicApi
``` ```
# usage
```js ## Usage
var api=require('NeteaseCloudMusicApi').api ``` javascript
var api = require('NeteaseCloudMusicApi').api
api.search('年度之歌',function(data){ api.search('年度之歌',function(data){
console.log(data) console.log(data)
}) })
``` ```
or or
```js ``` javascript
import {api} from 'NeteaseCloudMusicApi' import {api} from 'NeteaseCloudMusicApi'
api.search('年度之歌',(data)=>{ api.search('年度之歌',(data) => {
console.log(data) console.log(data)
}) })
``` ```
# api ## API
## search
```js ### search
``` javascript
api.search(name:String,[callback:function,limit:Nnumber default:3, offset:Number default:0]) api.search(name:String,[callback:function,limit:Nnumber default:3, offset:Number default:0])
``` ```
## lrc ### lrc
```js ``` javascript
api.lrc(id:Number,[callback:function,lv:Number default:-1]) api.lrc(id:Number,[callback:function,lv:Number default:-1])
``` ```
## song ### song
```js ``` javascript
api.song(id:Number,[callback:function]) api.song(id:Number,[callback:function])
``` ```
## Download
[github](https://github.com/Binaryify/NeteaseCloudMusicApi) [github](https://github.com/Binaryify/NeteaseCloudMusicApi)
[npm](https://www.npmjs.com/package/NeteaseCloudMusicApi) [npm](https://www.npmjs.com/package/NeteaseCloudMusicApi)
\ No newline at end of file
import request from 'request'
const deepCopy = (obj) => JSON.parse(JSON.stringify(obj))
const origin = 'http://music.163.com'
let globalOption = {
headers: {
'Origin': origin,
'Referer': origin,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
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'
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))
}
})
},
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, (error, response, body) => {
if (!error && response.statusCode == 200) {
let info = JSON.parse(body);
callback && callback(JSON.stringify(info, '', 2))
}
})
},
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, (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
...@@ -9,19 +9,12 @@ var _request = require('request'); ...@@ -9,19 +9,12 @@ var _request = require('request');
var _request2 = _interopRequireDefault(_request); var _request2 = _interopRequireDefault(_request);
var _config = require('./config');
var _util = require('./util');
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var deepCopy = function deepCopy(obj) {
return JSON.parse(JSON.stringify(obj));
};
var origin = 'http://music.163.com';
var globalOption = {
headers: {
'Origin': origin,
'Referer': origin,
'Content-Type': 'application/x-www-form-urlencoded'
}
};
var api = { var api = {
search: function search() { search: function search() {
var name = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; var name = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
...@@ -29,8 +22,8 @@ var api = { ...@@ -29,8 +22,8 @@ var api = {
var limit = arguments.length <= 2 || arguments[2] === undefined ? 3 : arguments[2]; var limit = arguments.length <= 2 || arguments[2] === undefined ? 3 : arguments[2];
var offset = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3]; var offset = arguments.length <= 3 || arguments[3] === undefined ? 0 : arguments[3];
var option = deepCopy(globalOption); var option = (0, _util.deepCopy)(_config.globalOption);
var url = origin + '/api/search/suggest/web'; var url = _config.origin + '/api/search/suggest/web';
var form = { var form = {
s: name, s: name,
limit: limit, limit: limit,
...@@ -49,8 +42,8 @@ var api = { ...@@ -49,8 +42,8 @@ var api = {
song: function song(id) { song: function song(id) {
var callback = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1]; var callback = arguments.length <= 1 || arguments[1] === undefined ? null : arguments[1];
var option = deepCopy(globalOption); var option = (0, _util.deepCopy)(_config.globalOption);
var url = origin + '/api/song/detail?ids=%5B' + id + '%5d'; var url = _config.origin + '/api/song/detail?ids=%5B' + id + '%5d';
var method = 'GET'; var method = 'GET';
Object.assign(option, { url: url, method: method }); Object.assign(option, { url: url, method: method });
(0, _request2.default)(option, function (error, response, body) { (0, _request2.default)(option, function (error, response, body) {
...@@ -64,8 +57,8 @@ var api = { ...@@ -64,8 +57,8 @@ var api = {
var callback = arguments.length <= 1 || arguments[1] === undefined ? null : 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 lv = arguments.length <= 2 || arguments[2] === undefined ? -1 : arguments[2];
var option = deepCopy(globalOption); var option = (0, _util.deepCopy)(_config.globalOption);
var url = origin + '/api/song/lyric?lv=' + lv + '&id=' + id; var url = _config.origin + '/api/song/lyric?lv=' + lv + '&id=' + id;
var method = 'GET'; var method = 'GET';
Object.assign(option, { url: url, method: method }); Object.assign(option, { url: url, method: method });
(0, _request2.default)(option, function (error, response, body) { (0, _request2.default)(option, function (error, response, body) {
......
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var origin = 'http://music.163.com';
var globalOption = {
headers: {
'Origin': origin,
'Referer': origin,
'Content-Type': 'application/x-www-form-urlencoded'
}
};
exports.origin = origin;
exports.globalOption = globalOption;
\ No newline at end of file
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var deepCopy = function deepCopy(obj) {
return JSON.parse(JSON.stringify(obj));
};
exports.deepCopy = deepCopy;
\ No newline at end of file
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
"main": "build/app.js", "main": "build/app.js",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
"build": "babel app.js -o build/app.js" "build": "babel src/ -d build/"
}, },
"keywords": ["NeteaseCloudMusic","网易云音乐"], "keywords": ["NeteaseCloudMusic","网易云音乐"],
"author": "traveller", "author": "traveller",
...@@ -17,4 +17,4 @@ ...@@ -17,4 +17,4 @@
"babel-core": "^6.9.1", "babel-core": "^6.9.1",
"babel-preset-es2015": "^6.9.0" "babel-preset-es2015": "^6.9.0"
} }
} }
\ No newline at end of file
import request from 'request'
import { origin, globalOption } from './config'
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)
}
})
},
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 })
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)
}
})
},
lrc: (id, callback = null, lv = -1) => {
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 })
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)
}
})
}
}
export {api}
const origin = 'http://music.163.com'
const globalOption = {
headers: {
'Origin': origin,
'Referer': origin,
'Content-Type': 'application/x-www-form-urlencoded'
}
}
export { origin, globalOption }
const deepCopy = (obj) => JSON.parse(JSON.stringify(obj))
export { deepCopy }
import {api }from './app.js' import { api } from '../src/app.js'
api.search("年度之歌",(data)=>{ api.search("年度之歌",(data)=>{
console.log(data) console.log(data)
}) })
api.song('308169',(data)=>{ api.song('308169',(data)=>{
console.log(data) console.log(data)
}) })
api.lrc('5243023',(data)=>{ api.lrc('5243023',(data)=>{
console.log(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.
先完成此消息的编辑!
想要评论请 注册