This repository has been archived by the owner on Apr 18, 2018. It is now read-only.
forked from Copay/cloudmusicapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
115 lines (105 loc) · 3.08 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
'use strict';
const core = require('./lib/core.lib');
function search(name, callback, { limit = '5', type = '1' } = {}) {
if (typeof limit == 'number') limit = limit.toString();
if (typeof type == 'number') type = type.toString();
if (!name) { throw new Error('Name not Found!!!'); }
const form = {
s: name,
limit,
total: true,
type,
csrf_token: '',
offset: '0'
};
core.post('http://music.163.com/weapi/cloudsearch/get/web?csrf_token=', form, (data) => callback(data));
};
function getAlbum(id, callback) {
if (id == 0) throw new Error('叽叽叽???');
if (typeof id == 'number') id = id.toString();
const form = {
album_id: id,
csrf_token: ''
};
core.post('http://music.163.com/weapi/v1/album/' + id + '?csrf_token=', form, (data) => callback(data));
};
function getDetail(id, callback) {
let isArr = false;
if (id == 0) throw new Error('叽叽叽???');
if (typeof id == 'number') {
id = id.toString();
} else if (Array.isArray(id)) {
id = JSON.stringify(id);
isArr = true;
}
const form = {
ids: id,
csrf_token: ''
};
core.post('http://music.163.com/weapi/v1/song/detail', form, (data) => callback(data, isArr));
};
function getPlaylist(id, callback) {
if (id == 0) throw new Error('叽叽叽???');
const form = {
id,
n: '1000',
csrf_token: ''
};
core.post('http://music.163.com/weapi/v3/playlist/detail?csrf_token=', form, (data) => callback(data));
};
function getURL(id, callback, br = '320000') {
if (id == 0) throw new Error('喵喵喵???');
if (typeof id == 'number') {
id = '[' + id + ']';
} else if (Array.isArray(id)) {
id = JSON.stringify(id);
} else if (id.substring(0, 1) !== '[') {
id = '[' + id + ']';
}
if (typeof br == 'number') br = br.toString();
const form = {
ids: id,
br,
csrf_token: ''
};
core.post('http://music.163.com/weapi/song/enhance/player/url?csrf_token=', form, (data) => callback(data));
};
function getLyric(id, callback) {
if (id == 0) throw new Error('哞哞哞???');
const form = {
id,
os: 'pc',
lv: '-1',
kv: '-1',
tv: '-1',
csrf_token: ''
};
core.post('http://music.163.com/weapi/song/lyric?csrf_token=', form, data => callback(data));
};
function getMV(id, callback) {
if (id == 0) throw new Error('WTF???');
const form = {
id,
csrf_token: ''
};
core.post('http://music.163.com/weapi/mv/detail/', form, (data) => callback(data));
};
function getRecord(uid, callback) {
if (uid === 0) throw new Error('WTF???');
const form = {
uid,
type: 0,
csrf_token: ''
};
core.post('http://music.163.com/weapi/v1/play/record?csrf_token=', form, (data) => callback(data));
};
module.exports = {
search: search,
getAlbum: getAlbum,
getDetail: getDetail,
getPlaylist: getPlaylist,
getURL: getURL,
getLyric: getLyric,
getMV: getMV,
getRecord: getRecord
};