mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
Feature/improve automatic chapter downloads (#680)
* Rename "newChapters" to "updatedChapterList" * Do not auto download new chapters of entries with unread chapters Makes it possible to prevent unnecessary chapter downloads in case the entry hasn't yet been caught up * Optionally limit auto new chapter downloads * Prevent downloading new chapters for mangas not in the library
This commit is contained in:
@@ -196,28 +196,48 @@ object Chapter {
|
||||
}
|
||||
}
|
||||
|
||||
downloadNewChapters(mangaId, numberOfCurrentChapters, newChapters)
|
||||
if (manga.inLibrary) {
|
||||
downloadNewChapters(mangaId, numberOfCurrentChapters, newChapters)
|
||||
}
|
||||
|
||||
return chapterList
|
||||
}
|
||||
|
||||
private fun downloadNewChapters(mangaId: Int, prevNumberOfChapters: Int, newChapters: List<ResultRow>) {
|
||||
private fun downloadNewChapters(mangaId: Int, prevNumberOfChapters: Int, updatedChapterList: List<ResultRow>) {
|
||||
// convert numbers to be index based
|
||||
val currentNumberOfChapters = (prevNumberOfChapters - 1).coerceAtLeast(0)
|
||||
val updatedNumberOfChapters = (newChapters.size - 1).coerceAtLeast(0)
|
||||
val updatedNumberOfChapters = (updatedChapterList.size - 1).coerceAtLeast(0)
|
||||
val numberOfNewChapters = updatedNumberOfChapters - currentNumberOfChapters
|
||||
|
||||
val areNewChaptersAvailable = currentNumberOfChapters < updatedNumberOfChapters
|
||||
val areNewChaptersAvailable = numberOfNewChapters > 0
|
||||
val wasInitialFetch = currentNumberOfChapters == 0
|
||||
|
||||
// make sure to ignore initial fetch
|
||||
val downloadNewChapters = serverConfig.autoDownloadNewChapters.value && !wasInitialFetch && areNewChaptersAvailable
|
||||
if (!downloadNewChapters) {
|
||||
val isDownloadPossible =
|
||||
serverConfig.autoDownloadNewChapters.value && areNewChaptersAvailable && !wasInitialFetch
|
||||
if (!isDownloadPossible) {
|
||||
return
|
||||
}
|
||||
|
||||
val numberOfNewChapters = updatedNumberOfChapters - currentNumberOfChapters
|
||||
val chapterIdsToDownload = newChapters.subList(0, numberOfNewChapters)
|
||||
.filter { !it[ChapterTable.isRead] && !it[ChapterTable.isDownloaded] }.map { it[ChapterTable.id].value }
|
||||
val newChapters = updatedChapterList.subList(0, numberOfNewChapters)
|
||||
|
||||
// make sure to only consider the latest chapters. e.g. old unread chapters should be ignored
|
||||
val latestReadChapterIndex =
|
||||
updatedChapterList.indexOfFirst { it[ChapterTable.isRead] }.takeIf { it > -1 } ?: return
|
||||
val unreadChapters = updatedChapterList.subList(numberOfNewChapters, latestReadChapterIndex)
|
||||
.filter { !it[ChapterTable.isRead] }
|
||||
|
||||
val skipDueToUnreadChapters = serverConfig.excludeEntryWithUnreadChapters.value && unreadChapters.isNotEmpty()
|
||||
if (skipDueToUnreadChapters) {
|
||||
return
|
||||
}
|
||||
|
||||
val firstChapterToDownloadIndex =
|
||||
(numberOfNewChapters - serverConfig.autoDownloadAheadLimit.value).coerceAtLeast(0)
|
||||
|
||||
val chapterIdsToDownload = newChapters.subList(firstChapterToDownloadIndex, numberOfNewChapters)
|
||||
.filter { !it[ChapterTable.isRead] && !it[ChapterTable.isDownloaded] }
|
||||
.map { it[ChapterTable.id].value }
|
||||
|
||||
if (chapterIdsToDownload.isEmpty()) {
|
||||
return
|
||||
|
||||
@@ -73,6 +73,8 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF
|
||||
val downloadAsCbz: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||
val downloadsPath: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
|
||||
val autoDownloadNewChapters: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||
val excludeEntryWithUnreadChapters: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||
val autoDownloadAheadLimit: MutableStateFlow<Int> by OverrideConfigValue(IntConfigAdapter)
|
||||
|
||||
// requests
|
||||
val maxSourcesInParallel: MutableStateFlow<Int> by OverrideConfigValue(IntConfigAdapter)
|
||||
|
||||
@@ -20,6 +20,8 @@ server.webUIUpdateCheckInterval = 23 # time in hours - 0 to disable auto update
|
||||
server.downloadAsCbz = false
|
||||
server.downloadsPath = ""
|
||||
server.autoDownloadNewChapters = false # if new chapters that have been retrieved should get automatically downloaded
|
||||
server.excludeEntryWithUnreadChapters = true # ignore automatic chapter downloads of entries with unread chapters
|
||||
server.autoDownloadAheadLimit = 5 # 0 to disable it - how many unread downloaded chapters should be available - if the limit is reached, new chapters won't be downloaded automatically
|
||||
|
||||
# requests
|
||||
server.maxSourcesInParallel = 6 # range: 1 <= n <= 20 - default: 6 - sets how many sources can do requests (updates, downloads) in parallel. updates/downloads are grouped by source and all mangas of a source are updated/downloaded synchronously
|
||||
|
||||
@@ -10,6 +10,8 @@ server.socksProxyPort = ""
|
||||
# downloader
|
||||
server.downloadAsCbz = false
|
||||
server.autoDownloadNewChapters = false
|
||||
server.excludeEntryWithUnreadChapters = true
|
||||
server.autoDownloadAheadLimit = 5
|
||||
|
||||
# requests
|
||||
server.maxSourcesInParallel = 10
|
||||
|
||||
Reference in New Issue
Block a user