-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
kuaishou.go
74 lines (64 loc) · 1.5 KB
/
kuaishou.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
69
70
71
72
73
74
package tv
import (
"time"
"github.com/go-olive/tv/model"
"github.com/go-olive/tv/util"
)
const (
KsLiveDetailQuery = `
query LiveDetail($principalId: String) {
liveDetail(principalId: $principalId) {
liveStream
}
}
`
)
func init() {
registerSite("kuaishou", &kuaishou{})
}
type kuaishou struct {
base
}
func (this *kuaishou) Name() string {
return "快手"
}
func (this *kuaishou) Snap(tv *Tv) (err error) {
tv.Info = &Info{
Timestamp: time.Now().Unix(),
}
return this.set(tv)
}
func (this *kuaishou) set(tv *Tv) error {
if tv.cookie == "" {
return ErrCookieNotSet
}
ksAG := new(model.KsLiveDetailAutoGenerated)
req := &util.HttpRequest{
URL: "https://live.kuaishou.com/graphql",
Method: "POST",
RequestData: map[string]interface{}{
"operationName": "LiveDetail",
"variables": map[string]string{
"principalId": tv.RoomID,
},
"query": KsLiveDetailQuery,
},
ResponseData: ksAG,
ContentType: "application/json",
Header: map[string]string{
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36 Edg/94.0.992.38",
"referer": "https://live.kuaishou.com/",
"cookie": tv.cookie,
},
}
var err error
if err = req.Send(); err != nil {
return err
}
if len(ksAG.Data.WebLiveDetail.LiveStream.PlayUrls) > 0 {
tv.roomOn = true
tv.streamUrl = ksAG.Data.WebLiveDetail.LiveStream.PlayUrls[0].URL
}
tv.roomName = ksAG.Data.WebLiveDetail.LiveStream.Caption
return nil
}