Skip to content

Commit bfa6f9f

Browse files
committed
Add NeteaseCloudMusic API
1 parent 9705520 commit bfa6f9f

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"passthrough-counter": "^1.0.0",
5959
"redis": "^2.8.0",
6060
"sequelize": "^4.32.2",
61+
"simple-netease-cloud-music": "^0.3.2",
6162
"uuid": "^3.2.1",
6263
"winston": "^2.4.0"
6364
}

routes.js

+11
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,16 @@ module.exports = (router, controller) => {
1111
router.get('/', controller.hitokoto)
1212
// router.get('/test', controller.hello.index)
1313
router.get('/status', controller.status)
14+
15+
// Netease API
16+
router.get('/nm/search/:id', controller.netease.search)
17+
router.get('/nm/playlist/:id', controller.netease.playlist)
18+
router.get('/nm/picture/:id/:height?', controller.netease.picture)
19+
router.get('/nm/artist/:id', controller.netease.artist)
20+
router.get('/nm/album/:id', controller.netease.album)
21+
router.get('/nm/lyric/:id', controller.netease.lyric)
22+
router.get('/nm/url/:id', controller.netease.url)
23+
router.get('/nm/detail/:id', controller.netease.detail)
24+
1425
return router
1526
}

src/controllers/netease.js

+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Import Packages
2+
const NeteaseMusic = require('simple-netease-cloud-music')
3+
const nm = new NeteaseMusic()
4+
5+
const controllers = {}
6+
7+
// Search API
8+
controllers.search = async (ctx, next) => {
9+
const ret = await nm.search(ctx.params.id)
10+
ctx.body = ret || {
11+
message: 'API 在请求时出现了问题,再试一下看看?',
12+
feedback: '访问 /status 获得详细信息',
13+
now: new Date().toString()
14+
}
15+
}
16+
17+
// Playlist API
18+
controllers.playlist = async (ctx, next) => {
19+
const ret = await nm.playlist(ctx.params.id)
20+
ctx.body = ret || {
21+
message: 'API 在请求时出现了问题,再试一下看看?',
22+
feedback: '访问 /status 获得详细信息',
23+
now: new Date().toString()
24+
}
25+
}
26+
27+
// Picture API
28+
controllers.picture = async (ctx, next) => {
29+
const ret = ctx.params.height ? await nm.artist(ctx.params.id, ctx.params.height) : await nm.artist(ctx.params.id)
30+
ctx.body = ret || {
31+
message: 'API 在请求时出现了问题,再试一下看看?',
32+
feedback: '访问 /status 获得详细信息',
33+
now: new Date().toString()
34+
}
35+
}
36+
37+
// Artist API
38+
controllers.artist = async (ctx, next) => {
39+
const ret = ctx.params.id
40+
ctx.body = ret || {
41+
message: 'API 在请求时出现了问题,再试一下看看?',
42+
feedback: '访问 /status 获得详细信息',
43+
now: new Date().toString()
44+
}
45+
}
46+
47+
// Album API
48+
controllers.album = async (ctx, next) => {
49+
const ret = await nm.album(ctx.params.id)
50+
ctx.body = ret || {
51+
message: 'API 在请求时出现了问题,再试一下看看?',
52+
feedback: '访问 /status 获得详细信息',
53+
now: new Date().toString()
54+
}
55+
}
56+
57+
// Lyric API
58+
controllers.lyric = async (ctx, next) => {
59+
const ret = await nm.lyric(ctx.params.id)
60+
ctx.body = ret || {
61+
message: 'API 在请求时出现了问题,再试一下看看?',
62+
feedback: '访问 /status 获得详细信息',
63+
now: new Date().toString()
64+
}
65+
}
66+
67+
// Music URL API
68+
controllers.url = async (ctx, next) => {
69+
const ret = await nm.url(ctx.params.id)
70+
ctx.body = ret || {
71+
message: 'API 在请求时出现了问题,再试一下看看?',
72+
feedback: '访问 /status 获得详细信息',
73+
now: new Date().toString()
74+
}
75+
}
76+
77+
// Song Detail API
78+
controllers.detail = async (ctx, next) => {
79+
const ret = await nm.song(ctx.params.id)
80+
ctx.body = ret || {
81+
message: 'API 在请求时出现了问题,再试一下看看?',
82+
feedback: '访问 /status 获得详细信息',
83+
now: new Date().toString()
84+
}
85+
}
86+
87+
module.exports = controllers

yarn.lock

+4
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,10 @@ signal-exit@^3.0.0, signal-exit@^3.0.1, signal-exit@^3.0.2:
23322332
version "3.0.2"
23332333
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
23342334

2335+
simple-netease-cloud-music@^0.3.2:
2336+
version "0.3.2"
2337+
resolved "https://registry.yarnpkg.com/simple-netease-cloud-music/-/simple-netease-cloud-music-0.3.2.tgz#199ec53c43c0441310e3f48a66ed7376b19c6412"
2338+
23352339
slice-ansi@1.0.0:
23362340
version "1.0.0"
23372341
resolved "https://registry.yarnpkg.com/slice-ansi/-/slice-ansi-1.0.0.tgz#044f1a49d8842ff307aad6b505ed178bd950134d"

0 commit comments

Comments
 (0)