Repository navigation
Conversation
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
left a comment
There was a problem hiding this comment.
Please do not tamper with the PR template.
Thanks for the reminder! I have restored the PR description to follow the template! |
There was a problem hiding this comment.
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 onDisableMediaLink, 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.
| _, 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) |
| 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) |
| 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 "" | ||
| } |
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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 The request shape used in this PR has been packet captured and verified from the current PikPak Web traffic. In my testing, the previous For the |
pikachuren
left a comment
There was a problem hiding this comment.
🙏 感谢 @wiskiiii 提交!
🤖 AI 自动审核声明:本评审报告由 AI 自动生成,当前使用 Claude Opus 5 模型进行分析。
🎯 结论
🔄 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 — 媒体链接优选是明确的改进,但域名切换与参数丢弃需作者确认后再合并。
Summary / 摘要
This PR updates the PikPak media-link request path to match the current PikPak Web behavior when media links are enabled.
disable_media_linkisfalse, file details are requested with the current web-style request shape instead of forcingusage=CACHE.usage=FETCH/web_content_linkpath is preserved.In my testing, the previous
usage=CACHEmedia-link request could only returndl-z01a-*.mypikpak.*links. Those links were limited to about 12 MB/s in my environment. Thez01ahosts 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 thesea10blinks resolved to Alibaba Cloud and reached about 50 MB/s./ 此 PR 包含破坏性变更。
/ 此 PR 修改了公开 API、配置、存储格式或迁移行为。
/ 此 PR 需要关联仓库同步修改。
Related repository PRs / 关联仓库 PR:
Related Issues / 关联 Issue
N/A
Testing / 测试
go test ./...go test ./drivers/pikpakdl-a10b-*.mypikpak.*origin media links.dl-z01a-*links to about 50 MB/s ondl-a10b-*links in my environment.web_content_linkbehavior.Checklist / 检查清单
/ 我已阅读 CONTRIBUTING。
/ 我确认此贡献符合仓库许可证、贡献规范和行为准则。
gofmt,go fmt, orprettierwhere applicable./ 我已按适用情况使用
gofmt,go fmt或prettier格式化变更代码。/ 我已在适用情况下请求相关维护者或代码所有者审查。
AI Disclosure / AI 使用声明
/ 此 PR 包含 AI 辅助内容。
Tools used / 使用工具:
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-Byattribution./ 我已确保所有 AI 辅助提交都包含
Co-Authored-By归属信息。I can reproduce all AI-assisted content included in this PR without any AI tools.
/ 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。