mirror of
https://github.com/recloudstream/cloudstream-extensions.git
synced 2024-08-15 03:03:54 +00:00
update streamio
This commit is contained in:
parent
81c15c46bc
commit
a169335037
2 changed files with 65 additions and 29 deletions
|
@ -1,5 +1,5 @@
|
|||
// use an integer for version numbers
|
||||
version = 1
|
||||
version = 2
|
||||
|
||||
|
||||
cloudstream {
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
package com.lagradost
|
||||
|
||||
import android.util.Log
|
||||
import com.lagradost.StremioProvider.Companion.encodeUri
|
||||
import com.lagradost.cloudstream3.*
|
||||
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
||||
|
||||
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.Qualities
|
||||
import com.lagradost.cloudstream3.utils.loadExtractor
|
||||
import org.json.JSONObject
|
||||
import java.net.URLEncoder
|
||||
|
||||
class StremioProvider : MainAPI() {
|
||||
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? {
|
||||
val res = tryParseJson<CatalogEntry>(url) ?: throw RuntimeException(url)
|
||||
return res.toLoadResponse(this)
|
||||
|
@ -41,10 +53,12 @@ class StremioProvider : MainAPI() {
|
|||
subtitleCallback: (SubtitleFile) -> Unit,
|
||||
callback: (ExtractorLink) -> Unit
|
||||
): Boolean {
|
||||
Log.i("Stremio", data)
|
||||
val res = tryParseJson<StreamsResponse>(app.get(data).text) ?: return false
|
||||
res.streams.forEach { stream ->
|
||||
stream.runCallback(subtitleCallback, callback)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -59,10 +73,21 @@ class StremioProvider : MainAPI() {
|
|||
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? {
|
||||
val entries = mutableListOf<SearchResponse>()
|
||||
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 ->
|
||||
entries.add(entry.toSearchResponse(provider))
|
||||
}
|
||||
|
@ -80,26 +105,54 @@ class StremioProvider : MainAPI() {
|
|||
val id: String,
|
||||
val poster: String?,
|
||||
val description: String?,
|
||||
val type: String?
|
||||
val type: String?,
|
||||
val videos: List<Video>?
|
||||
) {
|
||||
fun toSearchResponse(provider: StremioProvider): SearchResponse {
|
||||
return provider.newMovieSearchResponse(
|
||||
name,
|
||||
this.toJson(),
|
||||
type?.let { getType(it) } ?: TvType.Others
|
||||
TvType.Others
|
||||
) {
|
||||
posterUrl = poster
|
||||
}
|
||||
}
|
||||
suspend fun toLoadResponse(provider: StremioProvider): LoadResponse {
|
||||
return provider.newMovieLoadResponse(
|
||||
name,
|
||||
"${provider.mainUrl}/meta/$type/$id.json",
|
||||
getType(type),
|
||||
"${provider.mainUrl}/stream/$type/$id.json"
|
||||
if (videos == null || videos.isEmpty()) {
|
||||
return provider.newMovieLoadResponse(
|
||||
name,
|
||||
"${provider.mainUrl}/meta/${type?.encodeUri()}/${id.encodeUri()}.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
|
||||
plot = description
|
||||
this.name = title
|
||||
this.posterUrl = thumbnail
|
||||
this.description = overview
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,23 +209,6 @@ class StremioProvider : MainAPI() {
|
|||
}
|
||||
|
||||
companion object {
|
||||
private val typeAliases = hashMapOf(
|
||||
"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
|
||||
}
|
||||
fun String.encodeUri() = URLEncoder.encode(this, "utf8")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue