forked from Binaryify/NeteaseCloudMusicApi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelated_playlist.js
39 lines (38 loc) · 1.16 KB
/
related_playlist.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
// 相关歌单
module.exports = (query, request) => {
return request(
'GET',
`https://music.163.com/playlist?id=${query.id}`,
{},
{
ua: 'pc',
cookie: query.cookie,
proxy: query.proxy,
realIP: query.realIP,
},
).then((response) => {
try {
const pattern =
/<div class="cver u-cover u-cover-3">[\s\S]*?<img src="([^"]+)">[\s\S]*?<a class="sname f-fs1 s-fc0" href="([^"]+)"[^>]*>([^<]+?)<\/a>[\s\S]*?<a class="nm nm f-thide s-fc3" href="([^"]+)"[^>]*>([^<]+?)<\/a>/g
let result,
playlists = []
while ((result = pattern.exec(response.body)) != null) {
playlists.push({
creator: {
userId: result[4].slice('/user/home?id='.length),
nickname: result[5],
},
coverImgUrl: result[1].slice(0, -'?param=50y50'.length),
name: result[3],
id: result[2].slice('/playlist?id='.length),
})
}
response.body = { code: 200, playlists: playlists }
return response
} catch (err) {
response.status = 500
response.body = { code: 500, msg: err.stack }
return Promise.reject(response)
}
})
}