-
Notifications
You must be signed in to change notification settings - Fork 89
/
clips.go
113 lines (95 loc) · 3.4 KB
/
clips.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
107
108
109
110
111
112
113
package helix
type Clip struct {
ID string `json:"id"`
URL string `json:"url"`
EmbedURL string `json:"embed_url"`
BroadcasterID string `json:"broadcaster_id"`
BroadcasterName string `json:"broadcaster_name"`
CreatorID string `json:"creator_id"`
CreatorName string `json:"creator_name"`
Duration float64 `json:"duration"`
VideoID string `json:"video_id"`
GameID string `json:"game_id"`
Language string `json:"language"`
Title string `json:"title"`
ViewCount int `json:"view_count"`
CreatedAt string `json:"created_at"`
ThumbnailURL string `json:"thumbnail_url"`
VodOffset int `json:"vod_offset"`
}
type ManyClips struct {
Clips []Clip `json:"data"`
Pagination Pagination `json:"pagination"`
}
type ClipsResponse struct {
ResponseCommon
Data ManyClips
}
type ClipsParams struct {
// One of the below
BroadcasterID string `query:"broadcaster_id"`
GameID string `query:"game_id"`
IDs []string `query:"id"` // Limit 100
// Optional
First int `query:"first,20"` // Maximum 100
After string `query:"after"`
Before string `query:"before"`
StartedAt Time `query:"started_at"`
EndedAt Time `query:"ended_at"`
}
// GetClips returns information about a specified clip.
func (c *Client) GetClips(params *ClipsParams) (*ClipsResponse, error) {
resp, err := c.get("/clips", &ManyClips{}, params)
if err != nil {
return nil, err
}
clips := &ClipsResponse{}
resp.HydrateResponseCommon(&clips.ResponseCommon)
clips.Data.Clips = resp.Data.(*ManyClips).Clips
clips.Data.Pagination = resp.Data.(*ManyClips).Pagination
return clips, nil
}
type ClipEditURL struct {
ID string `json:"id"`
EditURL string `json:"edit_url"`
}
type ManyClipEditURLs struct {
ClipEditURLs []ClipEditURL `json:"data"`
}
type CreateClipResponse struct {
ResponseCommon
Data ManyClipEditURLs
}
// GetClipsCreationRateLimit returns the "Ratelimit-Helixclipscreation-Limit"
// header as an int.
func (ccr *CreateClipResponse) GetClipsCreationRateLimit() int {
return ccr.convertHeaderToInt(ccr.Header.Get("Ratelimit-Helixclipscreation-Limit"))
}
// GetClipsCreationRateLimitRemaining returns the "Ratelimit-Helixclipscreation-Remaining"
// header as an int.
func (ccr *CreateClipResponse) GetClipsCreationRateLimitRemaining() int {
return ccr.convertHeaderToInt(ccr.Header.Get("Ratelimit-Helixclipscreation-Remaining"))
}
type CreateClipParams struct {
BroadcasterID string `query:"broadcaster_id"`
// Optional
HasDelay bool `query:"has_delay,false"`
}
// CreateClip creates a clip programmatically. This returns both an ID and
// an edit URL for the new clip. Clip creation takes time. We recommend that
// you query Get Clip, with the clip ID that is returned here. If Get Clip
// returns a valid clip, your clip creation was successful. If, after 15 seconds,
// you still have not gotten back a valid clip from Get Clip, assume that the
// clip was not created and retry Create Clip.
//
// Required scope: clips:edit
func (c *Client) CreateClip(params *CreateClipParams) (*CreateClipResponse, error) {
resp, err := c.post("/clips", &ManyClipEditURLs{}, params)
if err != nil {
return nil, err
}
clips := &CreateClipResponse{}
resp.HydrateResponseCommon(&clips.ResponseCommon)
clips.Data.ClipEditURLs = resp.Data.(*ManyClipEditURLs).ClipEditURLs
return clips, nil
}