@@ -5,7 +5,7 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
55import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
66import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
77import com.lagradost.cloudstream3.utils.*
8- import kotlinx.coroutines.runBlocking
8+ import kotlinx.coroutines.*
99import org.jsoup.Jsoup
1010import org.jsoup.nodes.Element
1111
@@ -53,26 +53,20 @@ class Animasu : MainAPI() {
5353
5454 override suspend fun getMainPage (page : Int , request : MainPageRequest ): HomePageResponse {
5555 val document = app.get(" $mainUrl /pencarian/?${request.data} &halaman=$page " ).document
56- val home = document.select(" div.listupd div.bs" ).map {
57- it.toSearchResult()
58- }
56+ val home = document.select(" div.listupd div.bs" ).map { it.toSearchResult() }
5957 return newHomePageResponse(request.name, home)
6058 }
6159
6260 private fun getProperAnimeLink (uri : String ): String {
63- return if (uri.contains(" /anime/" )) {
64- uri
65- } else {
61+ return if (uri.contains(" /anime/" )) uri else {
6662 var title = uri.substringAfter(" $mainUrl /" )
6763 title = when {
68- (title.contains(" -episode" )) && ! (title.contains(" -movie" )) -> title.substringBefore(
69- " -episode"
70- )
64+ (title.contains(" -episode" )) && ! (title.contains(" -movie" )) ->
65+ title.substringBefore(" -episode" )
7166
7267 (title.contains(" -movie" )) -> title.substringBefore(" -movie" )
7368 else -> title
7469 }
75-
7670 " $mainUrl /anime/$title "
7771 }
7872 }
@@ -86,34 +80,30 @@ class Animasu : MainAPI() {
8680 this .posterUrl = posterUrl
8781 addSub(epNum)
8882 }
89-
9083 }
9184
9285 override suspend fun search (query : String ): List <SearchResponse > {
93- return app.get(" $mainUrl /?s=$query " ).document.select(" div.listupd div.bs" ).map {
94- it.toSearchResult()
95- }
86+ return app.get(" $mainUrl /?s=$query " ).document
87+ .select(" div.listupd div.bs" ).map { it.toSearchResult() }
9688 }
9789
9890 override suspend fun load (url : String ): LoadResponse {
9991 val document = app.get(url).document
100-
101- val title =
102- document.selectFirst(" div.infox h1" )?.text().toString().replace(" Sub Indo" , " " ).trim()
92+ val title = document.selectFirst(" div.infox h1" )?.text()
93+ .toString().replace(" Sub Indo" , " " ).trim()
10394 val poster = document.selectFirst(" div.bigcontent img" )?.getImageAttr()
10495
10596 val table = document.selectFirst(" div.infox div.spe" )
10697 val type = getType(table?.selectFirst(" span:contains(Jenis:)" )?.ownText())
107- val year =
108- table?.selectFirst(" span:contains(Rilis:)" )?.ownText()?.substringAfterLast(" ," )?.trim()
109- ?.toIntOrNull()
98+ val year = table?.selectFirst(" span:contains(Rilis:)" )?.ownText()
99+ ?.substringAfterLast(" ," )?.trim()?.toIntOrNull()
110100 val status = table?.selectFirst(" span:contains(Status:) font" )?.text()
111101 val trailer = document.selectFirst(" div.trailer iframe" )?.attr(" src" )
112102 val episodes = document.select(" ul#daftarepisode > li" ).map {
113103 val link = fixUrl(it.selectFirst(" a" )!! .attr(" href" ))
114104 val name = it.selectFirst(" a" )?.text() ? : " "
115- val episode =
116- Regex ( " Episode \\ s?( \\ d+) " ).find(name)?. groupValues?.getOrNull(0 )?.toIntOrNull()
105+ val episode = Regex ( " Episode \\ s?( \\ d+) " ).find(name)
106+ ?. groupValues?.getOrNull(1 )?.toIntOrNull()
117107 newEpisode(link) { this .episode = episode }
118108 }.reversed()
119109
@@ -138,16 +128,23 @@ class Animasu : MainAPI() {
138128 isCasting : Boolean ,
139129 subtitleCallback : (SubtitleFile ) -> Unit ,
140130 callback : (ExtractorLink ) -> Unit
141- ): Boolean {
131+ ): Boolean = coroutineScope {
142132 val document = app.get(data).document
143- document.select(" .mobius > .mirror > option" ).mapNotNull {
144- fixUrl(
133+ val mirrors = document.select(" .mobius > .mirror > option" ).mapNotNull {
134+ val iframe = fixUrl(
145135 Jsoup .parse(base64Decode(it.attr(" value" ))).select(" iframe" ).attr(" src" )
146- ) to it.text()
147- }.apmap { (iframe, quality) ->
148- loadFixedExtractor (iframe, quality, " $mainUrl / " , subtitleCallback, callback)
136+ )
137+ val quality = it.text()
138+ if (iframe != null ) iframe to quality else null
149139 }
150- return true
140+
141+ // Modern coroutine-safe parallel mapping
142+ mirrors.map { (iframe, quality) ->
143+ async {
144+ loadFixedExtractor(iframe, quality, " $mainUrl /" , subtitleCallback, callback)
145+ }
146+ }.awaitAll()
147+ true
151148 }
152149
153150 private suspend fun loadFixedExtractor (
@@ -158,28 +155,22 @@ class Animasu : MainAPI() {
158155 callback : (ExtractorLink ) -> Unit
159156 ) {
160157 loadExtractor(url, referer, subtitleCallback) { link ->
161- runBlocking {
162- callback.invoke(
163- newExtractorLink(
164- link.name,
165- link.name,
166- link.url,
167- link.type
168- ) {
169- this .referer = link.referer
170- this .quality = if (link.type == ExtractorLinkType .M3U8 || link.name == " Uservideo" ) link.quality else getIndexQuality(
171- quality
172- )
173- this .headers = link.headers
174- this .extractorData = link.extractorData
175- }
176- )
177- }
158+ callback.invoke(
159+ newExtractorLink(link.name, link.name, link.url, link.type) {
160+ this .referer = link.referer
161+ this .quality =
162+ if (link.type == ExtractorLinkType .M3U8 || link.name == " Uservideo" )
163+ link.quality else getIndexQuality(quality)
164+ this .headers = link.headers
165+ this .extractorData = link.extractorData
166+ }
167+ )
178168 }
179169 }
180170
181171 private fun getIndexQuality (str : String? ): Int {
182- return Regex (" (\\ d{3,4})[pP]" ).find(str ? : " " )?.groupValues?.getOrNull(1 )?.toIntOrNull()
172+ return Regex (" (\\ d{3,4})[pP]" ).find(str ? : " " )
173+ ?.groupValues?.getOrNull(1 )?.toIntOrNull()
183174 ? : Qualities .Unknown .value
184175 }
185176
@@ -191,5 +182,4 @@ class Animasu : MainAPI() {
191182 else -> this .attr(" abs:src" )
192183 }
193184 }
194-
195- }
185+ }
0 commit comments