-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaylists.go
50 lines (40 loc) · 1.16 KB
/
playlists.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
package main
import (
"fmt"
"google.golang.org/api/youtube/v3"
)
func getTitlesFromPlaylistID(playListID string, youtubeService *youtube.Service) []YTVideo {
fmt.Println(youtubeService)
call := youtubeService.PlaylistItems.List("snippet")
call = call.PlaylistId(playListID)
call = call.MaxResults(50)
playList, err := call.Do()
if err != nil {
fmt.Print(err)
}
var videos []YTVideo
for ok := true; ok; ok = !(playList.NextPageToken == "") {
for _, item := range playList.Items {
var video YTVideo
video.Title = item.Snippet.Title
video.ID = item.Snippet.ResourceId.VideoId
video.URL = buildURLFromVideoID(item.Snippet.ResourceId.VideoId)
videos = append(videos, video)
}
playList, err = call.PageToken(playList.NextPageToken).Do()
if err != nil {
fmt.Print(err)
}
}
return videos
}
func embedAllVideos(playListID string, youtubeService *youtube.Service) string {
videos := getTitlesFromPlaylistID(playListID, youtubeService)
var html string
html = "<html>\n<body>\n<div align='center'>\n"
for key, video := range videos {
html += buildEmbedCodeFromVideoID(key, video.ID)
}
html += "</div>\n</html>\n</body>"
return html
}