-
Notifications
You must be signed in to change notification settings - Fork 0
/
crawler.go
113 lines (90 loc) · 2.66 KB
/
crawler.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
package main
import (
"./baba"
"bufio"
"fmt"
"github.com/silentsokolov/go-vimeo/vimeo"
"os"
"strings"
)
func main() {
// try to get vimeoToken from env-vars
vimeoToken := os.Getenv("VIMEO_TOKEN")
//fmt.Printf("token from ENV: %v \n", vimeoToken)
vimeoToken = strings.TrimSpace(vimeoToken)
if len(vimeoToken) == 0 || len(vimeoToken) < 20 {
// if not found then ask the user to enter it manually
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter your VIMEO token: ")
vimeoToken, _ := reader.ReadString('\n')
vimeoToken = strings.TrimSpace(vimeoToken)
if len(vimeoToken) == 0 || len(vimeoToken) < 20 {
baba.DisplayTokenWarning()
panic("!!!missing vimeoToken!!!")
}
}
vimeoClient := baba.InitVimeoClient(vimeoToken)
if vimeoClient == nil {
baba.DisplayTokenWarning()
panic("!!!vimeoToken is NOT valid!!!")
}
loadVideosJavaZone(vimeoClient)
loadVideosNDCOslo(vimeoClient)
}
func loadVideosJavaZone(vimeoClient *vimeo.Client) {
community := baba.Community{}
community.UserId = "7540193"
community.Name = "JavaZone"
community.Albums = albums("JavaZone")
community.AlbumId = community.Albums["JavaZone-2018"]
fmt.Println(community)
for albumName, albumId := range community.Albums {
community.AlbumId = albumId
videos := baba.GetAlbumVideos(vimeoClient, community)
fmt.Printf("--> %v | videos #: %d \n", albumName, len(videos))
if len(videos) > 0 {
baba.WriteToFile(albumName, videos)
}
}
}
func loadVideosNDCOslo(vimeoClient *vimeo.Client) {
community := baba.Community{}
community.UserId = "12026726"
community.Name = "NDC-Oslo"
community.Albums = albums("NDC-Oslo")
community.AlbumId = community.Albums["NDC-Oslo-2018"]
fmt.Println(community)
for albumName, albumId := range community.Albums {
community.AlbumId = albumId
videos := baba.GetAlbumVideos(vimeoClient, community)
fmt.Printf("--> %v | videos #: %d \n", albumName, len(videos))
if len(videos) > 0 {
baba.WriteToFile(albumName, videos)
}
}
}
func albums(which string) (albums map[string]string){
// TODO: load album list from API
albums = make(map[string]string)
if strings.Contains(strings.ToUpper(which), "NDC-OSLO") {
albums["NDC-Oslo-2018"] = "5477311"
albums["NDC-Oslo-2017"] = "5491392"
albums["NDC-Oslo-2016"] = "5506154"
} else { // default javazone
albums["JavaZone-2018"] = "5419780"
albums["JavaZone-2017"] = "4766821"
albums["JavaZone-2016"] = "4133413"
//albums["JavaZone-2015"] = "3556815"
//albums["JavaZone-2014"] = "3031533"
}
return
}
/*func albumName(javaZone baba.Community) (albumName string) {
for key,val := range javaZone.Albums {
if javaZone.AlbumId == val {
albumName = key
break
}
}
return
}*/