Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1435 from SnowingFox/master
Browse files Browse the repository at this point in the history
feat(playlist_track_all): 获取歌单所有歌曲接口新增offset偏移量设置,以此达到分页效果
  • Loading branch information
Binaryify authored Jan 15, 2022
2 parents 4200833 + 4a941dd commit a0500ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 130 deletions.
16 changes: 14 additions & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1316,11 +1316,23 @@ tags: 歌单标签

**必选参数 :** `id` : 歌单 id

**可选参数 :** `limit` : 限制获取歌曲的数量
**可选参数 :** `limit` : 限制获取歌曲的数量,默认值为当前歌单的歌曲数量

**可选参数 :** `offset` : 默认值为0,用于歌曲的分页,计算方法为 `limit` * `offset`<= 你得到的歌曲 <= `limit` * `offset + 1`

**接口地址 :** `/playlist/track/all`

**调用例子 :** `/playlist/track/all?id=24381616&limit=10`
**调用例子 :** `/playlist/track/all?id=24381616&limit=10&offset=1`

> 注:关于`offset`,你可以这样理解,假设你当前的歌单有100首歌
>
> 你传入limit=10&offset=0等价于limit=10,你会得到第1-10首歌曲
>
> 你传入limit=10&offset=1,你会得到第11-20首歌曲
>
> 如果你设置limit=10&offset=2,你就会得到第21-30首歌曲
>
> 如果你offset超出了最大偏移量,即超出了`歌曲数量`/`limit`,则offset重置为最大偏移量
### 歌单详情动态

Expand Down
9 changes: 8 additions & 1 deletion module/playlist_track_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ module.exports = (query, request) => {
}
//不放在data里面避免请求带上无用的数据
let limit = query.limit
let offset = parseInt(query.offset) || 0
let allOffset
let trackIds
let idsData = Object.create(null)

Expand All @@ -23,8 +25,13 @@ module.exports = (query, request) => {
if (typeof limit === 'undefined') {
limit = trackIds.length
}
// 若offset超出最大偏移量则重置为最大偏移量
allOffset = trackIds.length / limit - 1
if (offset > allOffset) {
offset = allOffset
}
trackIds.forEach((item, index) => {
if (index < limit) {
if (index >= limit * offset && index < limit * (offset + 1)) {
ids.push(item.id)
}
})
Expand Down
129 changes: 2 additions & 127 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 comments on commit a0500ec

@vercel
Copy link

@vercel vercel bot commented on a0500ec Jan 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vercel
Copy link

@vercel vercel bot commented on a0500ec Jan 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

netease-cloud-music-api – ./docs

netease-cloud-music-api-git-master-binaryify.vercel.app
neteasecloudmusicapi.vercel.app

Please sign in to comment.