-
Notifications
You must be signed in to change notification settings - Fork 88
/
stream_markers.go
106 lines (88 loc) · 3.04 KB
/
stream_markers.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package helix
type Marker struct {
ID string `json:"id"`
CreatedAt Time `json:"created_at"`
Description string `json:"description"`
PositionSeconds int `json:"position_seconds"`
URL string `json:"URL"`
}
type VideoMarker struct {
VideoID string `json:"video_id"`
Markers []Marker `json:"markers"`
}
type StreamMarker struct {
UserID string `json:"user_id"`
UserName string `json:"user_name"`
UserLogin string `json:"user_login"`
Videos []VideoMarker `json:"videos"`
}
type ManyStreamMarkers struct {
StreamMarkers []StreamMarker `json:"data"`
Pagination Pagination `json:"pagination"`
}
type StreamMarkersResponse struct {
ResponseCommon
Data ManyStreamMarkers
}
// StreamMarkersParams requires _either_ UserID or VideoID set
//
// UserID: fetches stream markers of the current livestream of the given user
// (VOD recording must be enabled).
// VideoID: fetches streams markers of the VOD.
type StreamMarkersParams struct {
UserID string `query:"user_id"`
VideoID string `query:"video_id"`
// Optional
After string `query:"after"`
Before string `query:"before"`
First int `query:"first,20"` // Limit 100
}
// GetStreamMarkers gets stream markers of a VOD or of the current live stream
// of an user being recorded as VOD.
//
// Required Scope: user:read:broadcast
func (c *Client) GetStreamMarkers(params *StreamMarkersParams) (*StreamMarkersResponse, error) {
resp, err := c.get("/streams/markers", &ManyStreamMarkers{}, params)
if err != nil {
return nil, err
}
markers := &StreamMarkersResponse{}
resp.HydrateResponseCommon(&markers.ResponseCommon)
markers.Data.StreamMarkers = resp.Data.(*ManyStreamMarkers).StreamMarkers
markers.Data.Pagination = resp.Data.(*ManyStreamMarkers).Pagination
return markers, nil
}
type CreateStreamMarker struct {
ID string `json:"id"`
CreatedAt Time `json:"created_at"`
Description string `json:"description"`
PositionSeconds int `json:"position_seconds"`
}
type ManyCreateStreamMarkers struct {
CreateStreamMarkers []CreateStreamMarker `json:"data"`
}
type CreateStreamMarkerResponse struct {
ResponseCommon
Data ManyCreateStreamMarkers
}
type CreateStreamMarkerParams struct {
UserID string `query:"user_id"`
// Optional
Description string `query:"description"`
}
// CreateStreamMarker creates a stream marker for a live stream at the current time.
// The user has to be the stream owner or an editor. Stream markers cannot be created
// in some cases, see:
// https://dev.twitch.tv/docs/api/reference/#create-stream-marker
//
// Required Scope: user:edit:broadcast
func (c *Client) CreateStreamMarker(params *CreateStreamMarkerParams) (*CreateStreamMarkerResponse, error) {
resp, err := c.post("/streams/markers", &ManyCreateStreamMarkers{}, params)
if err != nil {
return nil, err
}
markers := &CreateStreamMarkerResponse{}
resp.HydrateResponseCommon(&markers.ResponseCommon)
markers.Data.CreateStreamMarkers = resp.Data.(*ManyCreateStreamMarkers).CreateStreamMarkers
return markers, nil
}