提交 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)
# start
```
## Start
``` shell
npm install NeteaseCloudMusicApi
```
# usage
```js
var api=require('NeteaseCloudMusicApi').api
## Usage
``` javascript
var api = require('NeteaseCloudMusicApi').api
api.search('年度之歌',function(data){
console.log(data)
})
```
or
```js
``` javascript
import {api} from 'NeteaseCloudMusicApi'
api.search('年度之歌',(data)=>{
api.search('年度之歌',(data) => {
console.log(data)
})
```
# api
## search
```js
## API
### search
``` javascript
api.search(name:String,[callback:function,limit:Nnumber default:3, offset:Number default:0])
```
## lrc
```js
### lrc
``` javascript
api.lrc(id:Number,[callback:function,lv:Number default:-1])
```
## song
```js
### song
``` javascript
api.song(id:Number,[callback:function])
```
## Download
[github](https://github.com/Binaryify/NeteaseCloudMusicApi)
[npm](https://www.npmjs.com/package/NeteaseCloudMusicApi)
\ No newline at end of file
[npm](https://www.npmjs.com/package/NeteaseCloudMusicApi)
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');
var _request2 = _interopRequireDefault(_request);
var _config = require('./config');
var _util = require('./util');
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 = {
search: function search() {
var name = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0];
......@@ -29,8 +22,8 @@ var api = {
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 option = (0, _util.deepCopy)(_config.globalOption);
var url = _config.origin + '/api/search/suggest/web';
var form = {
s: name,
limit: limit,
......@@ -49,8 +42,8 @@ var api = {
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 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) {
......@@ -64,8 +57,8 @@ var api = {
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 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) {
......
'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 @@
"main": "build/app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "babel app.js -o build/app.js"
"build": "babel src/ -d build/"
},
"keywords": ["NeteaseCloudMusic","网易云音乐"],
"author": "traveller",
......@@ -17,4 +17,4 @@
"babel-core": "^6.9.1",
"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)=>{
console.log(data)
console.log(data)
})
api.song('308169',(data)=>{
console.log(data)
console.log(data)
})
api.lrc('5243023',(data)=>{
console.log(data)
})
\ No newline at end of file
console.log(data)
})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册