mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-27 16:26:29 +03:00
fix(Downloader): Don't queue chapters on GlobalScope (#10217)
This fixes auto-download on library update not working on certain cases.
This commit is contained in:
parent
7d173062ca
commit
d466ba2b1d
2 changed files with 27 additions and 43 deletions
|
@ -296,27 +296,22 @@ class AnimeDownloader(
|
||||||
autoStart: Boolean,
|
autoStart: Boolean,
|
||||||
changeDownloader: Boolean = false,
|
changeDownloader: Boolean = false,
|
||||||
video: Video? = null,
|
video: Video? = null,
|
||||||
) = launchIO {
|
) {
|
||||||
if (episodes.isEmpty()) {
|
if (episodes.isEmpty()) return
|
||||||
return@launchIO
|
|
||||||
}
|
|
||||||
|
|
||||||
val source = sourceManager.get(anime.source) as? AnimeHttpSource ?: return@launchIO
|
val source = sourceManager.get(anime.source) as? AnimeHttpSource ?: return
|
||||||
val wasEmpty = queueState.value.isEmpty()
|
val wasEmpty = queueState.value.isEmpty()
|
||||||
// Called in background thread, the operation can be slow with SAF.
|
|
||||||
val episodesWithoutDir =
|
|
||||||
episodes
|
|
||||||
// Filter out those already downloaded.
|
|
||||||
.filter { provider.findEpisodeDir(it.name, it.scanlator, anime.title, source) == null }
|
|
||||||
// Add episodes to queue from the start.
|
|
||||||
.sortedByDescending { it.sourceOrder }
|
|
||||||
|
|
||||||
// Runs in main thread (synchronization needed).
|
val episodesToQueue = episodes.asSequence()
|
||||||
val episodesToQueue = episodesWithoutDir
|
// Filter out those already downloaded.
|
||||||
|
.filter { provider.findEpisodeDir(it.name, it.scanlator, anime.title, source) == null }
|
||||||
|
// Add episodes to queue from the start.
|
||||||
|
.sortedByDescending { it.sourceOrder }
|
||||||
// Filter out those already enqueued.
|
// Filter out those already enqueued.
|
||||||
.filter { episode -> queueState.value.none { it.episode.id == episode.id } }
|
.filter { episode -> queueState.value.none { it.episode.id == episode.id } }
|
||||||
// Create a download for each one.
|
// Create a download for each one.
|
||||||
.map { AnimeDownload(source, anime, it, changeDownloader, video) }
|
.map { AnimeDownload(source, anime, it, changeDownloader, video) }
|
||||||
|
.toList()
|
||||||
|
|
||||||
if (episodesToQueue.isNotEmpty()) {
|
if (episodesToQueue.isNotEmpty()) {
|
||||||
addAllToQueue(episodesToQueue)
|
addAllToQueue(episodesToQueue)
|
||||||
|
@ -335,16 +330,14 @@ class AnimeDownloader(
|
||||||
queuedDownloads > DOWNLOADS_QUEUED_WARNING_THRESHOLD ||
|
queuedDownloads > DOWNLOADS_QUEUED_WARNING_THRESHOLD ||
|
||||||
maxDownloadsFromSource > EPISODES_PER_SOURCE_QUEUE_WARNING_THRESHOLD
|
maxDownloadsFromSource > EPISODES_PER_SOURCE_QUEUE_WARNING_THRESHOLD
|
||||||
) {
|
) {
|
||||||
withUIContext {
|
notifier.onWarning(
|
||||||
notifier.onWarning(
|
context.stringResource(MR.strings.download_queue_size_warning),
|
||||||
context.stringResource(MR.strings.download_queue_size_warning),
|
WARNING_NOTIF_TIMEOUT_MS,
|
||||||
WARNING_NOTIF_TIMEOUT_MS,
|
NotificationHandler.openUrl(
|
||||||
NotificationHandler.openUrl(
|
context,
|
||||||
context,
|
AnimeLibraryUpdateNotifier.HELP_WARNING_URL,
|
||||||
AnimeLibraryUpdateNotifier.HELP_WARNING_URL,
|
),
|
||||||
),
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
AnimeDownloadJob.start(context)
|
AnimeDownloadJob.start(context)
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,6 @@ import tachiyomi.core.storage.extension
|
||||||
import tachiyomi.core.util.lang.launchIO
|
import tachiyomi.core.util.lang.launchIO
|
||||||
import tachiyomi.core.util.lang.launchNow
|
import tachiyomi.core.util.lang.launchNow
|
||||||
import tachiyomi.core.util.lang.withIOContext
|
import tachiyomi.core.util.lang.withIOContext
|
||||||
import tachiyomi.core.util.lang.withUIContext
|
|
||||||
import tachiyomi.core.util.system.ImageUtil
|
import tachiyomi.core.util.system.ImageUtil
|
||||||
import tachiyomi.core.util.system.logcat
|
import tachiyomi.core.util.system.logcat
|
||||||
import tachiyomi.domain.category.manga.interactor.GetMangaCategories
|
import tachiyomi.domain.category.manga.interactor.GetMangaCategories
|
||||||
|
@ -277,24 +276,21 @@ class MangaDownloader(
|
||||||
* @param chapters the list of chapters to download.
|
* @param chapters the list of chapters to download.
|
||||||
* @param autoStart whether to start the downloader after enqueing the chapters.
|
* @param autoStart whether to start the downloader after enqueing the chapters.
|
||||||
*/
|
*/
|
||||||
fun queueChapters(manga: Manga, chapters: List<Chapter>, autoStart: Boolean) = launchIO {
|
fun queueChapters(manga: Manga, chapters: List<Chapter>, autoStart: Boolean) {
|
||||||
if (chapters.isEmpty()) {
|
if (chapters.isEmpty()) return
|
||||||
return@launchIO
|
|
||||||
}
|
|
||||||
|
|
||||||
val source = sourceManager.get(manga.source) as? HttpSource ?: return@launchIO
|
val source = sourceManager.get(manga.source) as? HttpSource ?: return
|
||||||
val wasEmpty = queueState.value.isEmpty()
|
val wasEmpty = queueState.value.isEmpty()
|
||||||
val chaptersWithoutDir = chapters
|
val chaptersToQueue = chapters.asSequence()
|
||||||
// Filter out those already downloaded.
|
// Filter out those already downloaded.
|
||||||
.filter { provider.findChapterDir(it.name, it.scanlator, manga.title, source) == null }
|
.filter { provider.findChapterDir(it.name, it.scanlator, manga.title, source) == null }
|
||||||
// Add chapters to queue from the start.
|
// Add chapters to queue from the start.
|
||||||
.sortedByDescending { it.sourceOrder }
|
.sortedByDescending { it.sourceOrder }
|
||||||
|
|
||||||
val chaptersToQueue = chaptersWithoutDir
|
|
||||||
// Filter out those already enqueued.
|
// Filter out those already enqueued.
|
||||||
.filter { chapter -> queueState.value.none { it.chapter.id == chapter.id } }
|
.filter { chapter -> queueState.value.none { it.chapter.id == chapter.id } }
|
||||||
// Create a download for each one.
|
// Create a download for each one.
|
||||||
.map { MangaDownload(source, manga, it) }
|
.map { MangaDownload(source, manga, it) }
|
||||||
|
.toList()
|
||||||
|
|
||||||
if (chaptersToQueue.isNotEmpty()) {
|
if (chaptersToQueue.isNotEmpty()) {
|
||||||
addAllToQueue(chaptersToQueue)
|
addAllToQueue(chaptersToQueue)
|
||||||
|
@ -311,16 +307,11 @@ class MangaDownloader(
|
||||||
queuedDownloads > DOWNLOADS_QUEUED_WARNING_THRESHOLD ||
|
queuedDownloads > DOWNLOADS_QUEUED_WARNING_THRESHOLD ||
|
||||||
maxDownloadsFromSource > CHAPTERS_PER_SOURCE_QUEUE_WARNING_THRESHOLD
|
maxDownloadsFromSource > CHAPTERS_PER_SOURCE_QUEUE_WARNING_THRESHOLD
|
||||||
) {
|
) {
|
||||||
withUIContext {
|
notifier.onWarning(
|
||||||
notifier.onWarning(
|
context.stringResource(MR.strings.download_queue_size_warning),
|
||||||
context.stringResource(MR.strings.download_queue_size_warning),
|
WARNING_NOTIF_TIMEOUT_MS,
|
||||||
WARNING_NOTIF_TIMEOUT_MS,
|
NotificationHandler.openUrl(context, MangaLibraryUpdateNotifier.HELP_WARNING_URL),
|
||||||
NotificationHandler.openUrl(
|
)
|
||||||
context,
|
|
||||||
MangaLibraryUpdateNotifier.HELP_WARNING_URL,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
MangaDownloadJob.start(context)
|
MangaDownloadJob.start(context)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue