-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
93 lines (76 loc) · 1.61 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
package main
import (
"log"
"sync"
)
func main() {
err := TimeStamp()
if err != nil {
log.Fatal(err.Error())
panic(err)
}
err = InitDirs()
if err != nil {
log.Fatal(err.Error())
panic(err)
}
// ignores, err := GetIgnores()
if err != nil {
log.Fatal(err.Error())
panic(err)
}
youtubeClient, err := YoutubeClient()
if err != nil {
log.Fatal(err.Error())
panic(err)
}
playlist, _, total := GetPlayList(youtubeClient)
err = SavePlaylistToJSON(playlist, total)
if err != nil {
log.Fatalln(err.Error())
return
}
driveClient, err := DriveClient()
if err != nil {
log.Fatal(err.Error())
return
}
InitRootDir(driveClient)
files, err := GetDownloadedFiles(driveClient)
// for _, file := range files {
// // fmt.Printf("Files %+v\n\n\n", file.Name)
// println(file.Name)
// }
if err != nil {
log.Fatal(err.Error())
return
}
playlist, total = GetFilteredPlaylist(playlist, files, []string{})
if total == 0 {
println("Playlist is synced")
return
}
batches, perBatch, batchesSize := CalculateBatches(total)
var wg sync.WaitGroup
wg.Add(batchesSize)
// ignoresChannels := GetIgnoreChannels(batchesSize)
// for _, c := range ignoresChannels {
// defer close(c)
// }
for index, value := range batches {
multiplier := (index * perBatch)
start := multiplier + 1
end := multiplier + value
go func(index int) {
WorkerShell(index, start, end, playlist, driveClient)
wg.Done()
}(index)
}
// ignores = append(ignores, GetValuesFromIgnoreChannels(ignoresChannels)...)
wg.Wait()
// SyncIgnores(ignores)
if err != nil {
log.Fatal(err.Error())
return
}
}