@@ -11,7 +11,9 @@ import com.lagradost.cloudstream3.utils.ExtractorLink
1111import com.lagradost.cloudstream3.utils.Qualities
1212import com.lagradost.cloudstream3.utils.loadExtractor
1313import com.lagradost.cloudstream3.utils.newExtractorLink
14- import kotlinx.coroutines.runBlocking
14+ import kotlinx.coroutines.async
15+ import kotlinx.coroutines.awaitAll
16+ import kotlinx.coroutines.coroutineScope
1517import org.jsoup.Jsoup
1618import org.jsoup.nodes.Element
1719
@@ -77,7 +79,6 @@ class OtakudesuProvider : MainAPI() {
7779 this .posterUrl = posterUrl
7880 addSub(epNum)
7981 }
80-
8182 }
8283
8384 override suspend fun search (query : String ): List <SearchResponse > {
@@ -92,7 +93,6 @@ class OtakudesuProvider : MainAPI() {
9293 }
9394 }
9495
95-
9696 override suspend fun load (url : String ): LoadResponse {
9797 val document = app.get(url).document
9898
@@ -150,7 +150,6 @@ class OtakudesuProvider : MainAPI() {
150150 }
151151 }
152152
153-
154153 data class ResponseSources (
155154 @JsonProperty(" id" ) val id : String ,
156155 @JsonProperty(" i" ) val i : String ,
@@ -166,12 +165,13 @@ class OtakudesuProvider : MainAPI() {
166165 isCasting : Boolean ,
167166 subtitleCallback : (SubtitleFile ) -> Unit ,
168167 callback : (ExtractorLink ) -> Unit
169- ): Boolean {
168+ ): Boolean = coroutineScope {
170169
171170 val document = app.get(data).document
172171
173- argamap(
174- {
172+ // Gunakan coroutineScope + async untuk menggantikan argamap
173+ val jobs = listOf (
174+ async {
175175 val scriptData =
176176 document.select(" script:containsData(action:)" ).lastOrNull()?.data()
177177 val token =
@@ -187,51 +187,57 @@ class OtakudesuProvider : MainAPI() {
187187 base64Decode(it.select(" a" ).attr(" data-content" ))
188188 }.toString()
189189
190- tryParseJson<List <ResponseSources >>(mirrorData)?.apmap { res ->
191- val id = res.id
192- val i = res.i
193- val q = res.q
194-
195- val sources = Jsoup .parse(
196- base64Decode(
197- app.post(
198- " ${mainUrl} /wp-admin/admin-ajax.php" , data = mapOf (
199- " id" to id,
200- " i" to i,
201- " q" to q,
202- " nonce" to nonce,
203- " action" to action
204- )
205- ).parsed<ResponseData >().data
206- )
207- ).select(" iframe" ).attr(" src" )
208-
209- loadCustomExtractor(sources, data, subtitleCallback, callback, getQuality(q))
210-
211- }
190+ tryParseJson<List <ResponseSources >>(mirrorData)?.map { res ->
191+ async {
192+ val id = res.id
193+ val i = res.i
194+ val q = res.q
195+
196+ val sources = Jsoup .parse(
197+ base64Decode(
198+ app.post(
199+ " ${mainUrl} /wp-admin/admin-ajax.php" , data = mapOf (
200+ " id" to id,
201+ " i" to i,
202+ " q" to q,
203+ " nonce" to nonce,
204+ " action" to action
205+ )
206+ ).parsed<ResponseData >().data
207+ )
208+ ).select(" iframe" ).attr(" src" )
209+
210+ loadCustomExtractor(sources, data, subtitleCallback, callback, getQuality(q))
211+ }
212+ }?.awaitAll()
212213 },
213- {
214+ async {
214215 document.select(" div.download li" ).map { ele ->
215- val quality = getQuality(ele.select(" strong" ).text())
216- ele.select(" a" ).map {
217- it.attr(" href" ) to it.text()
218- }.filter {
219- ! inBlacklist(it.first) && quality != Qualities .P360 .value
220- }.apmap {
221- val link = app.get(it.first, referer = " $mainUrl /" ).url
222- loadCustomExtractor(
223- fixedIframe(link),
224- data,
225- subtitleCallback,
226- callback,
227- quality
228- )
216+ async {
217+ val quality = getQuality(ele.select(" strong" ).text())
218+ ele.select(" a" ).map {
219+ it.attr(" href" ) to it.text()
220+ }.filter {
221+ ! inBlacklist(it.first) && quality != Qualities .P360 .value
222+ }.map { pair ->
223+ async {
224+ val link = app.get(pair.first, referer = " $mainUrl /" ).url
225+ loadCustomExtractor(
226+ fixedIframe(link),
227+ data,
228+ subtitleCallback,
229+ callback,
230+ quality
231+ )
232+ }
233+ }.awaitAll()
229234 }
230- }
235+ }.awaitAll()
231236 }
232237 )
233238
234- return true
239+ jobs.awaitAll()
240+ true
235241 }
236242
237243 private suspend fun loadCustomExtractor (
@@ -242,21 +248,20 @@ class OtakudesuProvider : MainAPI() {
242248 quality : Int = Qualities .Unknown .value,
243249 ) {
244250 loadExtractor(url, referer, subtitleCallback) { link ->
245- runBlocking {
246- callback.invoke(
247- newExtractorLink(
248- link.name,
249- link.name,
250- link.url,
251- link.type
252- ) {
253- this .referer = link.referer
254- this .quality = quality
255- this .headers = link.headers
256- this .extractorData = link.extractorData
257- }
258- )
259- }
251+ // langsung panggil callback, tidak perlu runBlocking
252+ callback.invoke(
253+ newExtractorLink(
254+ link.name,
255+ link.name,
256+ link.url,
257+ link.type
258+ ) {
259+ this .referer = link.referer
260+ this .quality = quality
261+ this .headers = link.headers
262+ this .extractorData = link.extractorData
263+ }
264+ )
260265 }
261266 }
262267
0 commit comments