-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fantia.go
54 lines (48 loc) · 1.65 KB
/
fantia.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
package cdlogic
import (
"github.com/KJHJason/Cultured-Downloader-Logic/api/fantia"
"github.com/KJHJason/Cultured-Downloader-Logic/httpfuncs"
"github.com/KJHJason/Cultured-Downloader-Logic/progress"
)
// Start the download process for Fantia
func FantiaDownloadProcess(fantiaDl *fantia.FantiaDl, fantiaDlOptions *fantia.FantiaDlOptions) []error {
defer fantiaDlOptions.CancelCtx()
if !fantiaDlOptions.DlThumbnails && !fantiaDlOptions.DlImages && !fantiaDlOptions.DlAttachments {
return nil
}
var errorSlice []error
if len(fantiaDl.FanclubIds) > 0 {
if errSlice := fantiaDl.GetCreatorsPosts(fantiaDlOptions); len(errSlice) > 0 {
errorSlice = append(errorSlice, errSlice...)
}
}
var gdriveLinks []*httpfuncs.ToDownload
var downloadedPosts bool
if len(fantiaDl.PostIds) > 0 && fantiaDlOptions.CtxIsActive() {
gdriveUrls, errSlice := fantiaDl.DlFantiaPosts(fantiaDlOptions)
if len(errSlice) > 0 {
errorSlice = append(errorSlice, errSlice...)
} else {
gdriveLinks = append(gdriveLinks, gdriveUrls...)
}
downloadedPosts = true
}
if fantiaDlOptions.GdriveClient != nil && len(gdriveLinks) > 0 && fantiaDlOptions.CtxIsActive() {
gdriveErrs := fantiaDlOptions.GdriveClient.DownloadGdriveUrls(
gdriveLinks,
&progress.ProgressBarInfo{
MainProgressBar: fantiaDlOptions.MainProgBar,
DownloadProgressBars: fantiaDlOptions.DownloadProgressBars,
},
)
errorSlice = append(errorSlice, gdriveErrs...)
downloadedPosts = true
}
notifier := fantiaDlOptions.GetNotifier()
if downloadedPosts {
notifier.Alert("Downloaded all posts from Fantia!")
} else {
notifier.Alert("No posts to download from Fantia!")
}
return errorSlice
}