/
zuiyou.go
executable file
·59 lines (50 loc) · 1.4 KB
/
zuiyou.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package parser
import (
"errors"
"net/url"
"strconv"
"github.com/tidwall/gjson"
"github.com/go-resty/resty/v2"
)
type zuiYou struct{}
func (z zuiYou) parseShareUrl(shareUrl string) (*VideoParseInfo, error) {
urlInfo, err := url.Parse(shareUrl)
if err != nil {
return nil, errors.New("parse share url fail")
}
if len(urlInfo.Query()["pid"]) <= 0 {
return nil, errors.New("can not parse video id from share url")
}
pid := urlInfo.Query()["pid"][0]
intPid, err := strconv.Atoi(pid)
if err != nil {
return nil, err
}
postData := map[string]interface{}{
"h_av": "5.2.13.011",
"pid": intPid,
}
client := resty.New()
res, err := client.R().
SetHeader(HttpHeaderUserAgent, DefaultUserAgent).
SetBody(postData).
Post("https://share.xiaochuankeji.cn/planck/share/post/detail")
if err != nil {
return nil, err
}
data := gjson.GetBytes(res.Body(), "data.post")
videoKey := data.Get("imgs.0.id").String()
videoPlayAddr := data.Get("videos." + videoKey + ".url").String()
videoCover := data.Get("videos." + videoKey + ".cover_urls.0").String()
title := data.Get("content").String()
userName := data.Get("member.name").String()
userAvatar := data.Get("member.avatar_urls.origin.urls.0").String()
parseRes := &VideoParseInfo{
Title: title,
VideoUrl: videoPlayAddr,
CoverUrl: videoCover,
}
parseRes.Author.Name = userName
parseRes.Author.Avatar = userAvatar
return parseRes, nil
}