mirror of
https://github.com/zhaarey/apple-music-downloader.git
synced 2025-10-23 15:11:05 +00:00
fix:requests to resty
This commit is contained in:
@@ -4,20 +4,25 @@ import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"github.com/gospider007/requests"
|
||||
"log/slog"
|
||||
|
||||
"github.com/go-resty/resty/v2"
|
||||
|
||||
"main/utils/runv3/cdm"
|
||||
)
|
||||
|
||||
type Key struct {
|
||||
ReqCli *requests.Client
|
||||
BeforeRequest func(cl *requests.Client, preCtx context.Context, method string, href string, options ...requests.RequestOption) (resp *requests.Response, err error)
|
||||
AfterRequest func(*requests.Response) ([]byte, error)
|
||||
ReqCli *resty.Client
|
||||
|
||||
BeforeRequest func(cl *resty.Client, ctx context.Context, url string, body []byte) (*resty.Response, error)
|
||||
|
||||
AfterRequest func(*resty.Response) ([]byte, error)
|
||||
}
|
||||
|
||||
func (w *Key) CdmInit() {
|
||||
wv.InitConstants()
|
||||
}
|
||||
|
||||
func (w *Key) GetKey(ctx context.Context, licenseServerURL string, PSSH string, headers map[string][]string) (string, []byte, error) {
|
||||
initData, err := base64.StdEncoding.DecodeString(PSSH)
|
||||
var keybt []byte
|
||||
@@ -35,21 +40,23 @@ func (w *Key) GetKey(ctx context.Context, licenseServerURL string, PSSH string,
|
||||
slog.Error("license request error: %v", err)
|
||||
return "", keybt, err
|
||||
}
|
||||
var response *requests.Response
|
||||
|
||||
var response *resty.Response
|
||||
|
||||
if w.BeforeRequest != nil {
|
||||
response, err = w.BeforeRequest(w.ReqCli, ctx, "post", licenseServerURL, requests.RequestOption{
|
||||
Data: licenseRequest,
|
||||
})
|
||||
response, err = w.BeforeRequest(w.ReqCli, ctx, licenseServerURL, licenseRequest)
|
||||
} else {
|
||||
response, err = w.ReqCli.Request(nil, "post", licenseServerURL, requests.RequestOption{
|
||||
Data: licenseRequest,
|
||||
})
|
||||
response, err = w.ReqCli.R().
|
||||
SetContext(ctx).
|
||||
SetBody(licenseRequest).
|
||||
Post(licenseServerURL)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
slog.Error("license request error: %s", err)
|
||||
return "", keybt, err
|
||||
}
|
||||
|
||||
var licenseResponse []byte
|
||||
if w.AfterRequest != nil {
|
||||
licenseResponse, err = w.AfterRequest(response)
|
||||
@@ -57,14 +64,14 @@ func (w *Key) GetKey(ctx context.Context, licenseServerURL string, PSSH string,
|
||||
return "", keybt, err
|
||||
}
|
||||
} else {
|
||||
licenseResponse = response.Content()
|
||||
licenseResponse = response.Body()
|
||||
}
|
||||
|
||||
keys, err := cdm.GetLicenseKeys(licenseRequest, licenseResponse)
|
||||
command := ""
|
||||
|
||||
for _, key := range keys {
|
||||
if key.Type == wv.License_KeyContainer_CONTENT {
|
||||
//command += hex.EncodeToString(key.ID) + ":" + hex.EncodeToString(key.Value)
|
||||
command += hex.EncodeToString(key.Value)
|
||||
keybt = key.Value
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user