Skip to content

Commit

Permalink
fix #25 修复快手解析问题
Browse files Browse the repository at this point in the history
  • Loading branch information
wujunwei928 committed Feb 19, 2024
1 parent 32eaccc commit b84cdf7
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions parser/kuaishou.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,16 @@ func (k kuaiShou) parseShareUrl(shareUrl string) (*VideoParseInfo, error) {
client.SetRedirectPolicy(resty.NoRedirectPolicy())
res, _ := 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)
//这里会返回err, auto redirect is disabled

// 获取 cookies: did,didv
cookies := res.RawResponse.Cookies()
if len(cookies) <= 0 {
return nil, errors.New("get cookies from share url fail")
}

locationRes, err := res.RawResponse.Location()
if err != nil {
return nil, err
Expand All @@ -27,23 +34,29 @@ func (k kuaiShou) parseShareUrl(shareUrl string) (*VideoParseInfo, error) {
// 分享的中间跳转链接不太一样, 有些是 /fw/long-video , 有些 /fw/photo
referUri := strings.ReplaceAll(locationRes.String(), "v.m.chenzhongtech.com/fw/long-video", "m.gifshow.com/fw/photo")
referUri = strings.ReplaceAll(referUri, "v.m.chenzhongtech.com/fw/photo", "m.gifshow.com/fw/photo")

videoId := strings.ReplaceAll(strings.Trim(locationRes.Path, "/"), "fw/long-video/", "")
videoId = strings.ReplaceAll(videoId, "fw/photo/", "")
if len(videoId) <= 0 {
return nil, errors.New("parse video id from share url fail")
}

postData := map[string]interface{}{
"photoId": videoId,
"isLongVideo": false,
"fid": "0",
"shareResourceType": "PHOTO_OTHER",
"shareChannel": "share_copylink",
"kpn": "KUAISHOU",
"subBiz": "BROWSE_SLIDE_PHOTO",
"env": "SHARE_VIEWER_ENV_TX_TRICK",
"h5Domain": "m.gifshow.com",
"photoId": videoId,
"isLongVideo": false,
}
videoRes, err := client.R().
SetHeader(HttpHeaderCookie, "_did=web_4611110883127BC1; did=web_9a0b966fb1674f6c9a4886a504bee5e5").
SetHeader("Origin", "https://m.gifshow.com").
SetHeader(HttpHeaderReferer, strings.ReplaceAll(referUri, "m.gifshow.com/fw/photo", "m.gifshow.com/fw/photo")).
SetHeader(HttpHeaderContentType, "application/json").
SetHeader(HttpHeaderUserAgent, DefaultUserAgent).
SetCookies(cookies).
SetBody(postData).
Post("https://m.gifshow.com/rest/wd/photo/info?kpn=KUAISHOU&captchaToken=")

Expand Down

0 comments on commit b84cdf7

Please sign in to comment.