small fix

This commit is contained in:
hexated 2023-03-11 07:52:21 +07:00
parent 491298857c
commit ec7c2a1be7
2 changed files with 26 additions and 9 deletions

View file

@ -2738,19 +2738,34 @@ object SoraExtractor : SoraStream() {
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit,
) {
val slug = title.createSlug()
val url = if (season == null) {
"$ask4MoviesAPI/$slug-$year"
val query = if (season == null) {
title
} else {
"$ask4MoviesAPI/$slug-season-$season"
"$title season $season"
}
val mediaData =
app.get("$ask4MoviesAPI/?s=$query").document.select("div#search-content div.item").map {
it.selectFirst("div.main-item a")
}
val doc = app.get(url).document
val iframe = if(season == null) {
doc.select("div#player-embed iframe").attr("data-src")
val media = if (mediaData.size == 1) {
mediaData.firstOrNull()
} else {
doc.select("ul.group-links-list li:nth-child($episode) a").attr("data-embed-src")
mediaData.find {
if (season == null) {
it?.text().equals("$title ($year)", true)
} else {
it?.text().equals("$title (Season $season)", true)
}
}
}
val epsDoc = app.get(media?.attr("href") ?: return).document
val iframe = if (season == null) {
epsDoc.select("div#player-embed iframe").attr("data-src")
} else {
epsDoc.select("ul.group-links-list li:nth-child($episode) a").attr("data-embed-src")
}
loadExtractor(iframe, ask4MoviesAPI, subtitleCallback, callback)

View file

@ -898,7 +898,9 @@ fun Headers.getGomoviesCookies(cookieKey: String = "set-cookie"): Map<String, St
}
fun String?.createSlug(): String? {
return this?.replace(Regex("[!%:'?,]|( &)"), "")?.replace(Regex("( )|( -)|(- )"), "-")
return this?.replace(Regex("[^\\w\\s]"), "")
?.replace(Regex("( )|( -)|(- )"), "-")
?.replace("--", "-")
?.replace(" ", "-")?.lowercase()
}