-
Notifications
You must be signed in to change notification settings - Fork 89
/
videos.go
89 lines (75 loc) · 2.79 KB
/
videos.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
package helix
type Video struct {
ID string `json:"id"`
UserID string `json:"user_id"`
UserLogin string `json:"user_login"`
UserName string `json:"user_name"`
StreamID string `json:"stream_id"`
Title string `json:"title"`
Description string `json:"description"`
CreatedAt string `json:"created_at"`
PublishedAt string `json:"published_at"`
URL string `json:"url"`
ThumbnailURL string `json:"thumbnail_url"`
Viewable string `json:"viewable"`
ViewCount int `json:"view_count"`
Language string `json:"language"`
Type string `json:"type"`
Duration string `json:"duration"`
MutedSegments []VideoMutedSegment `json:"muted_segments"`
}
type VideoMutedSegment struct {
Duration int `json:"duration"`
Offest int `json:"offset"`
}
type ManyVideos struct {
Videos []Video `json:"data"`
Pagination Pagination `json:"pagination"`
}
type VideosParams struct {
IDs []string `query:"id"` // Limit 100
UserID string `query:"user_id"` // Limit 1
GameID string `query:"game_id"` // Limit 1
// Optional
After string `query:"after"`
Before string `query:"before"`
First int `query:"first,20"` // Limit 100
Language string `query:"language"` // Limit 1
Period string `query:"period,all"` // "all" (default), "day", "month", and "week"
Sort string `query:"sort,time"` // "time" (default), "trending", and "views"
Type string `query:"type,all"` // "all" (default), "upload", "archive", and "highlight"
}
type DeleteVideosParams struct {
IDs []string `query:"id"` // Limit 5
}
type VideosResponse struct {
ResponseCommon
Data ManyVideos
}
type DeleteVideosResponse struct {
ResponseCommon
}
// GetVideos gets video information by video ID (one or more), user ID (one only),
// or game ID (one only).
func (c *Client) GetVideos(params *VideosParams) (*VideosResponse, error) {
resp, err := c.get("/videos", &ManyVideos{}, params)
if err != nil {
return nil, err
}
videos := &VideosResponse{}
resp.HydrateResponseCommon(&videos.ResponseCommon)
videos.Data.Videos = resp.Data.(*ManyVideos).Videos
videos.Data.Pagination = resp.Data.(*ManyVideos).Pagination
return videos, nil
}
// DeleteVideos delete one or more videos (max 5)
// Required scope: channel:manage:videos
func (c *Client) DeleteVideos(params *DeleteVideosParams) (*DeleteVideosResponse, error) {
resp, err := c.delete("/videos", &DeleteVideosResponse{}, params)
if err != nil {
return nil, err
}
videos := &DeleteVideosResponse{}
resp.HydrateResponseCommon(&videos.ResponseCommon)
return videos, nil
}