Skip to content

fix(drivers/pikpak): prefer web media link request - #2599

Open
wiskiiii wants to merge 3 commits into
OpenListTeam:mainfrom
wiskiiii:fix/pikpak-web-media-link
Open

wiskiiii wants to merge 3 commits into
OpenListTeam:mainfrom
wiskiiii:fix/pikpak-web-media-link

Conversation

@wiskiiii

@wiskiiii wiskiiii commented Jun 11, 2026 •

Copy link
Copy Markdown

Summary / 摘要

This PR updates the PikPak media-link request path to match the current PikPak Web behavior when media links are enabled.

  • When disable_media_link is false, file details are requested with the current web-style request shape instead of forcing usage=CACHE.
  • Media URL selection now prefers:
    1. origin media link
    2. default media link
    3. first available media link
  • When media links are disabled, the existing usage=FETCH / web_content_link path is preserved.

In my testing, the previous usage=CACHE media-link request could only return dl-z01a-*.mypikpak.* links. Those links were limited to about 12 MB/s in my environment. The z01a hosts resolved to a Singapore ByteDance data center.

After this change, PikPak can return the same origin media links as the official web app, such as dl-a10b-*.mypikpak.*. In my environment these a10b links resolved to Alibaba Cloud and reached about 50 MB/s.

  • This PR has breaking changes.
    / 此 PR 包含破坏性变更。
  • This PR changes public API, config, storage format, or migration behavior.
    / 此 PR 修改了公开 API、配置、存储格式或迁移行为。
  • This PR requires corresponding changes in related repositories.
    / 此 PR 需要关联仓库同步修改。

Related repository PRs / 关联仓库 PR:

  • OpenList-Frontend:
  • OpenList-Docs:

Related Issues / 关联 Issue

N/A

Testing / 测试

  • go test ./...
  • go test ./drivers/pikpak
  • Manual test / 手动测试:
    • Built a custom OpenList binary with this change and tested using this change.
    • Verified that PikPak media-link requests can return dl-a10b-*.mypikpak.* origin media links.
    • Verified download speed improved from about 12 MB/s on dl-z01a-* links to about 50 MB/s on dl-a10b-* links in my environment.
    • Verified the disabled-media-link path still uses the normal web_content_link behavior.

Checklist / 检查清单

  • I have read CONTRIBUTING.
    / 我已阅读 CONTRIBUTING。
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
    / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable.
    / 我已按适用情况使用 gofmt, go fmt 或 prettier 格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable.
    / 我已在适用情况下请求相关维护者或代码所有者审查。

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.
    / 此 PR 包含 AI 辅助内容。

Tools used / 使用工具:

  • ChatGPT
  • Codex
  • GitHub Copilot
  • Claude
  • Gemini
  • Other (please specify) / 其他(请注明):

Usage scope / 使用范围:

  • Code generation / 代码生成

  • Refactoring / 重构

  • Documentation / 文档

  • Tests / 测试

  • Translation / 翻译

  • Review assistance / 审查辅助

  • I have reviewed and validated all AI-assisted content included in this PR.
    / 我已审核并验证此 PR 中的所有 AI 辅助内容。

  • I have ensured that all AI-assisted commits include Co-Authored-By attribution.
    / 我已确保所有 AI 辅助提交都包含 Co-Authored-By 归属信息。

  • I can reproduce all AI-assisted content included in this PR without any AI tools.
    / 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。

Use the current web file-detail request shape when media links are enabled, so PikPak returns the same origin media links as the web app. Keep the existing FETCH request path when media links are disabled, and prefer origin/default media links when selecting a media URL.\n\nCo-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@jyxjjj jyxjjj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please do not tamper with the PR template.

@wiskiiii

Copy link
Copy Markdown
Author

Please do not tamper with the PR template.

Thanks for the reminder! I have restored the PR description to follow the template!

