feat(pikpak&pikpak_share): add download address delay detection (#7136)

* feat(pikpak): add download address delay detection

* feat(pikpak_share): add download address delay detection
This commit is contained in:
YangXu
2024-09-08 10:45:43 +08:00
committed by GitHub
parent c9fa3d7cd6
commit 716d33fddd
6 changed files with 300 additions and 56 deletions

View File

@ -4,6 +4,7 @@ import (
"context"
"github.com/alist-org/alist/v3/internal/op"
"net/http"
"regexp"
"time"
"github.com/alist-org/alist/v3/internal/driver"
@ -36,6 +37,7 @@ func (d *PikPakShare) Init(ctx context.Context) error {
d.Common.CaptchaToken = token
op.MustSaveDriverStorage(d)
},
LowLatencyAddr: "",
}
}
@ -60,6 +62,21 @@ func (d *PikPakShare) Init(ctx context.Context) error {
d.PackageName = WebPackageName
d.Algorithms = WebAlgorithms
d.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
} else if d.Platform == "pc" {
d.ClientID = PCClientID
d.ClientSecret = PCClientSecret
d.ClientVersion = PCClientVersion
d.PackageName = PCPackageName
d.Algorithms = PCAlgorithms
d.UserAgent = "MainWindow Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) PikPak/2.5.6.4831 Chrome/100.0.4896.160 Electron/18.3.15 Safari/537.36"
}
if d.UseLowLatencyAddress && d.Addition.CustomLowLatencyAddress != "" {
d.Common.LowLatencyAddr = d.Addition.CustomLowLatencyAddress
} else if d.UseLowLatencyAddress {
d.Common.LowLatencyAddr = findLowestLatencyAddress(DlAddr)
d.Addition.CustomLowLatencyAddress = d.Common.LowLatencyAddr
op.MustSaveDriverStorage(d)
}
// 获取CaptchaToken
@ -71,6 +88,7 @@ func (d *PikPakShare) Init(ctx context.Context) error {
if d.SharePwd != "" {
return d.getSharePassToken()
}
return nil
}
@ -112,10 +130,16 @@ func (d *PikPakShare) Link(ctx context.Context, file model.Obj, args model.LinkA
}
}
link := model.Link{
URL: downloadUrl,
if d.UseLowLatencyAddress && d.Common.LowLatencyAddr != "" {
// 替换为加速链接
re := regexp.MustCompile(`https://[^/]+/download/`)
downloadUrl = re.ReplaceAllString(downloadUrl, "https://"+d.Common.LowLatencyAddr+"/download/")
}
return &link, nil
return &model.Link{
URL: downloadUrl,
}, nil
}
var _ driver.Driver = (*PikPakShare)(nil)