stremiox: fix episode

This commit is contained in:
hexated 2023-04-02 07:52:17 +07:00
parent 5adc74aa95
commit 5d0d2e3e3b

View file

@ -1,6 +1,7 @@
package com.hexated package com.hexated
import android.util.Log import android.util.Log
import com.fasterxml.jackson.annotation.JsonProperty
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.*
import com.lagradost.cloudstream3.utils.AppUtils.parseJson import com.lagradost.cloudstream3.utils.AppUtils.parseJson
@ -17,12 +18,11 @@ class Stremio : MainAPI() {
override var name = "Stremio" override var name = "Stremio"
override val supportedTypes = setOf(TvType.Others) override val supportedTypes = setOf(TvType.Others)
override val hasMainPage = true override val hasMainPage = true
private var fixedUrl = mainUrl
private val cinemataUrl = "https://v3-cinemeta.strem.io" private val cinemataUrl = "https://v3-cinemeta.strem.io"
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse? { override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse? {
fixedUrl = mainUrl.fixSourceUrl() mainUrl = mainUrl.fixSourceUrl()
val res = tryParseJson<Manifest>(app.get("${fixedUrl}/manifest.json").text) ?: return null val res = tryParseJson<Manifest>(app.get("${mainUrl}/manifest.json").text) ?: return null
val lists = mutableListOf<HomePageList>() val lists = mutableListOf<HomePageList>()
res.catalogs.forEach { catalog -> res.catalogs.forEach { catalog ->
catalog.toHomePageList(this)?.let { catalog.toHomePageList(this)?.let {
@ -36,8 +36,8 @@ class Stremio : MainAPI() {
} }
override suspend fun search(query: String): List<SearchResponse>? { override suspend fun search(query: String): List<SearchResponse>? {
fixedUrl = mainUrl.fixSourceUrl() mainUrl = mainUrl.fixSourceUrl()
val res = tryParseJson<Manifest>(app.get("${fixedUrl}/manifest.json").text) ?: return null val res = tryParseJson<Manifest>(app.get("${mainUrl}/manifest.json").text) ?: return null
val list = mutableListOf<SearchResponse>() val list = mutableListOf<SearchResponse>()
res.catalogs.forEach { catalog -> res.catalogs.forEach { catalog ->
list.addAll(catalog.search(query, this)) list.addAll(catalog.search(query, this))
@ -47,8 +47,8 @@ class Stremio : MainAPI() {
override suspend fun load(url: String): LoadResponse? { override suspend fun load(url: String): LoadResponse? {
val res = parseJson<CatalogEntry>(url) val res = parseJson<CatalogEntry>(url)
fixedUrl = if((res.type == "movie" || res.type == "series") && isImdborTmdb(res.id)) cinemataUrl else mainUrl.fixSourceUrl() mainUrl = if((res.type == "movie" || res.type == "series") && isImdborTmdb(res.id)) cinemataUrl else mainUrl
val json = app.get("${fixedUrl}/meta/${res.type}/${res.id}.json") val json = app.get("${mainUrl}/meta/${res.type}/${res.id}.json")
.parsedSafe<CatalogResponse>()?.meta ?: throw RuntimeException(url) .parsedSafe<CatalogResponse>()?.meta ?: throw RuntimeException(url)
return json.toLoadResponse(this) return json.toLoadResponse(this)
} }
@ -87,7 +87,7 @@ class Stremio : MainAPI() {
val entries = mutableListOf<SearchResponse>() val entries = mutableListOf<SearchResponse>()
types.forEach { type -> types.forEach { type ->
val json = val json =
app.get("${provider.fixedUrl}/catalog/${type}/${id}/search=${query}.json").text app.get("${provider.mainUrl}/catalog/${type}/${id}/search=${query}.json").text
val res = val res =
tryParseJson<CatalogResponse>(json) tryParseJson<CatalogResponse>(json)
?: return@forEach ?: return@forEach
@ -101,7 +101,7 @@ class Stremio : MainAPI() {
suspend fun toHomePageList(provider: Stremio): HomePageList? { suspend fun toHomePageList(provider: Stremio): HomePageList? {
val entries = mutableListOf<SearchResponse>() val entries = mutableListOf<SearchResponse>()
types.forEach { type -> types.forEach { type ->
val json = app.get("${provider.fixedUrl}/catalog/${type}/${id}.json").text val json = app.get("${provider.mainUrl}/catalog/${type}/${id}.json").text
val res = val res =
tryParseJson<CatalogResponse>(json) tryParseJson<CatalogResponse>(json)
?: return@forEach ?: return@forEach
@ -139,9 +139,9 @@ class Stremio : MainAPI() {
if (videos == null || videos.isEmpty()) { if (videos == null || videos.isEmpty()) {
return provider.newMovieLoadResponse( return provider.newMovieLoadResponse(
name, name,
"${provider.fixedUrl}/meta/${type}/${id}.json", "${provider.mainUrl}/meta/${type}/${id}.json",
TvType.Movie, TvType.Movie,
"${provider.fixedUrl}/stream/${type}/${id}.json" "${provider.mainUrl}/stream/${type}/${id}.json"
) { ) {
posterUrl = poster posterUrl = poster
plot = description plot = description
@ -149,7 +149,7 @@ class Stremio : MainAPI() {
} else { } else {
return provider.newTvSeriesLoadResponse( return provider.newTvSeriesLoadResponse(
name, name,
"${provider.fixedUrl}/meta/${type}/${id}.json", "${provider.mainUrl}/meta/${type}/${id}.json",
TvType.TvSeries, TvType.TvSeries,
videos.map { videos.map {
it.toEpisode(provider, type) it.toEpisode(provider, type)
@ -164,18 +164,24 @@ class Stremio : MainAPI() {
} }
private data class Video( private data class Video(
val id: String, @JsonProperty("id") val id: String? = null,
val title: String?, @JsonProperty("title") val title: String? = null,
val thumbnail: String?, @JsonProperty("name") val name: String? = null,
val overview: String? @JsonProperty("season") val seasonNumber: Int? = null,
@JsonProperty("number") val number: Int? = null,
@JsonProperty("episode") val episode: Int? = null,
@JsonProperty("thumbnail") val thumbnail: String? = null,
@JsonProperty("overview") val overview: String? = null,
) { ) {
fun toEpisode(provider: Stremio, type: String?): Episode { fun toEpisode(provider: Stremio, type: String?): Episode {
return provider.newEpisode( return provider.newEpisode(
"${provider.fixedUrl}/stream/${type}/${id}.json" "${provider.mainUrl}/stream/${type}/${id}.json"
) { ) {
this.name = title this.name = title ?: name
this.posterUrl = thumbnail this.posterUrl = thumbnail
this.description = overview this.description = overview
this.season = seasonNumber
this.episode = episode ?: number
} }
} }
} }
@ -219,7 +225,7 @@ class Stremio : MainAPI() {
name ?: "", name ?: "",
title ?: name ?: "", title ?: name ?: "",
url, url,
if (provider.fixedUrl.contains("kisskh")) "https://kisskh.me/" else referer if (provider.mainUrl.contains("kisskh")) "https://kisskh.me/" else referer
?: "", ?: "",
getQualityFromName(description), getQualityFromName(description),
isM3u8 = URI(url).path.endsWith(".m3u8") isM3u8 = URI(url).path.endsWith(".m3u8")