-
Notifications
You must be signed in to change notification settings - Fork 56
/
quanmin.go
executable file
·68 lines (57 loc) · 1.74 KB
/
quanmin.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
60
61
62
63
64
65
66
67
68
package parser
import (
"errors"
"net/url"
"github.com/go-resty/resty/v2"
"github.com/tidwall/gjson"
)
type quanMin struct{}
func (q quanMin) parseShareUrl(shareUrl string) (*VideoParseInfo, error) {
urlRes, err := url.Parse(shareUrl)
if err != nil {
return nil, err
}
videoId := urlRes.Query().Get("vid")
if len(videoId) <= 0 {
return nil, errors.New("parse video_id from share url fail")
}
return q.parseVideoID(videoId)
}
func (q quanMin) parseVideoID(videoId string) (*VideoParseInfo, error) {
reqUrl := "https://quanmin.hao222.com/wise/growth/api/sv/immerse?source=share-h5&pd=qm_share_mvideo&_format=json&vid=" + videoId
client := resty.New()
res, err := client.R().
SetHeader(HttpHeaderUserAgent, DefaultUserAgent).
Get(reqUrl)
if err != nil {
return nil, err
}
// 接口返回错误
if gjson.GetBytes(res.Body(), "errno").Int() != 0 {
return nil, errors.New(gjson.GetBytes(res.Body(), "error").String())
}
// 视频状态错误
metaStatusText := gjson.GetBytes(res.Body(), "data.meta.statusText").String()
if len(metaStatusText) > 0 {
return nil, errors.New(metaStatusText)
}
data := gjson.GetBytes(res.Body(), "data")
author := data.Get("author.name").String()
avatar := data.Get("author.icon").String()
videoUrl := data.Get("meta.video_info.clarityUrl.1.url").String()
cover := data.Get("meta.image").String()
// 获取视频标题,如果没有则使用分享标题
title := data.Get("meta.title").String()
if len(title) <= 0 {
title = data.Get("shareInfo.title").String()
}
parseRes := &VideoParseInfo{
Title: title,
VideoUrl: videoUrl,
CoverUrl: cover,
}
parseRes.Author.Uid = data.Get("author.id").String()
parseRes.Author.Name = author
parseRes.Author.Avatar = avatar
return parseRes, nil
}