fix: pikpak captcha_required (#6497)

* fix: pikpak captcha_required

* fix(pikpak_share):  video download
This commit is contained in:
foxxorcat
2024-05-22 23:29:29 +08:00
committed by GitHub
parent 9eec872637
commit 7013d1b7b8
6 changed files with 85 additions and 175 deletions

View File

@ -17,13 +17,14 @@ import (
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
"golang.org/x/oauth2"
)
type PikPak struct {
model.Storage
Addition
RefreshToken string
AccessToken string
oauth2Token oauth2.TokenSource
}
func (d *PikPak) Config() driver.Config {
@ -34,8 +35,32 @@ func (d *PikPak) GetAddition() driver.Additional {
return &d.Addition
}
func (d *PikPak) Init(ctx context.Context) error {
return d.login()
func (d *PikPak) Init(ctx context.Context) (err error) {
if d.ClientID == "" || d.ClientSecret == "" {
d.ClientID = "YNxT9w7GMdWvEOKa"
d.ClientSecret = "dbw2OtmVEeuUvIptb1Coyg"
}
withClient := func(ctx context.Context) context.Context {
return context.WithValue(ctx, oauth2.HTTPClient, base.HttpClient)
}
oauth2Config := &oauth2.Config{
ClientID: d.ClientID,
ClientSecret: d.ClientSecret,
Endpoint: oauth2.Endpoint{
AuthURL: "https://user.mypikpak.com/v1/auth/signin",
TokenURL: "https://user.mypikpak.com/v1/auth/token",
AuthStyle: oauth2.AuthStyleInParams,
},
}
oauth2Token, err := oauth2Config.PasswordCredentialsToken(withClient(ctx), d.Username, d.Password)
if err != nil {
return err
}
d.oauth2Token = oauth2Config.TokenSource(withClient(context.Background()), oauth2Token)
return nil
}
func (d *PikPak) Drop(ctx context.Context) error {