mirror of
https://github.com/hexated/cloudstream-extensions-hexated.git
synced 2024-08-15 00:03:22 +00:00
stremiox: small fix
This commit is contained in:
parent
a1f47f1dc6
commit
0b0e1e8622
3 changed files with 46 additions and 44 deletions
|
@ -17,9 +17,10 @@ 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 val fixedUrl = mainUrl.fixSourceUrl()
|
||||||
|
|
||||||
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse? {
|
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>()
|
val lists = mutableListOf<HomePageList>()
|
||||||
res.catalogs.forEach { catalog ->
|
res.catalogs.forEach { catalog ->
|
||||||
catalog.toHomePageList(this)?.let {
|
catalog.toHomePageList(this)?.let {
|
||||||
|
@ -33,7 +34,7 @@ class Stremio : MainAPI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun search(query: String): List<SearchResponse>? {
|
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>()
|
val list = mutableListOf<SearchResponse>()
|
||||||
res.catalogs.forEach { catalog ->
|
res.catalogs.forEach { catalog ->
|
||||||
list.addAll(catalog.search(query, this))
|
list.addAll(catalog.search(query, this))
|
||||||
|
@ -43,7 +44,7 @@ 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)
|
||||||
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)
|
.parsedSafe<CatalogResponse>()?.meta ?: throw RuntimeException(url)
|
||||||
return json.toLoadResponse(this)
|
return json.toLoadResponse(this)
|
||||||
}
|
}
|
||||||
|
@ -77,7 +78,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.mainUrl}/catalog/${type}/${id}/search=${query}.json").text
|
app.get("${provider.fixedUrl}/catalog/${type}/${id}/search=${query}.json").text
|
||||||
val res =
|
val res =
|
||||||
tryParseJson<CatalogResponse>(json)
|
tryParseJson<CatalogResponse>(json)
|
||||||
?: return@forEach
|
?: return@forEach
|
||||||
|
@ -91,7 +92,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.mainUrl}/catalog/${type}/${id}.json").text
|
val json = app.get("${provider.fixedUrl}/catalog/${type}/${id}.json").text
|
||||||
val res =
|
val res =
|
||||||
tryParseJson<CatalogResponse>(json)
|
tryParseJson<CatalogResponse>(json)
|
||||||
?: return@forEach
|
?: return@forEach
|
||||||
|
@ -129,9 +130,9 @@ class Stremio : MainAPI() {
|
||||||
if (videos == null || videos.isEmpty()) {
|
if (videos == null || videos.isEmpty()) {
|
||||||
return provider.newMovieLoadResponse(
|
return provider.newMovieLoadResponse(
|
||||||
name,
|
name,
|
||||||
"${provider.mainUrl}/meta/${type}/${id}.json",
|
"${provider.fixedUrl}/meta/${type}/${id}.json",
|
||||||
TvType.Others,
|
TvType.Others,
|
||||||
"${provider.mainUrl}/stream/${type}/${id}.json"
|
"${provider.fixedUrl}/stream/${type}/${id}.json"
|
||||||
) {
|
) {
|
||||||
posterUrl = poster
|
posterUrl = poster
|
||||||
plot = description
|
plot = description
|
||||||
|
@ -139,7 +140,7 @@ class Stremio : MainAPI() {
|
||||||
} else {
|
} else {
|
||||||
return provider.newTvSeriesLoadResponse(
|
return provider.newTvSeriesLoadResponse(
|
||||||
name,
|
name,
|
||||||
"${provider.mainUrl}/meta/${type}/${id}.json",
|
"${provider.fixedUrl}/meta/${type}/${id}.json",
|
||||||
TvType.Others,
|
TvType.Others,
|
||||||
videos.map {
|
videos.map {
|
||||||
it.toEpisode(provider, type)
|
it.toEpisode(provider, type)
|
||||||
|
@ -161,7 +162,7 @@ class Stremio : MainAPI() {
|
||||||
) {
|
) {
|
||||||
fun toEpisode(provider: Stremio, type: String?): Episode {
|
fun toEpisode(provider: Stremio, type: String?): Episode {
|
||||||
return provider.newEpisode(
|
return provider.newEpisode(
|
||||||
"${provider.mainUrl}/stream/${type}/${id}.json"
|
"${provider.fixedUrl}/stream/${type}/${id}.json"
|
||||||
) {
|
) {
|
||||||
this.name = title
|
this.name = title
|
||||||
this.posterUrl = thumbnail
|
this.posterUrl = thumbnail
|
||||||
|
@ -209,7 +210,7 @@ class Stremio : MainAPI() {
|
||||||
name ?: "",
|
name ?: "",
|
||||||
title ?: name ?: "",
|
title ?: name ?: "",
|
||||||
url,
|
url,
|
||||||
if (provider.mainUrl.contains("kisskh")) "https://kisskh.me/" else referer
|
if (provider.fixedUrl.contains("kisskh")) "https://kisskh.me/" else referer
|
||||||
?: "",
|
?: "",
|
||||||
getQualityFromName(description),
|
getQualityFromName(description),
|
||||||
isM3u8 = URI(url).path.endsWith(".m3u8")
|
isM3u8 = URI(url).path.endsWith(".m3u8")
|
||||||
|
|
|
@ -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 StreamsResponse(val streams: List<Stream>)
|
||||||
private data class Subtitle(
|
private data class Subtitle(
|
||||||
val url: String?,
|
val url: String?,
|
||||||
|
|
35
StremioX/src/main/kotlin/com/hexated/Utils.kt
Normal file
35
StremioX/src/main/kotlin/com/hexated/Utils.kt
Normal 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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue