sora: small optimize code

This commit is contained in:
hexated 2023-03-14 01:17:48 +07:00
parent bd636a3fe7
commit 60f54a4ab7
2 changed files with 35 additions and 108 deletions

View file

@ -6,7 +6,6 @@ import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
import com.lagradost.nicehttp.Requests import com.lagradost.nicehttp.Requests
import com.lagradost.nicehttp.Session import com.lagradost.nicehttp.Session
import com.google.gson.JsonParser
import com.hexated.RabbitStream.extractRabbitStream import com.hexated.RabbitStream.extractRabbitStream
import com.lagradost.cloudstream3.extractors.Filesim import com.lagradost.cloudstream3.extractors.Filesim
import com.lagradost.cloudstream3.extractors.StreamSB import com.lagradost.cloudstream3.extractors.StreamSB
@ -242,56 +241,6 @@ object SoraExtractor : SoraStream() {
loadExtractor(url, databaseGdriveAPI, subtitleCallback, callback) loadExtractor(url, databaseGdriveAPI, subtitleCallback, callback)
} }
/* suspend fun invokeSoraVIP(
title: String? = null,
orgTitle: String? = null,
year: Int? = null,
season: Int? = null,
episode: Int? = null,
subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit
) {
val apiUrl = base64DecodeAPI("aQ==YXA=cC8=YXA=bC4=Y2U=ZXI=LnY=b2s=a2w=bG8=Ly8=czo=dHA=aHQ=")
val url = if(season == null) {
"$apiUrl/search/one?title=$title&orgTitle=$orgTitle&year=$year"
} else {
"$apiUrl/search/one?title=$title&orgTitle=$orgTitle&year=$year&season=$season"
}
val id = app.get(url).parsedSafe<DetailVipResult>()?.data?.id
val sourcesUrl = if(season == null) {
"$apiUrl/movie/detail?id=$id"
} else {
"$apiUrl/tv/detail?id=$id&episodeId=${episode?.minus(1)}"
}
val json = app.get(sourcesUrl).parsedSafe<LoadVIPLinks>()
json?.sources?.map { source ->
callback.invoke(
ExtractorLink(
"${this.name} (VIP)",
"${this.name} (VIP)",
source.url ?: return@map null,
"$apiUrl/",
source.quality ?: Qualities.Unknown.value,
isM3u8 = source.url.contains(".m3u8"),
)
)
}
json?.subtitles?.map { sub ->
subtitleCallback.invoke(
SubtitleFile(
getLanguage(sub.language.toString()),
sub.url ?: return@map null
)
)
}
}
*/
suspend fun invokeHDMovieBox( suspend fun invokeHDMovieBox(
title: String? = null, title: String? = null,
season: Int? = null, season: Int? = null,
@ -566,47 +515,43 @@ object SoraExtractor : SoraStream() {
"PHPSESSID" to "${filmxyCookies.phpsessid}" "PHPSESSID" to "${filmxyCookies.phpsessid}"
) )
val request = session.get(url, cookies = cookiesDoc) val doc = session.get(url, cookies = cookiesDoc).document
if (!request.isSuccessful) return val script = doc.selectFirst("script:containsData(var isSingle)")?.data() ?: return
val doc = request.document val sourcesData = Regex("listSE\\s*=\\s?(.*?),[\\n|\\s]").find(script)?.groupValues?.get(1).let {
val script = doc.selectFirst("script:containsData(var isSingle)")?.data().toString() tryParseJson<HashMap<String, HashMap<String, List<String>>>>(it)
val sourcesData = Regex("listSE\\s*=\\s?(.*?),[\\n|\\s]").find(script)?.groupValues?.get(1) }
val sourcesDetail = val sourcesDetail =
Regex("linkDetails\\s*=\\s?(.*?),[\\n|\\s]").find(script)?.groupValues?.get(1) Regex("linkDetails\\s*=\\s?(.*?),[\\n|\\s]").find(script)?.groupValues?.get(1).let {
val subSources = tryParseJson<HashMap<String, HashMap<String, String>>>(it)
Regex("dSubtitles\\s*=\\s?(.*?),[\\n|\\s]").find(script)?.groupValues?.get(1) }
val subSourcesData =
Regex("dSubtitles\\s*=\\s?(.*?),[\\n|\\s]").find(script)?.groupValues?.get(1).let {
tryParseJson<HashMap<String, HashMap<String, HashMap<String, String>>>>(it)
}
//Gson is shit, but i don't care val (seasonSlug, episodeSlug) = getEpisodeSlug(season, episode)
val sourcesJson = JsonParser().parse(sourcesData).asJsonObject
val sourcesDetailJson = JsonParser().parse(sourcesDetail).asJsonObject
val subJson = JsonParser().parse(subSources).asJsonObject
val sources = if (season == null && episode == null) { val sources = if(season == null) {
sourcesJson.getAsJsonObject("movie").getAsJsonArray("movie") sourcesData?.get("movie")?.get("movie")
} else { } else {
val eps = if (episode!! < 10) "0$episode" else episode sourcesData?.get("s$seasonSlug")?.get("e$episodeSlug")
val sson = if (season!! < 10) "0$season" else season }
sourcesJson.getAsJsonObject("s$sson").getAsJsonArray("e$eps") val subSources = if(season == null) {
}.asJsonArray subSourcesData?.get("movie")?.get("movie")
val subSource = if (season == null && episode == null) {
subJson.getAsJsonObject("movie").getAsJsonObject("movie")
} else { } else {
val eps = if (episode!! < 10) "0$episode" else episode subSourcesData?.get("s$seasonSlug")?.get("e$episodeSlug")
val sson = if (season!! < 10) "0$season" else season }
subJson.getAsJsonObject("s$sson").getAsJsonObject("e$eps")
}.asJsonObject
val scriptUser = val scriptUser =
doc.select("script").find { it.data().contains("var userNonce") }?.data().toString() doc.select("script").find { it.data().contains("var userNonce") }?.data() ?: return
val userNonce = val userNonce =
Regex("var\\suserNonce.*?[\"|'](\\S+?)[\"|'];").find(scriptUser)?.groupValues?.get(1) Regex("var\\suserNonce.*?[\"|'](\\S+?)[\"|'];").find(scriptUser)?.groupValues?.get(1)
val userId = val userId =
Regex("var\\suser_id.*?[\"|'](\\S+?)[\"|'];").find(scriptUser)?.groupValues?.get(1) Regex("var\\suser_id.*?[\"|'](\\S+?)[\"|'];").find(scriptUser)?.groupValues?.get(1)
val linkIDs = sources.joinToString("") { val linkIDs = sources?.joinToString("") {
"&linkIDs%5B%5D=$it" "&linkIDs%5B%5D=$it"
}.replace("\"", "") }?.replace("\"", "")
val body = "action=get_vid_links$linkIDs&user_id=$userId&nonce=$userNonce".toRequestBody() val body = "action=get_vid_links$linkIDs&user_id=$userId&nonce=$userNonce".toRequestBody()
val cookiesJson = mapOf( val cookiesJson = mapOf(
@ -627,41 +572,34 @@ object SoraExtractor : SoraStream() {
"X-Requested-With" to "XMLHttpRequest", "X-Requested-With" to "XMLHttpRequest",
), ),
cookies = cookiesJson cookies = cookiesJson
).text.let { JsonParser().parse(it).asJsonObject } ).text.let { tryParseJson<HashMap<String, String>>(it) }
sources.map { source -> sources?.map { source ->
val src = source.asString val link = json?.get(source)
val link = json.getAsJsonPrimitive(src).asString val quality = sourcesDetail?.get(source)?.get("resolution")
val quality = val server = sourcesDetail?.get(source)?.get("server")
sourcesDetailJson.getAsJsonObject(src).getAsJsonPrimitive("resolution").asString val size = sourcesDetail?.get(source)?.get("size")
val server =
sourcesDetailJson.getAsJsonObject(src).getAsJsonPrimitive("server").asString
val size = sourcesDetailJson.getAsJsonObject(src).getAsJsonPrimitive("size").asString
callback.invoke( callback.invoke(
ExtractorLink( ExtractorLink(
"Filmxy",
"Filmxy $size ($server)", "Filmxy $size ($server)",
link, "Filmxy $size ($server)",
link ?: return@map,
"$filmxyAPI/", "$filmxyAPI/",
getQualityFromName(quality) getQualityFromName(quality)
) )
) )
} }
subSource.toString().removeSurrounding("{", "}").split(",").map { subSources?.mapKeys { sub ->
val slug = Regex("\"(\\w+)\":\"(\\d+)\"").find(it)?.groupValues
slug?.getOrNull(1) to slug?.getOrNull(2)
}.map { (lang, id) ->
subtitleCallback.invoke( subtitleCallback.invoke(
SubtitleFile( SubtitleFile(
SubtitleHelper.fromTwoLettersToLanguage(lang ?: "") ?: "$lang", SubtitleHelper.fromTwoLettersToLanguage(sub.key) ?: return@mapKeys,
"https://www.mysubs.org/get-subtitle/$id" "https://www.mysubs.org/get-subtitle/${sub.value}"
) )
) )
} }
} }
suspend fun invokeKimcartoon( suspend fun invokeKimcartoon(
@ -2906,16 +2844,6 @@ data class ResponseHash(
@JsonProperty("type") val type: String?, @JsonProperty("type") val type: String?,
) )
data class Track(
@JsonProperty("file") val file: String? = null,
@JsonProperty("label") val label: String? = null,
)
data class RabbitSources(
@JsonProperty("sources") val sources: String? = null,
@JsonProperty("tracks") val tracks: ArrayList<Track>? = arrayListOf(),
)
data class SubtitlingList( data class SubtitlingList(
@JsonProperty("languageAbbr") val languageAbbr: String? = null, @JsonProperty("languageAbbr") val languageAbbr: String? = null,
@JsonProperty("language") val language: String? = null, @JsonProperty("language") val language: String? = null,

View file

@ -90,7 +90,6 @@ subprojects {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") // html parser implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4") // html parser
//run JS //run JS
implementation("org.mozilla:rhino:1.7.14") implementation("org.mozilla:rhino:1.7.14")
implementation("com.google.code.gson:gson:2.8.9")
} }
} }