Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
olivia committed Jan 30, 2024
1 parent e368193 commit 1040dd6
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 47 deletions.
55 changes: 34 additions & 21 deletions SoraStream/src/main/kotlin/com/hexated/SoraExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2202,45 +2202,58 @@ 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<CinemaTvResponse>()?.items?.find {
it.imdb_id?.removePrefix("tt")
.equals(imdbId?.removePrefix("tt")) || (it.title.equals(
title,
true
) && it.year == year)
} ?: return
val id = imdbId?.removePrefix("tt")
val slug = title?.createSlug()
val url = if (season == null) {
"$cinemaTvAPI/movies/play/$id-$slug-$year"
} else {
"$cinemaTvAPI/shows/play/$id-$slug-$year"
}

val mediaId = if (season == null) {
media.id_movie
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 {
app.get("$cinemaTvAPI/v1/shows?expand=episodes&id=${media.id_show}")
.parsedSafe<CinemaTvResponse>()?.episodes?.find { it.episode == episode && it.season == season }?.id
} ?: return
"""episode:\s*['"]$episode['"],[\n\s]+id_episode:\s*(\d+),[\n\s]+season:\s*['"]$season['"]"""
}).let { it.toRegex().find(script)?.groupValues?.get(1) }

val sources =
app.get("$cinemaTvAPI/v1/${if (season == null) "movies" else "episodes"}/view?expand=streams,subtitles&id=$mediaId")
.parsedSafe<CinemaTvResponse>()
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<CinemaTvResponse>()

sources?.streams?.mapKeys { source ->
callback.invoke(
ExtractorLink(
"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),
)
)
}
Expand Down
36 changes: 10 additions & 26 deletions SoraStream/src/main/kotlin/com/hexated/SoraParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,32 +191,6 @@ data class JikanResponse(
@JsonProperty("data") val data: JikanData? = null,
)

data class CinemaTvResponse(
@JsonProperty("items") val items: ArrayList<Items>? = arrayListOf(),
@JsonProperty("episodes") val episodes: ArrayList<Episodes>? = arrayListOf(),
@JsonProperty("streams") val streams: HashMap<String, String>? = null,
@JsonProperty("subtitles") val subtitles: ArrayList<Subtitles>? = 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,
Expand Down Expand Up @@ -486,4 +460,14 @@ data class AoneroomResponse(
)
}
}
}

data class CinemaTvResponse(
@JsonProperty("streams") val streams: HashMap<String, String>? = null,
@JsonProperty("subtitles") val subtitles: ArrayList<Subtitles>? = arrayListOf(),
) {
data class Subtitles(
@JsonProperty("language") val language: String? = null,
@JsonProperty("file") val file: Any? = null,
)
}

0 comments on commit 1040dd6

Please sign in to comment.