mirror of
https://gitlab.com/Binaryify/neteasecloudmusicapi.git
synced 2025-05-23 22:37:41 +08:00
Merge pull request #3 from rccoder/master
Update README & Fix proxy bug & plan directory
This commit is contained in:
commit
9798e969cd
20
.editorconfig
Normal file
20
.editorconfig
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# 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
|
38
README.MD
38
README.MD
@ -1,41 +1,47 @@
|
|||||||
一个调用网易云音乐API的node模块
|
# NeteaseCloudMusicApi
|
||||||
|
|
||||||
|
一个调用网易云音乐 API 的 node 模块
|
||||||
|
|
||||||

|

|
||||||
# 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)
|
||||||
|
55
app.js
55
app.js
@ -1,55 +0,0 @@
|
|||||||
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}
|
|
27
build/app.js
27
build/app.js
@ -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 = {
|
|||||||
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 = {
|
|||||||
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 = {
|
|||||||
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) {
|
||||||
|
17
build/config.js
Normal file
17
build/config.js
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
'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;
|
10
build/util.js
Normal file
10
build/util.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
var deepCopy = function deepCopy(obj) {
|
||||||
|
return JSON.parse(JSON.stringify(obj));
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.deepCopy = deepCopy;
|
@ -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 @@
|
|||||||
"babel-core": "^6.9.1",
|
"babel-core": "^6.9.1",
|
||||||
"babel-preset-es2015": "^6.9.0"
|
"babel-preset-es2015": "^6.9.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
58
src/app.js
Normal file
58
src/app.js
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
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}
|
11
src/config.js
Normal file
11
src/config.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const origin = 'http://music.163.com'
|
||||||
|
|
||||||
|
const globalOption = {
|
||||||
|
headers: {
|
||||||
|
'Origin': origin,
|
||||||
|
'Referer': origin,
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { origin, globalOption }
|
3
src/util.js
Normal file
3
src/util.js
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
const deepCopy = (obj) => JSON.parse(JSON.stringify(obj))
|
||||||
|
|
||||||
|
export { deepCopy }
|
10
test.js
10
test.js
@ -1,10 +0,0 @@
|
|||||||
import {api }from './app.js'
|
|
||||||
api.search("年度之歌",(data)=>{
|
|
||||||
console.log(data)
|
|
||||||
})
|
|
||||||
api.song('308169',(data)=>{
|
|
||||||
console.log(data)
|
|
||||||
})
|
|
||||||
api.lrc('5243023',(data)=>{
|
|
||||||
console.log(data)
|
|
||||||
})
|
|
11
test/test.js
Normal file
11
test/test.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { api } from '../src/app.js'
|
||||||
|
|
||||||
|
api.search("年度之歌",(data)=>{
|
||||||
|
console.log(data)
|
||||||
|
})
|
||||||
|
api.song('308169',(data)=>{
|
||||||
|
console.log(data)
|
||||||
|
})
|
||||||
|
api.lrc('5243023',(data)=>{
|
||||||
|
console.log(data)
|
||||||
|
})
|
Loading…
x
Reference in New Issue
Block a user