Skip to content

Commit

Permalink
ok an actual fix this time
Browse files Browse the repository at this point in the history
  • Loading branch information
rebelonion committed Jan 13, 2024
1 parent 310f068 commit ad19795
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions app/src/main/java/ani/dantotsu/parsers/AniyomiAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -315,37 +317,36 @@ class DynamicMangaParser(extension: MangaExtension.Installed) : MangaParser() {
}
return ret
}

suspend fun imageList(chapterLink: String, sChapter: SChapter): List<ImageData> {
val source = try {
extension.sources[sourceLanguage]
} catch (e: Exception) {
sourceLanguage = 0
extension.sources[sourceLanguage]
} as? HttpSource ?: return emptyList()
var imageDataList: List<ImageData> = 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(
Expand Down

0 comments on commit ad19795

Please sign in to comment.