-
Notifications
You must be signed in to change notification settings - Fork 0
/
video.go
43 lines (36 loc) · 911 Bytes
/
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
package ytube
import (
"google.golang.org/api/youtube/v3"
)
type Video struct {
VideoID string `json:"id"`
Title string `json:"title"`
Thumbnail string `json:"thumbnail"`
PublishedAt string `json:"publishedAt"`
Description string `json:"description"`
Channel Channel `json:"channel"`
}
type Channel struct {
Name string `fig:"name" yaml:"name"`
ID string `fig:"id" yaml:"id"`
}
func FromSearchResult(raw *youtube.SearchResult) (Video, error) {
snippet := raw.Snippet
return Video{
VideoID: raw.Id.VideoId,
Thumbnail: snippet.Thumbnails.High.Url,
PublishedAt: snippet.PublishedAt,
Description: snippet.Description,
Title: snippet.Title,
Channel: Channel{
Name: snippet.ChannelTitle,
ID: snippet.ChannelId,
},
}, nil
}
func (v Video) ID() string {
return v.VideoID
}
func (v Video) URL() string {
return "https://youtu.be/" + v.ID()
}