-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pixivfanbox.go
87 lines (79 loc) · 2.84 KB
/
pixivfanbox.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
package cdlogic
import (
"github.com/KJHJason/Cultured-Downloader-Logic/api/pixivfanbox"
"github.com/KJHJason/Cultured-Downloader-Logic/constants"
"github.com/KJHJason/Cultured-Downloader-Logic/httpfuncs"
)
// Start the download process for Pixiv Fanbox
func PixivFanboxDownloadProcess(pixivFanboxDl *pixivfanbox.PixivFanboxDl, pixivFanboxDlOptions *pixivfanbox.PixivFanboxDlOptions, catchInterrupt bool) []error {
defer pixivFanboxDlOptions.CancelCtx()
if !pixivFanboxDlOptions.Base.DlThumbnails && !pixivFanboxDlOptions.Base.DlImages && !pixivFanboxDlOptions.Base.DlAttachments && !pixivFanboxDlOptions.Base.DlGdrive {
return nil
}
if catchInterrupt {
stopSignal := catchInterruptSignal(pixivFanboxDlOptions.CancelCtx)
defer stopSignal()
}
var errSlice []error
if len(pixivFanboxDl.CreatorIds) > 0 {
if err := pixivFanboxDl.GetCreatorsPosts(pixivFanboxDlOptions); len(err) > 0 {
errSlice = append(errSlice, err...)
}
}
var urlsToDownload, gdriveUrlsToDownload []*httpfuncs.ToDownload
if len(pixivFanboxDl.PostIds) > 0 && pixivFanboxDlOptions.CtxIsActive() {
var err []error
urlsToDownload, gdriveUrlsToDownload, err = pixivFanboxDl.GetPostDetails(
pixivFanboxDlOptions,
)
if len(err) > 0 {
errSlice = append(errSlice, err...)
}
}
var downloadedPosts bool
if len(urlsToDownload) > 0 && pixivFanboxDlOptions.CtxIsActive() {
cookies := pixivFanboxDlOptions.Base.SessionCookies
cookies = append(cookies, pixivFanboxDlOptions.CfCookies...)
downloadedPosts = true
cancelled, err := httpfuncs.DownloadUrls(
urlsToDownload,
&httpfuncs.DlOptions{
Context: pixivFanboxDlOptions.GetContext(),
MaxConcurrency: constants.PIXIV_FANBOX_MAX_CONCURRENCY,
Headers: pixivfanbox.GetPixivFanboxHeaders(),
Cookies: cookies,
UseHttp3: false,
HeadReqTimeout: constants.DEFAULT_HEAD_REQ_TIMEOUT,
SupportRange: constants.PIXIV_FANBOX_RANGE_SUPPORTED,
Filters: pixivFanboxDlOptions.Base.Filters,
ProgressBarInfo: pixivFanboxDlOptions.Base.ProgressBarInfo,
CaptchaHandler: pixivFanboxDlOptions.GetCaptchaHandler(),
},
pixivFanboxDlOptions.Base.Configs,
)
if cancelled {
return nil
}
if len(err) > 0 {
errSlice = append(errSlice, err...)
}
}
if pixivFanboxDlOptions.Base.GdriveClient != nil && len(gdriveUrlsToDownload) > 0 && pixivFanboxDlOptions.CtxIsActive() {
downloadedPosts = true
err := pixivFanboxDlOptions.Base.GdriveClient.DownloadGdriveUrls(
gdriveUrlsToDownload,
pixivFanboxDlOptions.Base.ProgressBarInfo,
pixivFanboxDlOptions.Base.Filters,
)
if len(err) > 0 {
errSlice = append(errSlice, err...)
}
}
notifier := pixivFanboxDlOptions.Base.Notifier
if downloadedPosts {
notifier.Alert("Downloaded all posts from Pixiv Fanbox!")
} else {
notifier.Alert("No posts to download from Pixiv Fanbox!")
}
return errSlice
}