From ad1979505e2434ae1fc2e6bf20ba2c233229f8b1 Mon Sep 17 00:00:00 2001 From: Finnley Somdahl <87634197+rebelonion@users.noreply.github.com> Date: Sat, 13 Jan 2024 00:24:14 -0600 Subject: [PATCH] ok an actual fix this time --- .../java/ani/dantotsu/parsers/AniyomiAdapter.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt b/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt index 08c69b5560..fe4c0daee6 100644 --- a/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt +++ b/app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt @@ -41,6 +41,8 @@ import kotlinx.coroutines.awaitAll import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.sync.Semaphore +import kotlinx.coroutines.sync.withPermit import kotlinx.coroutines.withContext import okhttp3.Request import uy.kohesive.injekt.Injekt @@ -315,7 +317,6 @@ class DynamicMangaParser(extension: MangaExtension.Installed) : MangaParser() { } return ret } - suspend fun imageList(chapterLink: String, sChapter: SChapter): List { val source = try { extension.sources[sourceLanguage] @@ -323,29 +324,29 @@ class DynamicMangaParser(extension: MangaExtension.Installed) : MangaParser() { sourceLanguage = 0 extension.sources[sourceLanguage] } as? HttpSource ?: return emptyList() - var imageDataList: List = listOf() - coroutineScope { + + return coroutineScope { try { println("source.name " + source.name) val res = source.getPageList(sChapter) - val reIndexedPages = - res.mapIndexed { index, page -> Page(index, page.url, page.imageUrl, page.uri) } + val reIndexedPages = res.mapIndexed { index, page -> Page(index, page.url, page.imageUrl, page.uri) } + val semaphore = Semaphore(5) val deferreds = reIndexedPages.map { page -> async(Dispatchers.IO) { - imageDataList += ImageData(page, source) + semaphore.withPermit { + ImageData(page, source) + } } } deferreds.awaitAll() - } catch (e: Exception) { logger("loadImages Exception: $e") snackString("Failed to load images: $e") emptyList() } } - return imageDataList } suspend fun fetchAndProcessImage(