Skip to content

Commit

Permalink
feat: Parallelmap moment
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudemirovsky committed Oct 26, 2023
1 parent 20d0ae8 commit fa6bed8
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import eu.kanade.tachiyomi.lib.streamwishextractor.StreamWishExtractor
import eu.kanade.tachiyomi.lib.voeextractor.VoeExtractor
import eu.kanade.tachiyomi.network.GET
import eu.kanade.tachiyomi.util.asJsoup
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.runBlocking
import okhttp3.Request
import okhttp3.Response
import org.jsoup.nodes.Document
Expand Down Expand Up @@ -93,11 +97,11 @@ class ArabSeed : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
override fun videoListSelector() = "div.containerServers ul li"

private fun videosFromElement(document: Document): List<Video> {
return document.select(videoListSelector()).flatMap { element ->
return document.select(videoListSelector()).parallelMap { element ->
val quality = element.text()
val embedUrl = element.attr("data-link")
runCatching { getVideosFromUrl(embedUrl, quality) }.getOrElse { emptyList() }
}
}.flatten()
}

private val doodExtractor by lazy { DoodExtractor(client) }
Expand Down Expand Up @@ -246,6 +250,12 @@ class ArabSeed : ConfigurableAnimeSource, ParsedAnimeHttpSource() {
screen.addPreference(videoQualityPref)
}

// ============================= Utilities ==============================
private inline fun <A, B> Iterable<A>.parallelMap(crossinline f: suspend (A) -> B): List<B> =
runBlocking {
map { async(Dispatchers.Default) { f(it) } }.awaitAll()
}

companion object {
// From egydead(ar)
private const val PREF_DOMAIN_KEY = "default_domain_v${BuildConfig.VERSION_NAME}"
Expand Down

0 comments on commit fa6bed8

Please sign in to comment.