-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.go
57 lines (44 loc) · 1.13 KB
/
video.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
package ytube
import (
"encoding/json"
"time"
"google.golang.org/api/youtube/v3"
)
type VideoID struct {
VideoID string `json:"videoId"`
}
type VideoThumbnails struct {
Height int `json:"height"`
Width int `json:"width"`
URL string `json:"url"`
}
type VideoSnippet struct {
Title string `json:"title"`
ChannelTitle string `json:"channelTitle"`
PublishedAt time.Time `json:"publishedAt"`
Description time.Time `json:"description"`
Thumbnails map[string]VideoThumbnails `json:"thumbnails"`
}
type Video struct {
VideoID VideoID `json:"id"`
Snippet VideoSnippet `json:"snippet"`
}
type Channel struct {
Name string `fig:"name" yaml:"name"`
ID string `fig:"id" yaml:"id"`
}
func FromSearchResult(raw *youtube.SearchResult) (Video, error) {
var res Video
bt, err := raw.MarshalJSON()
if err != nil {
return res, err
}
err = json.Unmarshal(bt, &res)
return res, err
}
func (v Video) URL() string {
return "https://youtu.be/" + v.VideoID.VideoID
}
func (v Video) ToBotContent() (interface{}, error) {
return v.URL(), nil
}