@@ -4,14 +4,11 @@ import com.lagradost.cloudstream3.*
44import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
55import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
66import com.lagradost.cloudstream3.mvvm.safeApiCall
7- import com.lagradost.cloudstream3.utils.ExtractorLink
8- import com.lagradost.cloudstream3.utils.ExtractorLinkType
9- import com.lagradost.cloudstream3.utils.INFER_TYPE
10- import com.lagradost.cloudstream3.utils.Qualities
11- import com.lagradost.cloudstream3.utils.loadExtractor
12- import com.lagradost.cloudstream3.utils.newExtractorLink
7+ import com.lagradost.cloudstream3.utils.*
138import com.lagradost.nicehttp.NiceResponse
14- import kotlinx.coroutines.runBlocking
9+ import kotlinx.coroutines.async
10+ import kotlinx.coroutines.awaitAll
11+ import kotlinx.coroutines.coroutineScope
1512import org.jsoup.Jsoup
1613import org.jsoup.nodes.Element
1714
@@ -96,7 +93,6 @@ class AnimeSailProvider : MainAPI() {
9693 this .posterUrl = posterUrl
9794 addSub(epNum)
9895 }
99-
10096 }
10197
10298 override suspend fun search (query : String ): List <SearchResponse > {
@@ -147,28 +143,30 @@ class AnimeSailProvider : MainAPI() {
147143 isCasting : Boolean ,
148144 subtitleCallback : (SubtitleFile ) -> Unit ,
149145 callback : (ExtractorLink ) -> Unit
150- ): Boolean {
146+ ): Boolean = coroutineScope {
151147
152148 val document = request(data).document
149+ val options = document.select(" .mobius > .mirror > option" )
153150
154- document.select(" .mobius > .mirror > option" ).apmap {
155- safeApiCall {
156- val iframe = fixUrl(
157- Jsoup .parse(base64Decode(it.attr(" data-em" ))).select(" iframe" ).attr(" src" )
158- ? : throw ErrorLoadingException (" No iframe found" )
159- )
160- val quality = getIndexQuality(it.text())
161- when {
162- iframe.startsWith(" $mainUrl /utils/player/kodir2" ) -> request(
163- iframe,
164- ref = data
165- ).text.substringAfter(" = `" ).substringBefore(" `;" )
166- .let {
151+ // FIXED: replace apmap with coroutineScope async + awaitAll
152+ options.map { option ->
153+ async {
154+ safeApiCall {
155+ val iframe = fixUrl(
156+ Jsoup .parse(base64Decode(option.attr(" data-em" ))).select(" iframe" )
157+ .attr(" src" ) ? : throw ErrorLoadingException (" No iframe found" )
158+ )
159+ val quality = getIndexQuality(option.text())
160+
161+ when {
162+ iframe.startsWith(" $mainUrl /utils/player/kodir2" ) -> request(
163+ iframe, ref = data
164+ ).text.substringAfter(" = `" ).substringBefore(" `;" ).let {
167165 val link = Jsoup .parse(it).select(" source" ).last()?.attr(" src" )
168166 callback.invoke(
169167 newExtractorLink(
170- source = this . name,
171- name = this . name,
168+ source = name,
169+ name = name,
172170 url = link ? : return @let,
173171 INFER_TYPE
174172 ) {
@@ -178,19 +176,19 @@ class AnimeSailProvider : MainAPI() {
178176 )
179177 }
180178
181- iframe.startsWith( " $mainUrl /utils/player/arch/ " ) || iframe.startsWith(" $mainUrl /utils/player/race /" ) || iframe.startsWith(
182- " $mainUrl /utils/player/hexupload/ "
183- ) || iframe.startsWith(" $mainUrl /utils/player/pomf /" )
184- -> request(iframe, ref = data).document.select( " source " ).attr( " src " )
185- . let { link ->
186- val source =
187- when {
188- iframe.contains(" /arch/" ) -> " Arch"
189- iframe.contains(" /race/" ) -> " Race"
190- iframe.contains(" /hexupload/" ) -> " Hexupload"
191- iframe.contains(" /pomf/" ) -> " Pomf"
192- else -> this . name
193- }
179+ iframe.startsWith(" $mainUrl /utils/player/arch /" ) ||
180+ iframe.startsWith( " $mainUrl /utils/player/race/ " ) ||
181+ iframe.startsWith(" $mainUrl /utils/player/hexupload /" ) ||
182+ iframe.startsWith( " $mainUrl /utils/player/pomf/ " ) -> request(
183+ iframe, ref = data
184+ ).document.select( " source " ).attr( " src " ). let { link ->
185+ val source = when {
186+ iframe.contains(" /arch/" ) -> " Arch"
187+ iframe.contains(" /race/" ) -> " Race"
188+ iframe.contains(" /hexupload/" ) -> " Hexupload"
189+ iframe.contains(" /pomf/" ) -> " Pomf"
190+ else -> name
191+ }
194192 callback.invoke(
195193 newExtractorLink(
196194 source = source,
@@ -203,19 +201,17 @@ class AnimeSailProvider : MainAPI() {
203201 }
204202 )
205203 }
206- // skip for now
207- // iframe.startsWith("$mainUrl/utils/player/fichan/") -> ""
208- // iframe.startsWith("$mainUrl/utils/player/blogger/") -> ""
209- iframe.startsWith(" https://aghanim.xyz/tools/redirect/" ) -> {
210- val link = " https://rasa-cintaku-semakin-berantai.xyz/v/${
211- iframe.substringAfter(" id=" ).substringBefore(" &token" )
212- } "
213- loadFixedExtractor(link, quality, mainUrl, subtitleCallback, callback)
214- }
215204
216- iframe.startsWith(" $mainUrl /utils/player/framezilla/" ) || iframe.startsWith(" https://uservideo.xyz" ) -> {
217- request(iframe, ref = data).document.select(" iframe" ).attr(" src" )
218- .let { link ->
205+ iframe.startsWith(" https://aghanim.xyz/tools/redirect/" ) -> {
206+ val link = " https://rasa-cintaku-semakin-berantai.xyz/v/${
207+ iframe.substringAfter(" id=" ).substringBefore(" &token" )
208+ } "
209+ loadFixedExtractor(link, quality, mainUrl, subtitleCallback, callback)
210+ }
211+
212+ iframe.startsWith(" $mainUrl /utils/player/framezilla/" ) ||
213+ iframe.startsWith(" https://uservideo.xyz" ) -> {
214+ request(iframe, ref = data).document.select(" iframe" ).attr(" src" ).let { link ->
219215 loadFixedExtractor(
220216 fixUrl(link),
221217 quality,
@@ -224,16 +220,17 @@ class AnimeSailProvider : MainAPI() {
224220 callback
225221 )
226222 }
227- }
223+ }
228224
229- else -> {
230- loadFixedExtractor(iframe, quality, mainUrl, subtitleCallback, callback)
225+ else -> {
226+ loadFixedExtractor(iframe, quality, mainUrl, subtitleCallback, callback)
227+ }
231228 }
232229 }
233230 }
234- }
231+ }.awaitAll()
235232
236- return true
233+ true
237234 }
238235
239236 private suspend fun loadFixedExtractor (
@@ -244,29 +241,26 @@ class AnimeSailProvider : MainAPI() {
244241 callback : (ExtractorLink ) -> Unit
245242 ) {
246243 loadExtractor(url, referer, subtitleCallback) { link ->
247- runBlocking {
248- callback.invoke(
249- newExtractorLink(
250- source = link.name,
251- name = link.name,
252- url = link.url,
253- INFER_TYPE
254- ) {
255- this .referer = mainUrl
256- this .quality = if (link.type == ExtractorLinkType .M3U8 ) link.quality else quality
257- ? : Qualities .Unknown .value
258- this .type = link.type
259- this .headers = link.headers
260- this .extractorData = link.extractorData
261- }
262- )
263- }
244+ callback.invoke(
245+ newExtractorLink(
246+ source = link.name,
247+ name = link.name,
248+ url = link.url,
249+ INFER_TYPE
250+ ) {
251+ this .referer = mainUrl
252+ this .quality = if (link.type == ExtractorLinkType .M3U8 ) link.quality
253+ else quality ? : Qualities .Unknown .value
254+ this .type = link.type
255+ this .headers = link.headers
256+ this .extractorData = link.extractorData
257+ }
258+ )
264259 }
265260 }
266261
267262 private fun getIndexQuality (str : String ): Int {
268263 return Regex (" (\\ d{3,4})[pP]" ).find(str)?.groupValues?.getOrNull(1 )?.toIntOrNull()
269264 ? : Qualities .Unknown .value
270265 }
271-
272266}
0 commit comments