Skip to content

Commit 9ee723c

Browse files
Try to fix
1 parent 2e41147 commit 9ee723c

1 file changed

Lines changed: 61 additions & 47 deletions

File tree

Animasu/src/main/kotlin/com/hexated/Animasu.kt

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.lagradost.cloudstream3.LoadResponse.Companion.addAniListId
55
import com.lagradost.cloudstream3.LoadResponse.Companion.addMalId
66
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
77
import com.lagradost.cloudstream3.utils.*
8-
import kotlinx.coroutines.*
8+
import kotlinx.coroutines.runBlocking
99
import org.jsoup.Jsoup
1010
import org.jsoup.nodes.Element
1111

@@ -53,20 +53,26 @@ 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 { it.toSearchResult() }
56+
val home = document.select("div.listupd div.bs").map {
57+
it.toSearchResult()
58+
}
5759
return newHomePageResponse(request.name, home)
5860
}
5961

6062
private fun getProperAnimeLink(uri: String): String {
61-
return if (uri.contains("/anime/")) uri else {
63+
return if (uri.contains("/anime/")) {
64+
uri
65+
} else {
6266
var title = uri.substringAfter("$mainUrl/")
6367
title = when {
64-
(title.contains("-episode")) && !(title.contains("-movie")) ->
65-
title.substringBefore("-episode")
68+
(title.contains("-episode")) && !(title.contains("-movie")) -> title.substringBefore(
69+
"-episode"
70+
)
6671

6772
(title.contains("-movie")) -> title.substringBefore("-movie")
6873
else -> title
6974
}
75+
7076
"$mainUrl/anime/$title"
7177
}
7278
}
@@ -80,30 +86,34 @@ class Animasu : MainAPI() {
8086
this.posterUrl = posterUrl
8187
addSub(epNum)
8288
}
89+
8390
}
8491

8592
override suspend fun search(query: String): List<SearchResponse> {
86-
return app.get("$mainUrl/?s=$query").document
87-
.select("div.listupd div.bs").map { it.toSearchResult() }
93+
return app.get("$mainUrl/?s=$query").document.select("div.listupd div.bs").map {
94+
it.toSearchResult()
95+
}
8896
}
8997

9098
override suspend fun load(url: String): LoadResponse {
9199
val document = app.get(url).document
92-
val title = document.selectFirst("div.infox h1")?.text()
93-
.toString().replace("Sub Indo", "").trim()
100+
101+
val title =
102+
document.selectFirst("div.infox h1")?.text().toString().replace("Sub Indo", "").trim()
94103
val poster = document.selectFirst("div.bigcontent img")?.getImageAttr()
95104

96105
val table = document.selectFirst("div.infox div.spe")
97106
val type = getType(table?.selectFirst("span:contains(Jenis:)")?.ownText())
98-
val year = table?.selectFirst("span:contains(Rilis:)")?.ownText()
99-
?.substringAfterLast(",")?.trim()?.toIntOrNull()
107+
val year =
108+
table?.selectFirst("span:contains(Rilis:)")?.ownText()?.substringAfterLast(",")?.trim()
109+
?.toIntOrNull()
100110
val status = table?.selectFirst("span:contains(Status:) font")?.text()
101111
val trailer = document.selectFirst("div.trailer iframe")?.attr("src")
102112
val episodes = document.select("ul#daftarepisode > li").map {
103113
val link = fixUrl(it.selectFirst("a")!!.attr("href"))
104114
val name = it.selectFirst("a")?.text() ?: ""
105-
val episode = Regex("Episode\\s?(\\d+)").find(name)
106-
?.groupValues?.getOrNull(1)?.toIntOrNull()
115+
val episode =
116+
Regex("Episode\\s?(\\d+)").find(name)?.groupValues?.getOrNull(0)?.toIntOrNull()
107117
newEpisode(link) { this.episode = episode }
108118
}.reversed()
109119

@@ -123,54 +133,57 @@ class Animasu : MainAPI() {
123133
}
124134
}
125135

126-
override suspend fun loadLinks(
136+
override suspend fun loadLinks(
127137
data: String,
128138
isCasting: Boolean,
129139
subtitleCallback: (SubtitleFile) -> Unit,
130140
callback: (ExtractorLink) -> Unit
131-
): Boolean = coroutineScope {
141+
): Boolean {
132142
val document = app.get(data).document
133143
val mirrors = document.select(".mobius > .mirror > option").mapNotNull {
134-
val iframe = fixUrl(
135-
Jsoup.parse(base64Decode(it.attr("value"))).select("iframe").attr("src")
136-
)
137-
val quality = it.text()
138-
if (iframe != null) iframe to quality else null
139-
}
144+
fixUrl(
145+
Jsoup.parse(base64Decode(it.attr("value"))).select("iframe").attr("src")
146+
) to it.text()
147+
}
140148

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
149+
for ((iframe, quality) in mirrors) {
150+
loadFixedExtractor(iframe, quality, "$mainUrl/", subtitleCallback, callback)
151+
}
152+
return true
148153
}
149154

150155
private suspend fun loadFixedExtractor(
151-
url: String,
152-
quality: String?,
153-
referer: String? = null,
154-
subtitleCallback: (SubtitleFile) -> Unit,
155-
callback: (ExtractorLink) -> Unit
156-
) {
157-
loadExtractor(url, referer, subtitleCallback) { link ->
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-
)
156+
url: String,
157+
quality: String?,
158+
referer: String? = null,
159+
subtitleCallback: (SubtitleFile) -> Unit,
160+
callback: (ExtractorLink) -> Unit
161+
) {
162+
loadExtractor(url, referer, subtitleCallback) { link ->
163+
runBlocking {
164+
callback.invoke(
165+
newExtractorLink(
166+
link.name,
167+
link.name,
168+
link.url,
169+
link.type
170+
) {
171+
this.referer = link.referer
172+
this.quality = if (
173+
link.type == ExtractorLinkType.M3U8 || link.name == "Uservideo"
174+
) link.quality else getIndexQuality(quality)
175+
176+
this.headers = link.headers
177+
this.extractorData = link.extractorData
178+
}
179+
)
168180
}
169181
}
182+
}
183+
170184

171185
private fun getIndexQuality(str: String?): Int {
172-
return Regex("(\\d{3,4})[pP]").find(str ?: "")
173-
?.groupValues?.getOrNull(1)?.toIntOrNull()
186+
return Regex("(\\d{3,4})[pP]").find(str ?: "")?.groupValues?.getOrNull(1)?.toIntOrNull()
174187
?: Qualities.Unknown.value
175188
}
176189

@@ -182,4 +195,5 @@ class Animasu : MainAPI() {
182195
else -> this.attr("abs:src")
183196
}
184197
}
198+
185199
}

0 commit comments

Comments
 (0)