update streamio

This commit is contained in:
Cloudburst 2022-09-20 23:10:12 +02:00
parent 81c15c46bc
commit a169335037
2 changed files with 65 additions and 29 deletions

View file

@ -1,5 +1,5 @@
// use an integer for version numbers // use an integer for version numbers
version = 1 version = 2
cloudstream { cloudstream {

View file

@ -1,14 +1,17 @@
package com.lagradost package com.lagradost
import android.util.Log import android.util.Log
import com.lagradost.StremioProvider.Companion.encodeUri
import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.*
import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.lagradost.cloudstream3.utils.AppUtils.toJson
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
import com.lagradost.cloudstream3.utils.Coroutines.ioSafe
import com.lagradost.cloudstream3.utils.ExtractorLink import com.lagradost.cloudstream3.utils.ExtractorLink
import com.lagradost.cloudstream3.utils.Qualities import com.lagradost.cloudstream3.utils.Qualities
import com.lagradost.cloudstream3.utils.loadExtractor import com.lagradost.cloudstream3.utils.loadExtractor
import org.json.JSONObject import org.json.JSONObject
import java.net.URLEncoder
class StremioProvider : MainAPI() { class StremioProvider : MainAPI() {
override var mainUrl = "https://stremio.github.io/stremio-static-addon-example" override var mainUrl = "https://stremio.github.io/stremio-static-addon-example"
@ -30,6 +33,15 @@ class StremioProvider : MainAPI() {
) )
} }
override suspend fun search(query: String): List<SearchResponse>? {
val res = tryParseJson<Manifest>(app.get("${mainUrl}/manifest.json").text) ?: return null
val list = mutableListOf<SearchResponse>()
res.catalogs.forEach { catalog ->
list.addAll(catalog.search(query, this))
}
return list
}
override suspend fun load(url: String): LoadResponse? { override suspend fun load(url: String): LoadResponse? {
val res = tryParseJson<CatalogEntry>(url) ?: throw RuntimeException(url) val res = tryParseJson<CatalogEntry>(url) ?: throw RuntimeException(url)
return res.toLoadResponse(this) return res.toLoadResponse(this)
@ -41,10 +53,12 @@ class StremioProvider : MainAPI() {
subtitleCallback: (SubtitleFile) -> Unit, subtitleCallback: (SubtitleFile) -> Unit,
callback: (ExtractorLink) -> Unit callback: (ExtractorLink) -> Unit
): Boolean { ): Boolean {
Log.i("Stremio", data)
val res = tryParseJson<StreamsResponse>(app.get(data).text) ?: return false val res = tryParseJson<StreamsResponse>(app.get(data).text) ?: return false
res.streams.forEach { stream -> res.streams.forEach { stream ->
stream.runCallback(subtitleCallback, callback) stream.runCallback(subtitleCallback, callback)
} }
return true return true
} }
@ -59,10 +73,21 @@ class StremioProvider : MainAPI() {
if (type != null) types.add(type) if (type != null) types.add(type)
} }
suspend fun search(query: String, provider: StremioProvider): List<SearchResponse> {
val entries = mutableListOf<SearchResponse>()
types.forEach { type ->
val res = tryParseJson<CatalogResponse>(app.get("${provider.mainUrl}/catalog/${type.encodeUri()}/${id.encodeUri()}/search=${query.encodeUri()}.json").text) ?: return@forEach
res.metas.forEach { entry ->
entries.add(entry.toSearchResponse(provider))
}
}
return entries
}
suspend fun toHomePageList(provider: StremioProvider): HomePageList? { suspend fun toHomePageList(provider: StremioProvider): HomePageList? {
val entries = mutableListOf<SearchResponse>() val entries = mutableListOf<SearchResponse>()
types.forEach { type -> types.forEach { type ->
val res = tryParseJson<CatalogResponse>(app.get("${provider.mainUrl}/catalog/$type/$id.json").text) ?: return@forEach val res = tryParseJson<CatalogResponse>(app.get("${provider.mainUrl}/catalog/${type.encodeUri()}/${id.encodeUri()}.json").text) ?: return@forEach
res.metas.forEach { entry -> res.metas.forEach { entry ->
entries.add(entry.toSearchResponse(provider)) entries.add(entry.toSearchResponse(provider))
} }
@ -80,26 +105,54 @@ class StremioProvider : MainAPI() {
val id: String, val id: String,
val poster: String?, val poster: String?,
val description: String?, val description: String?,
val type: String? val type: String?,
val videos: List<Video>?
) { ) {
fun toSearchResponse(provider: StremioProvider): SearchResponse { fun toSearchResponse(provider: StremioProvider): SearchResponse {
return provider.newMovieSearchResponse( return provider.newMovieSearchResponse(
name, name,
this.toJson(), this.toJson(),
type?.let { getType(it) } ?: TvType.Others TvType.Others
) { ) {
posterUrl = poster posterUrl = poster
} }
} }
suspend fun toLoadResponse(provider: StremioProvider): LoadResponse { suspend fun toLoadResponse(provider: StremioProvider): LoadResponse {
return provider.newMovieLoadResponse( if (videos == null || videos.isEmpty()) {
name, return provider.newMovieLoadResponse(
"${provider.mainUrl}/meta/$type/$id.json", name,
getType(type), "${provider.mainUrl}/meta/${type?.encodeUri()}/${id.encodeUri()}.json",
"${provider.mainUrl}/stream/$type/$id.json" TvType.Others,
"${provider.mainUrl}/stream/${type?.encodeUri()}/${id.encodeUri()}.json"
) {
posterUrl = poster
plot = description
}
} else {
return provider.newTvSeriesLoadResponse(
name,
"${provider.mainUrl}/meta/${type?.encodeUri()}/${id.encodeUri()}.json",
TvType.Others,
videos.map {
it.toEpisode(provider, type)
}
) {
posterUrl = poster
plot = description
}
}
}
}
private data class Video(val id: String, val title: String?, val thumbnail: String?, val overview: String?) {
fun toEpisode(provider: StremioProvider, type: String?): Episode {
return provider.newEpisode(
"${provider.mainUrl}/stream/${type?.encodeUri()}/${id.encodeUri()}.json"
) { ) {
posterUrl = poster this.name = title
plot = description this.posterUrl = thumbnail
this.description = overview
} }
} }
} }
@ -156,23 +209,6 @@ class StremioProvider : MainAPI() {
} }
companion object { companion object {
private val typeAliases = hashMapOf( fun String.encodeUri() = URLEncoder.encode(this, "utf8")
"tv" to TvType.TvSeries,
"series" to TvType.TvSeries,
"channel" to TvType.Live,
"adult" to TvType.NSFW
)
fun getType(t_str: String?): TvType {
if (t_str == null) return TvType.Others
typeAliases[t_str.lowercase()]?.let {
return it
}
for (t_enum in TvType.values()) {
if (t_enum.toString().lowercase() == t_str.lowercase())
return t_enum
}
return TvType.Others
}
} }
} }