-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fantia.go
92 lines (82 loc) · 2.85 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
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
package cdlogic
import (
"github.com/KJHJason/Cultured-Downloader-Logic/api/fantia"
"github.com/KJHJason/Cultured-Downloader-Logic/constants"
"github.com/KJHJason/Cultured-Downloader-Logic/httpfuncs"
)
// Start the download process for Fantia
func FantiaDownloadProcess(fantiaDl *fantia.FantiaDl, fantiaDlOptions *fantia.FantiaDlOptions, catchInterrupt bool) []error {
defer fantiaDlOptions.CancelCtx()
if !fantiaDlOptions.Base.DlThumbnails && !fantiaDlOptions.Base.DlImages && !fantiaDlOptions.Base.DlAttachments {
return nil
}
if catchInterrupt {
stopSignal := catchInterruptSignal(fantiaDlOptions.CancelCtx)
defer stopSignal()
}
var errorSlice []error
if len(fantiaDl.FanclubIds) > 0 {
if errSlice := fantiaDl.GetFanclubsPosts(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 len(fantiaDl.ProductFanclubIds) > 0 && fantiaDlOptions.CtxIsActive() {
if errSlice := fantiaDl.GetFanclubsProducts(fantiaDlOptions); len(errSlice) > 0 {
errorSlice = append(errorSlice, errSlice...)
}
}
if len(fantiaDl.ProductIds) > 0 && fantiaDlOptions.CtxIsActive() {
productContents, errSlice := fantiaDl.GetProducts(fantiaDlOptions)
if len(errSlice) > 0 {
errorSlice = append(errorSlice, errSlice...)
}
downloadedPosts = true
cancelled, errSlice := httpfuncs.DownloadUrls(
productContents,
&httpfuncs.DlOptions{
Context: fantiaDlOptions.GetContext(),
MaxConcurrency: constants.FANTIA_MAX_CONCURRENCY,
Cookies: fantiaDlOptions.Base.SessionCookies,
UseHttp3: constants.FANTIA_PRODUCT_USE_HTTP3,
SupportRange: constants.FANTIA_RANGE_SUPPORTED,
HeadReqTimeout: constants.DEFAULT_HEAD_REQ_TIMEOUT,
Filters: fantiaDlOptions.Base.Filters,
ProgressBarInfo: fantiaDlOptions.Base.ProgressBarInfo,
},
fantiaDlOptions.Base.Configs,
)
if cancelled {
return nil
}
if len(errSlice) > 0 {
errorSlice = append(errorSlice, errSlice...)
}
}
if fantiaDlOptions.Base.GdriveClient != nil && len(gdriveLinks) > 0 && fantiaDlOptions.CtxIsActive() {
gdriveErrs := fantiaDlOptions.Base.GdriveClient.DownloadGdriveUrls(
gdriveLinks,
fantiaDlOptions.Base.ProgressBarInfo,
fantiaDlOptions.Base.Filters,
)
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
}