-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kemono.go
112 lines (105 loc) · 3.38 KB
/
kemono.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
package cdlogic
import (
"github.com/KJHJason/Cultured-Downloader-Logic/api/kemono"
"github.com/KJHJason/Cultured-Downloader-Logic/constants"
"github.com/KJHJason/Cultured-Downloader-Logic/httpfuncs"
"github.com/KJHJason/Cultured-Downloader-Logic/logger"
)
func KemonoDownloadProcess(kemonoDl *kemono.KemonoDl, dlOptions *kemono.KemonoDlOptions, catchInterrupt bool) []error {
defer dlOptions.CancelCtx()
if !dlOptions.Base.DlAttachments && !dlOptions.Base.DlGdrive {
return nil
}
if catchInterrupt {
stopSignal := catchInterruptSignal(dlOptions.CancelCtx)
defer stopSignal()
}
var errSlice []error
var toDownload, gdriveLinks []*httpfuncs.ToDownload
if kemonoDl.DlFav {
prog := dlOptions.Base.MainProgBar()
prog.SetToSpinner()
prog.UpdateBaseMsg("Getting favourites from Kemono...")
prog.UpdateSuccessMsg("Finished getting favourites from Kemono!")
prog.UpdateErrorMsg("Something went wrong while getting favourites from Kemono.\nPlease refer to the logs for more details.")
prog.Start()
favToDl, favGdriveLinks, err := kemono.GetFavourites(dlOptions)
hasErr := (err != nil)
if hasErr {
cancel := logger.LogErrors(logger.ERROR, err...)
if cancel {
return nil
}
errSlice = append(errSlice, err...)
} else {
toDownload = favToDl
gdriveLinks = favGdriveLinks
}
prog.Stop(hasErr)
prog.SnapshotTask()
}
if len(kemonoDl.PostsToDl) > 0 && dlOptions.CtxIsActive() {
postsToDl, gdriveLinksToDl, err := kemono.GetMultiplePosts(kemonoDl.PostsToDl, dlOptions)
if err != nil {
errSlice = append(errSlice, err...)
} else {
toDownload = append(toDownload, postsToDl...)
gdriveLinks = append(gdriveLinks, gdriveLinksToDl...)
}
}
if len(kemonoDl.CreatorsToDl) > 0 && dlOptions.CtxIsActive() {
creatorsToDl, gdriveLinksToDl, err := kemono.GetMultipleCreators(kemonoDl.CreatorsToDl, dlOptions)
if err != nil {
errSlice = append(errSlice, err...)
} else {
toDownload = append(toDownload, creatorsToDl...)
gdriveLinks = append(gdriveLinks, gdriveLinksToDl...)
}
}
var downloadedPosts bool
if len(toDownload) > 0 && dlOptions.CtxIsActive() {
downloadedPosts = true
cancelled, err := httpfuncs.DownloadUrls(
toDownload,
&httpfuncs.DlOptions{
Context: dlOptions.GetContext(),
MaxConcurrency: constants.KEMONO_MAX_CONCURRENCY,
Cookies: dlOptions.Base.SessionCookies,
UseHttp3: httpfuncs.IsHttp3Supported(constants.KEMONO, false),
SupportRange: constants.KEMONO_RANGE_SUPPORTED,
HeadReqTimeout: constants.KEMONO_HEAD_REQ_TIMEOUT,
RetryDelay: &httpfuncs.RetryDelay{
Min: constants.KEMONO_RETRY_MIN_DELAY,
Max: constants.KEMONO_RETRY_MAX_DELAY,
},
Filters: dlOptions.Base.Filters,
ProgressBarInfo: dlOptions.Base.ProgressBarInfo,
},
dlOptions.Base.Configs,
)
if cancelled {
return nil
}
if err != nil {
errSlice = append(errSlice, err...)
}
}
if dlOptions.Base.GdriveClient != nil && len(gdriveLinks) > 0 && dlOptions.CtxIsActive() {
downloadedPosts = true
err := dlOptions.Base.GdriveClient.DownloadGdriveUrls(
gdriveLinks,
dlOptions.Base.ProgressBarInfo,
dlOptions.Base.Filters,
)
if err != nil {
errSlice = append(errSlice, err...)
}
}
notifier := dlOptions.Base.Notifier
if downloadedPosts {
notifier.Alert("Downloaded all posts from Kemono!")
} else {
notifier.Alert("No posts to download from Kemono!")
}
return errSlice
}