stremiox: small fix

This commit is contained in:
hexated 2023-04-02 01:27:43 +07:00
parent a1f47f1dc6
commit 0b0e1e8622
3 changed files with 46 additions and 44 deletions

View file

@ -17,9 +17,10 @@ class Stremio : MainAPI() {
override var name = "Stremio"
override val supportedTypes = setOf(TvType.Others)
override val hasMainPage = true
private val fixedUrl = mainUrl.fixSourceUrl()
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse? {
val res = tryParseJson<Manifest>(app.get("${mainUrl}/manifest.json").text) ?: return null
val res = tryParseJson<Manifest>(app.get("${fixedUrl}/manifest.json").text) ?: return null
val lists = mutableListOf<HomePageList>()
res.catalogs.forEach { catalog ->
catalog.toHomePageList(this)?.let {
@ -33,7 +34,7 @@ class Stremio : MainAPI() {
}
override suspend fun search(query: String): List<SearchResponse>? {
val res = tryParseJson<Manifest>(app.get("${mainUrl}/manifest.json").text) ?: return null
val res = tryParseJson<Manifest>(app.get("${fixedUrl}/manifest.json").text) ?: return null
val list = mutableListOf<SearchResponse>()
res.catalogs.forEach { catalog ->
list.addAll(catalog.search(query, this))
@ -43,7 +44,7 @@ class Stremio : MainAPI() {
override suspend fun load(url: String): LoadResponse? {
val res = parseJson<CatalogEntry>(url)
val json = app.get("${mainUrl}/meta/${res.type}/${res.id}.json")
val json = app.get("${fixedUrl}/meta/${res.type}/${res.id}.json")
.parsedSafe<CatalogResponse>()?.meta ?: throw RuntimeException(url)
return json.toLoadResponse(this)
}
@ -77,7 +78,7 @@ class Stremio : MainAPI() {
val entries = mutableListOf<SearchResponse>()
types.forEach { type ->
val json =
app.get("${provider.mainUrl}/catalog/${type}/${id}/search=${query}.json").text
app.get("${provider.fixedUrl}/catalog/${type}/${id}/search=${query}.json").text
val res =
tryParseJson<CatalogResponse>(json)
?: return@forEach
@ -91,7 +92,7 @@ class Stremio : MainAPI() {
suspend fun toHomePageList(provider: Stremio): HomePageList? {
val entries = mutableListOf<SearchResponse>()
types.forEach { type ->
val json = app.get("${provider.mainUrl}/catalog/${type}/${id}.json").text
val json = app.get("${provider.fixedUrl}/catalog/${type}/${id}.json").text
val res =
tryParseJson<CatalogResponse>(json)
?: return@forEach
@ -129,9 +130,9 @@ class Stremio : MainAPI() {
if (videos == null || videos.isEmpty()) {
return provider.newMovieLoadResponse(
name,
"${provider.mainUrl}/meta/${type}/${id}.json",
"${provider.fixedUrl}/meta/${type}/${id}.json",
TvType.Others,
"${provider.mainUrl}/stream/${type}/${id}.json"
"${provider.fixedUrl}/stream/${type}/${id}.json"
) {
posterUrl = poster
plot = description
@ -139,7 +140,7 @@ class Stremio : MainAPI() {
} else {
return provider.newTvSeriesLoadResponse(
name,
"${provider.mainUrl}/meta/${type}/${id}.json",
"${provider.fixedUrl}/meta/${type}/${id}.json",
TvType.Others,
videos.map {
it.toEpisode(provider, type)
@ -161,7 +162,7 @@ class Stremio : MainAPI() {
) {
fun toEpisode(provider: Stremio, type: String?): Episode {
return provider.newEpisode(
"${provider.mainUrl}/stream/${type}/${id}.json"
"${provider.fixedUrl}/stream/${type}/${id}.json"
) {
this.name = title
this.posterUrl = thumbnail
@ -209,7 +210,7 @@ class Stremio : MainAPI() {
name ?: "",
title ?: name ?: "",
url,
if (provider.mainUrl.contains("kisskh")) "https://kisskh.me/" else referer
if (provider.fixedUrl.contains("kisskh")) "https://kisskh.me/" else referer
?: "",
getQualityFromName(description),
isM3u8 = URI(url).path.endsWith(".m3u8")

View file

@ -311,40 +311,6 @@ open class StremioX : MainAPI() {
}
private fun String.fixSourceUrl() : String {
return this.replace("/manifest.json", "").replace("stremio://", "https://")
}
private fun getEpisodeSlug(
season: Int? = null,
episode: Int? = null,
): Pair<String, String> {
return if (season == null && episode == null) {
"" to ""
} else {
(if (season!! < 10) "0$season" else "$season") to (if (episode!! < 10) "0$episode" else "$episode")
}
}
private fun fixUrl(url: String, domain: String): String {
if (url.startsWith("http")) {
return url
}
if (url.isEmpty()) {
return ""
}
val startsWithNoHttp = url.startsWith("//")
if (startsWithNoHttp) {
return "https:$url"
} else {
if (url.startsWith('/')) {
return domain + url
}
return "$domain/$url"
}
}
private data class StreamsResponse(val streams: List<Stream>)
private data class Subtitle(
val url: String?,

View file

@ -0,0 +1,35 @@
package com.hexated
fun String.fixSourceUrl() : String {
return this.replace("/manifest.json", "").replace("stremio://", "https://")
}
fun getEpisodeSlug(
season: Int? = null,
episode: Int? = null,
): Pair<String, String> {
return if (season == null && episode == null) {
"" to ""
} else {
(if (season!! < 10) "0$season" else "$season") to (if (episode!! < 10) "0$episode" else "$episode")
}
}
fun fixUrl(url: String, domain: String): String {
if (url.startsWith("http")) {
return url
}
if (url.isEmpty()) {
return ""
}
val startsWithNoHttp = url.startsWith("//")
if (startsWithNoHttp) {
return "https:$url"
} else {
if (url.startsWith('/')) {
return domain + url
}
return "$domain/$url"
}
}