From 1040dd6731f13a2bed5d2c5ad79c9e0dbcf9833d Mon Sep 17 00:00:00 2001 From: Olivia Date: Tue, 30 Jan 2024 23:44:18 +0700 Subject: [PATCH] fix --- .../main/kotlin/com/hexated/SoraExtractor.kt | 57 ++++++++++++------- .../src/main/kotlin/com/hexated/SoraParser.kt | 36 ++++-------- 2 files changed, 45 insertions(+), 48 deletions(-) diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt index e4eabfbf..8b0ef008 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt @@ -2202,26 +2202,38 @@ object SoraExtractor : SoraStream() { subtitleCallback: (SubtitleFile) -> Unit, callback: (ExtractorLink) -> Unit, ) { - val media = - app.get("$cinemaTvAPI/v1/${if (season == null) "movies" else "shows"}?filters[q]=$title") - .parsedSafe()?.items?.find { - it.imdb_id?.removePrefix("tt") - .equals(imdbId?.removePrefix("tt")) || (it.title.equals( - title, - true - ) && it.year == year) - } ?: return - - val mediaId = if (season == null) { - media.id_movie + val id = imdbId?.removePrefix("tt") + val slug = title?.createSlug() + val url = if (season == null) { + "$cinemaTvAPI/movies/play/$id-$slug-$year" } else { - app.get("$cinemaTvAPI/v1/shows?expand=episodes&id=${media.id_show}") - .parsedSafe()?.episodes?.find { it.episode == episode && it.season == season }?.id - } ?: return + "$cinemaTvAPI/shows/play/$id-$slug-$year" + } - val sources = - app.get("$cinemaTvAPI/v1/${if (season == null) "movies" else "episodes"}/view?expand=streams,subtitles&id=$mediaId") - .parsedSafe() + val headers = mapOf( + "x-requested-with" to "XMLHttpRequest", + ) + val doc = app.get(url, headers = headers).document + val script = doc.selectFirst("script:containsData(hash:)")?.data() + val hash = Regex("hash:\\s*['\"](\\S+)['\"]").find(script ?: return)?.groupValues?.get(1) + val expires = Regex("expires:\\s*(\\d+)").find(script)?.groupValues?.get(1) + val episodeId = (if (season == null) { + """id_movie:\s*(\d+)""" + } else { + """episode:\s*['"]$episode['"],[\n\s]+id_episode:\s*(\d+),[\n\s]+season:\s*['"]$season['"]""" + }).let { it.toRegex().find(script)?.groupValues?.get(1) } + + val videoUrl = if (season == null) { + "$cinemaTvAPI/api/v1/security/movie-access?id_movie=$episodeId&hash=$hash&expires=$expires" + } else { + "$cinemaTvAPI/api/v1/security/episode-access?id_episode=$episodeId&hash=$hash&expires=$expires" + } + + val sources = app.get( + videoUrl, + referer = url, + headers = headers + ).parsedSafe() sources?.streams?.mapKeys { source -> callback.invoke( @@ -2229,18 +2241,19 @@ object SoraExtractor : SoraStream() { "CinemaTv", "CinemaTv", source.value, - "", + "$cinemaTvAPI/", getQualityFromName(source.key), true ) ) } - sources?.subtitles?.map { + sources?.subtitles?.map { sub -> + val file = sub.file.toString() subtitleCallback.invoke( SubtitleFile( - it.language ?: return@map, - fixUrl(it.url ?: return@map, cinemaTvAPI) + sub.language ?: return@map, + if (file.startsWith("[")) return@map else fixUrl(file, cinemaTvAPI), ) ) } diff --git a/SoraStream/src/main/kotlin/com/hexated/SoraParser.kt b/SoraStream/src/main/kotlin/com/hexated/SoraParser.kt index b09fa747..c920555a 100644 --- a/SoraStream/src/main/kotlin/com/hexated/SoraParser.kt +++ b/SoraStream/src/main/kotlin/com/hexated/SoraParser.kt @@ -191,32 +191,6 @@ data class JikanResponse( @JsonProperty("data") val data: JikanData? = null, ) -data class CinemaTvResponse( - @JsonProperty("items") val items: ArrayList? = arrayListOf(), - @JsonProperty("episodes") val episodes: ArrayList? = arrayListOf(), - @JsonProperty("streams") val streams: HashMap? = null, - @JsonProperty("subtitles") val subtitles: ArrayList? = arrayListOf(), - ) { - data class Items( - @JsonProperty("id_movie") val id_movie: Int? = null, - @JsonProperty("id_show") val id_show: Int? = null, - @JsonProperty("title") val title: String? = null, - @JsonProperty("year") val year: Int? = null, - @JsonProperty("imdb_id") val imdb_id: String? = null, - ) - - data class Episodes( - @JsonProperty("id") val id: Int? = null, - @JsonProperty("season") val season: Int? = null, - @JsonProperty("episode") val episode: Int? = null, - ) - - data class Subtitles( - @JsonProperty("language") val language: String? = null, - @JsonProperty("url") val url: String? = null, - ) -} - data class VidsrctoResult( @JsonProperty("id") val id: String? = null, @JsonProperty("title") val title: String? = null, @@ -486,4 +460,14 @@ data class AoneroomResponse( ) } } +} + +data class CinemaTvResponse( + @JsonProperty("streams") val streams: HashMap? = null, + @JsonProperty("subtitles") val subtitles: ArrayList? = arrayListOf(), +) { + data class Subtitles( + @JsonProperty("language") val language: String? = null, + @JsonProperty("file") val file: Any? = null, + ) } \ No newline at end of file