-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
148 lines (120 loc) · 3.4 KB
/
main.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package main
import (
"context"
"fmt"
"log"
"net/url"
"os"
"strconv"
"strings"
"time"
)
const (
SavedRecordFileName = ".zoomdl_saved_records.json"
)
// Config defines the application configuration
type Config struct {
RecordingTypes []string
IgnoreTitles []string
Destinations []string
DeleteAfter bool
Duration time.Duration
Token string
APIEndpoint *url.URL
AuthEndpoint *url.URL
UserID string
ClientID string
ClientSecret string
Concurrency int
ChunckSizeMB int
StartingFromYear int
}
// SavedRecord is a dataentry stored in the saved records file that
// keeps track of all the records
type SavedRecord struct {
ID string `json:"id"`
SessionID string `json:"session_id"`
SavedAt time.Time `json:"saved_at"`
RecordedAt time.Time `json:"recorded_at"`
Path string `json:"path"`
}
func main() {
config := NewConfig()
fs, err := newMultiFS(context.Background(), config.Destinations)
if err != nil {
log.Fatalf("error opening destinations: %v", err)
}
zc := NewZoomClient(config, fs)
log.Printf("starting service with allowed recording types %v and ignored titles %v", config.RecordingTypes, config.IgnoreTitles)
for {
wait := config.Duration
if err := zc.Sweep(); err != nil {
log.Printf("error during sweep: %s", err)
wait = time.Second * 5
}
time.Sleep(wait)
}
}
// NewConfig returns a new initialized config
func NewConfig() *Config {
c := &Config{}
c.RecordingTypes = strings.Split(os.Getenv("ZOOMDL_RECORDING_TYPES"), ";")
c.IgnoreTitles = strings.Split(os.Getenv("ZOOMDL_IGNORE_TITLES"), ";")
c.Destinations = strings.Split(os.Getenv("ZOOMDL_DESTINATIONS"), ";")
if dir := os.Getenv("ZOOMDL_DIR"); dir != "" { // backwards compatibility
c.Destinations = append(c.Destinations, fmt.Sprintf("file://%s", dir))
}
c.UserID = envRequired("ZOOMDL_USER_ID")
c.ClientID = envRequired("ZOOMDL_CLIENT_ID")
c.ClientSecret = envRequired("ZOOMDL_CLIENT_SECRET")
c.APIEndpoint = envURL("ZOOMDL_API_ENDPOINT", "https://api.zoom.us/v2")
c.AuthEndpoint = envURL("ZOOMDL_AUTH_ENDPOINT", "https://zoom.us")
c.StartingFromYear = envInt("ZOOMDL_START_YEAR", 2018)
c.Concurrency = envInt("ZOOMDL_CONCURRENCY", 4)
c.ChunckSizeMB = envInt("ZOOMDL_CHUNKSIZE_MB", 256)
c.Duration = envDuration("ZOOMDL_DURATION", "30m")
c.DeleteAfter = os.Getenv("ZOOMDL_DELETE_AFTER") == "true"
return c
}
func envRequired(env string) string {
val := os.Getenv(env)
if val == "" {
log.Fatalf("missing required environment variable '%s'", env)
}
return val
}
func envDefault(env, defaultStr string) string {
val := os.Getenv(env)
if val == "" {
return defaultStr
}
return val
}
func envDuration(env, defaultDuration string) time.Duration {
val := envDefault(env, defaultDuration)
dur, err := time.ParseDuration(val)
if err != nil {
log.Fatalf("error parsing %s with value '%s': %v", env, val, err)
}
return dur
}
func envURL(env, defaultURL string) *url.URL {
val := envDefault(env, defaultURL)
u, err := url.Parse(val)
if err != nil {
log.Fatalf("error parsing for '%s' url '%s': %v", val, env, err)
}
return u
}
func envInt(env string, defaultInt int) int {
val := os.Getenv(env)
if val == "" {
return defaultInt
}
i, err := strconv.Atoi(val)
if err != nil {
log.Printf("error parsing for '%s' int '%s' (now using default): %v", val, env, err)
return defaultInt
}
return i
}