Skip to content

Commit

Permalink
修复快手 long-video 解析
Browse files Browse the repository at this point in the history
  • Loading branch information
wujunwei928 committed Nov 3, 2024
1 parent e8bd8bf commit 114a26a
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion parser/kuaishou.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"regexp"
"strings"

"github.com/go-resty/resty/v2"
"github.com/tidwall/gjson"
Expand All @@ -14,10 +15,30 @@ type kuaiShou struct{}

func (k kuaiShou) parseShareUrl(shareUrl string) (*VideoParseInfo, error) {
client := resty.New()
res, err := client.R().
// disable redirects in the HTTP client, get params before redirects
client.SetRedirectPolicy(resty.NoRedirectPolicy())
shareRes, err := client.R().
SetHeader(HttpHeaderUserAgent, DefaultUserAgent).
SetHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7").
Get(shareUrl)
// 非 resty.ErrAutoRedirectDisabled 错误时,返回错误
if !errors.Is(err, resty.ErrAutoRedirectDisabled) {
return nil, err
}

locationRes, err := shareRes.RawResponse.Location()
if err != nil {
return nil, err
}

// /fw/long-video/ 返回结果不一样, 统一替换为 /fw/photo/ 请求
locationUrl := locationRes.String()
locationUrl = strings.ReplaceAll(locationUrl, "/fw/long-video/", "/fw/photo/")

res, err := client.R().
SetHeader(HttpHeaderUserAgent, DefaultUserAgent).
SetHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7").
Get(locationUrl)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 114a26a

Please sign in to comment.