diff --git a/docs/README.md b/docs/README.md index 795ef68e53e..76ca0ec33f2 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1280,6 +1280,19 @@ tags: 歌单标签 **调用例子 :** `/playlist/detail?id=24381616` +### 获取歌单所有歌曲 + +说明 : 由于网易云接口限制,歌单详情只会提供10首歌,通过调用此接口,传入对应的歌单`id`,即可获得对应的所有歌曲 + +**必选参数 :** `id` : 歌单id + +**可选参数 :** `limit` : 限制获取歌曲的数量 + +**接口地址 :** `/playlist/track/all` + +**调用例子 :** `/playlist/track/all?id=24381616&limit=10` + + ### 歌单详情动态 说明 : 调用后可获取歌单详情动态部分,如评论数,是否收藏,播放数 diff --git a/docs/v2.md b/docs/v2.md index fc0b836cc79..08ba02f3bbd 100644 --- a/docs/v2.md +++ b/docs/v2.md @@ -542,6 +542,7 @@ category Code 取值: **调用例子 :** `/related/playlist?id=1` + ### 获取歌单详情 说明 : 歌单能看到歌单名字 , 但看不到具体歌单内容 , 调用此接口 , 传入歌单 id, 可 diff --git a/module/playlist_track_all.js b/module/playlist_track_all.js new file mode 100644 index 00000000000..03a8c3aac9c --- /dev/null +++ b/module/playlist_track_all.js @@ -0,0 +1,47 @@ +// 通过传过来的歌单id拿到所有歌曲数据 +// 支持传递参数limit来限制获取歌曲的数据数量 例如: /playlist/track/all?id=7044354223&limit=10 + +module.exports = (query, request) => { + const data = { + id: query.id, + n: 100000, + s: query.s || 8, + } + //不放在data里面避免请求带上无用的数据 + let limit = query.limit + let trackIds + let idsData = Object.create(null) + + return request('POST', `https://music.163.com/api/v6/playlist/detail`, data, { + crypto: 'api', + cookie: query.cookie, + proxy: query.proxy, + realIP: query.realIP, + }).then((res) => { + const ids = [] + let trackIds = res.body.playlist.trackIds + if (typeof limit === 'undefined') { + limit = trackIds.length + } + trackIds.forEach((item, index) => { + if (index < limit) { + ids.push(item.id) + } + }) + idsData = { + c: '[' + ids.map((id) => '{"id":' + id + '}').join(',') + ']', + } + + return request( + 'POST', + `https://music.163.com/api/v3/song/detail`, + idsData, + { + crypto: 'weapi', + cookie: query.cookie, + proxy: query.proxy, + realIP: query.realIP, + }, + ) + }) +} diff --git a/package-lock.json b/package-lock.json index bec6d73e2fd..07368fe770e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,7 +5,6 @@ "requires": true, "packages": { "": { - "name": "NeteaseCloudMusicApi", "version": "4.0.23", "license": "MIT", "dependencies": {