mirror of
https://github.com/Suwayomi/Suwayomi-Server.git
synced 2026-07-03 10:54:38 -05: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
|
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
|
// convert numbers to be index based
|
||||||
val currentNumberOfChapters = (prevNumberOfChapters - 1).coerceAtLeast(0)
|
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
|
val wasInitialFetch = currentNumberOfChapters == 0
|
||||||
|
|
||||||
// make sure to ignore initial fetch
|
// make sure to ignore initial fetch
|
||||||
val downloadNewChapters = serverConfig.autoDownloadNewChapters.value && !wasInitialFetch && areNewChaptersAvailable
|
val isDownloadPossible =
|
||||||
if (!downloadNewChapters) {
|
serverConfig.autoDownloadNewChapters.value && areNewChaptersAvailable && !wasInitialFetch
|
||||||
|
if (!isDownloadPossible) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
val numberOfNewChapters = updatedNumberOfChapters - currentNumberOfChapters
|
val newChapters = updatedChapterList.subList(0, numberOfNewChapters)
|
||||||
val chapterIdsToDownload = newChapters.subList(0, numberOfNewChapters)
|
|
||||||
.filter { !it[ChapterTable.isRead] && !it[ChapterTable.isDownloaded] }.map { it[ChapterTable.id].value }
|
// 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()) {
|
if (chapterIdsToDownload.isEmpty()) {
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ class ServerConfig(getConfig: () -> Config, val moduleName: String = SERVER_CONF
|
|||||||
val downloadAsCbz: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
val downloadAsCbz: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||||
val downloadsPath: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
|
val downloadsPath: MutableStateFlow<String> by OverrideConfigValue(StringConfigAdapter)
|
||||||
val autoDownloadNewChapters: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
val autoDownloadNewChapters: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||||
|
val excludeEntryWithUnreadChapters: MutableStateFlow<Boolean> by OverrideConfigValue(BooleanConfigAdapter)
|
||||||
|
val autoDownloadAheadLimit: MutableStateFlow<Int> by OverrideConfigValue(IntConfigAdapter)
|
||||||
|
|
||||||
// requests
|
// requests
|
||||||
val maxSourcesInParallel: MutableStateFlow<Int> by OverrideConfigValue(IntConfigAdapter)
|
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.downloadAsCbz = false
|
||||||
server.downloadsPath = ""
|
server.downloadsPath = ""
|
||||||
server.autoDownloadNewChapters = false # if new chapters that have been retrieved should get automatically downloaded
|
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
|
# 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
|
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
|
# downloader
|
||||||
server.downloadAsCbz = false
|
server.downloadAsCbz = false
|
||||||
server.autoDownloadNewChapters = false
|
server.autoDownloadNewChapters = false
|
||||||
|
server.excludeEntryWithUnreadChapters = true
|
||||||
|
server.autoDownloadAheadLimit = 5
|
||||||
|
|
||||||
# requests
|
# requests
|
||||||
server.maxSourcesInParallel = 10
|
server.maxSourcesInParallel = 10
|
||||||
|
|||||||
Reference in New Issue
Block a user