@wiskiiii
wiskiiii marked this pull request as ready for review June 11, 2026 16:22
Copilot AI review requested due to automatic review settings June 11, 2026 16:22

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates the PikPak driver’s link-generation logic to improve media link selection and adjust the request used to fetch file metadata.

Changes:

  • Split Link() behavior based on DisableMediaLink, changing request URL/headers accordingly.
  • Add pickMediaLink() helper to choose a better media URL (origin/default/any).
  • Replace “first media only” selection with prioritized iteration across available medias.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread drivers/pikpak/driver.go
Comment on lines +139 to +156
_, err := d.request(fmt.Sprintf("https://api-drive.mypikpak.net/drive/v1/files/%s", file.GetID()),
http.MethodGet, func(req *resty.Request) {
req.SetContext(ctx).
SetQueryParams(queryParams)
}, &resp)
if err != nil {
return nil, err
}
url = resp.WebContentLink
} else {
_, err := d.request(fmt.Sprintf("https://api-drive.mypikpak.com/drive/v1/files/%s", file.GetID()),
http.MethodGet, func(req *resty.Request) {
req.SetContext(ctx).
SetHeader("Accept", "*/*").
SetHeader("Content-Type", "application/json").
SetHeader("Referer", "https://mypikpak.com/").
SetHeader("Origin", "https://mypikpak.com")
}, &resp)
Comment thread drivers/pikpak/driver.go
Comment on lines +133 to +143
if d.DisableMediaLink {
queryParams := map[string]string{
"_magic": "2021",
"usage": "FETCH",
"thumbnail_size": "SIZE_LARGE",
}
_, err := d.request(fmt.Sprintf("https://api-drive.mypikpak.net/drive/v1/files/%s", file.GetID()),
http.MethodGet, func(req *resty.Request) {
req.SetContext(ctx).
SetQueryParams(queryParams)
}, &resp)
Comment thread drivers/pikpak/driver.go
Comment on lines +172 to +189
func pickMediaLink(medias []Media) string {
for _, media := range medias {
if media.IsOrigin && media.Link.Url != "" {
return media.Link.Url
}
}
for _, media := range medias {
if media.IsDefault && media.Link.Url != "" {
return media.Link.Url
}
}
for _, media := range medias {
if media.Link.Url != "" {
return media.Link.Url
}
}
return ""
}
jyxjjj

This comment was marked as outdated.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@wiskiiii

Copy link
Copy Markdown
Author

Priority assessment:

P2: The implementation now relies on reproducing the current PikPak Web request shape, including endpoint selection and request headers. This introduces coupling to upstream Web behavior. It would be useful to document whether these values were verified from current client traffic and whether there is a fallback strategy if the Web client behavior changes in the future.

P3: pickMediaLink encodes a priority order (origin > default > first available) that appears reasonable, but the rationale is currently implicit in the implementation. A short code comment describing the selection policy would help future maintainers understand why this ordering is preferred.

No P0/P1 issues identified from the reviewed diff.

Thanks for the assessment!

I agree that this relies on the current PikPak Web behavior, and I understand the maintenance risk here. My understanding is that this is also an inherent risk of the PikPak driver itself, since it already depends on non-public PikPak APIs/client behavior. One example is that the previous implementation was still using the older .net API host, while the current Web client traffic uses the .com API host; this PR updates that path as part of aligning the media-link request with the current Web behavior.

The request shape used in this PR has been packet captured and verified from the current PikPak Web traffic. In my testing, the previous usage=CACHE request returned dl-z01a-* media links, while the Web-style file-detail request could return the faster origin dl-a10b-* media link for the same file.

For the pickMediaLink ordering, I have added a short code comment to document the selection policy: prefer origin media first, then the default media, and finally the first available media URL.

@xrgzs xrgzs changed the title fix(pikpak): prefer web media link request fix(drivers/pikpak): prefer web media link request Jun 17, 2026
@xrgzs xrgzs added the Module: Driver Driver-Related Issue/PR label Jun 17, 2026
@PIKACHUIM
PIKACHUIM requested a review from jyxjjj August 7, 2026 15:22

@pikachuren pikachuren left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

🙏 感谢 @wiskiiii 提交!
🤖 AI 自动审核声明:本评审报告由 AI 自动生成,当前使用 Claude Opus 5 模型进行分析。
⚠️ AI 分析结果仅供参考,可能存在误判或遗漏。如您发现任何问题或有不同意见,欢迎随时提出讨论和纠正。
⚠️ 重要提醒:即使 AI 评审认为代码质量良好且建议合并,最终是否合并仍需由项目维护者进行人工判定。项目维护者会综合考虑代码质量、项目规划、技术方向、团队资源等多方面因素做出决策。

🎯 结论

🔄 Request Changes — 媒体链接优选逻辑写得不错,但请求域名从 .net 改为 .com 缺少说明,需要确认

📖 概要

fix(drivers/pikpak): prefer web media link request · 优化 PikPak 获取播放链接的逻辑。
核心改动:按 DisableMediaLink 拆分为两条独立请求路径,新增 pickMediaLink 按「原画 → 默认 → 任意」优先级选取媒体链接。

🧭 整体方案

把原先「统一请求 + 条件覆盖」拆成两条清晰分支,并把媒体链接选取抽成独立函数。pickMediaLink 的三级降级(IsOrigin → IsDefault → 任意可用)比原先「无脑取 Medias[0]」明显更合理,这部分是实打实的改进。但非 disable 分支同时把请求域名从 api-drive.mypikpak.net 换成了 api-drive.mypikpak.com 并新增了一组 Referer/Origin 头,这个改动没有在描述里说明。

📊 变更统计

1 个文件(+53 / -21 行) | 功能 ⭐⭐⭐⭐ | 最小改动 ⭐⭐⭐ | 前向兼容 ⭐⭐⭐ | 方案设计 ⭐⭐⭐⭐

🚨 关键问题

P0(阻塞合并):无

P1(建议修复):

  • ⚠️ drivers/pikpak/driver.go — 非 disable 分支的域名从 .net 改为 .com,而同文件 MakeDir 等方法仍在用 .net,导致同一驱动内两个域名并存。请问 .com 是当前 web 端实际使用的域名吗?建议在描述中说明依据,并确认 .net 是否仍可用(避免部分地区 .com 不可达而 .net 可达的情况)~
  • ⚠️ 新分支丢弃了原有的 _magic / usage / thumbnail_size 查询参数。原代码启用媒体链接时会传 usage=CACHE,新代码在该分支完全不传。请问这是刻意简化吗?如果服务端依赖 usage 决定返回内容,可能影响 Medias 字段的完整性~

P2(可选):

  • 💡 pickMediaLink 三次遍历切片。媒体数量通常很少、性能无影响,也可以用一次遍历记录三个候选,代码更紧凑~
  • 💡 两个分支都有 resp.WebContentLink 赋值与错误处理,可把公共部分提出来减少重复~

📂 逐文件分析

drivers/pikpak/driver.go

改动意图:改善播放链接质量,优先返回原画媒体链接。
代码逻辑:DisableMediaLink 为真走原 .net + 查询参数路径取 WebContentLink;为假走 .com + web 端请求头路径,并用 pickMediaLink 优选。
问题分析:pickMediaLink 的优先级设计正确、边界处理完善(每级都校验 Link.Url != "")。主要待确认项是域名切换依据与查询参数丢弃(均见 P1)。

✅ 待处理清单

  • [P1] 说明 .net → .com 域名切换的依据,并确认各地区网络可达性
  • [P1] 确认丢弃 _magic / usage / thumbnail_size 是否影响 Medias 返回
  • [P2] 可将 pickMediaLink 优化为单次遍历
  • [P2] 提取两个分支的重复逻辑

🎯 结论:🔄 Request Changes — 媒体链接优选是明确的改进,但域名切换与参数丢弃需作者确认后再合并。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Module: Driver Driver-Related Issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants