2023-04-01 17:42:02 +00:00
|
|
|
package com.hexated
|
|
|
|
|
|
|
|
import android.util.Log
|
2023-04-02 00:52:17 +00:00
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty
|
2023-04-04 06:30:20 +00:00
|
|
|
import com.hexated.SubsExtractors.invokeOpenSubs
|
|
|
|
import com.hexated.SubsExtractors.invokeWatchsomuch
|
2023-04-01 17:42:02 +00:00
|
|
|
import com.lagradost.cloudstream3.*
|
2023-04-04 05:17:12 +00:00
|
|
|
import com.lagradost.cloudstream3.LoadResponse.Companion.addActors
|
|
|
|
import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer
|
2023-04-01 17:42:02 +00:00
|
|
|
import com.lagradost.cloudstream3.utils.*
|
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.parseJson
|
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.toJson
|
|
|
|
import com.lagradost.cloudstream3.utils.AppUtils.tryParseJson
|
|
|
|
import org.json.JSONObject
|
|
|
|
import java.net.URI
|
|
|
|
|
|
|
|
private const val TRACKER_LIST_URL =
|
|
|
|
"https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt"
|
|
|
|
|
2023-04-02 01:58:58 +00:00
|
|
|
class StremioC : MainAPI() {
|
2023-04-01 17:42:02 +00:00
|
|
|
override var mainUrl = "https://stremio.github.io/stremio-static-addon-example"
|
2023-04-02 01:58:58 +00:00
|
|
|
override var name = "StremioC"
|
2023-04-01 17:42:02 +00:00
|
|
|
override val supportedTypes = setOf(TvType.Others)
|
|
|
|
override val hasMainPage = true
|
2023-04-01 21:01:43 +00:00
|
|
|
private val cinemataUrl = "https://v3-cinemeta.strem.io"
|
2023-04-01 17:42:02 +00:00
|
|
|
|
|
|
|
override suspend fun getMainPage(page: Int, request: MainPageRequest): HomePageResponse? {
|
2023-04-02 00:52:17 +00:00
|
|
|
mainUrl = mainUrl.fixSourceUrl()
|
|
|
|
val res = tryParseJson<Manifest>(app.get("${mainUrl}/manifest.json").text) ?: return null
|
2023-04-01 17:42:02 +00:00
|
|
|
val lists = mutableListOf<HomePageList>()
|
|
|
|
res.catalogs.forEach { catalog ->
|
|
|
|
catalog.toHomePageList(this)?.let {
|
2023-04-04 04:15:57 +00:00
|
|
|
if (it.list.isNotEmpty()) lists.add(it)
|
2023-04-01 17:42:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return HomePageResponse(
|
|
|
|
lists,
|
|
|
|
false
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun search(query: String): List<SearchResponse>? {
|
2023-04-02 00:52:17 +00:00
|
|
|
mainUrl = mainUrl.fixSourceUrl()
|
|
|
|
val res = tryParseJson<Manifest>(app.get("${mainUrl}/manifest.json").text) ?: return null
|
2023-04-01 17:42:02 +00:00
|
|
|
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 = parseJson<CatalogEntry>(url)
|
2023-04-04 04:15:57 +00:00
|
|
|
mainUrl =
|
|
|
|
if ((res.type == "movie" || res.type == "series") && isImdborTmdb(res.id)) cinemataUrl else mainUrl
|
2023-04-02 00:52:17 +00:00
|
|
|
val json = app.get("${mainUrl}/meta/${res.type}/${res.id}.json")
|
2023-04-01 17:42:02 +00:00
|
|
|
.parsedSafe<CatalogResponse>()?.meta ?: throw RuntimeException(url)
|
2023-04-04 04:15:57 +00:00
|
|
|
return json.toLoadResponse(this, res.id)
|
2023-04-01 17:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
override suspend fun loadLinks(
|
|
|
|
data: String,
|
|
|
|
isCasting: Boolean,
|
|
|
|
subtitleCallback: (SubtitleFile) -> Unit,
|
|
|
|
callback: (ExtractorLink) -> Unit
|
|
|
|
): Boolean {
|
2023-04-04 04:15:57 +00:00
|
|
|
val loadData = parseJson<LoadData>(data)
|
|
|
|
val request = app.get("${mainUrl}/stream/${loadData.type}/${loadData.id}.json")
|
|
|
|
if (request.isSuccessful) {
|
|
|
|
val res = tryParseJson<StreamsResponse>(request.text) ?: return false
|
|
|
|
res.streams.forEach { stream ->
|
|
|
|
stream.runCallback(this, subtitleCallback, callback)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
argamap(
|
|
|
|
{
|
|
|
|
invokeStremioX(loadData.type, loadData.id, subtitleCallback, callback)
|
|
|
|
},
|
|
|
|
{
|
2023-04-04 06:30:20 +00:00
|
|
|
invokeWatchsomuch(
|
2023-04-04 04:15:57 +00:00
|
|
|
loadData.imdbId,
|
|
|
|
loadData.season,
|
|
|
|
loadData.episode,
|
|
|
|
subtitleCallback
|
|
|
|
)
|
|
|
|
},
|
|
|
|
{
|
2023-04-04 06:30:20 +00:00
|
|
|
invokeOpenSubs(
|
2023-04-04 04:15:57 +00:00
|
|
|
loadData.imdbId,
|
|
|
|
loadData.season,
|
|
|
|
loadData.episode,
|
|
|
|
subtitleCallback
|
|
|
|
)
|
|
|
|
},
|
|
|
|
)
|
2023-04-01 17:42:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2023-04-04 04:15:57 +00:00
|
|
|
private suspend fun invokeStremioX(
|
|
|
|
type: String?,
|
|
|
|
id: String?,
|
|
|
|
subtitleCallback: (SubtitleFile) -> Unit,
|
|
|
|
callback: (ExtractorLink) -> Unit
|
|
|
|
) {
|
|
|
|
val sites =
|
|
|
|
AcraApplication.getKey<Array<CustomSite>>(USER_PROVIDER_API)?.toMutableList()
|
|
|
|
?: mutableListOf()
|
|
|
|
sites.filter { it.parentJavaClass == "StremioX" }.apmap { site ->
|
|
|
|
val res =
|
|
|
|
tryParseJson<StreamsResponse>(app.get("${site.url.fixSourceUrl()}/stream/${type}/${id}.json").text)
|
|
|
|
?: return@apmap
|
|
|
|
res.streams.forEach { stream ->
|
|
|
|
stream.runCallback(this, subtitleCallback, callback)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
data class LoadData(
|
|
|
|
val type: String? = null,
|
|
|
|
val id: String? = null,
|
|
|
|
val season: Int? = null,
|
|
|
|
val episode: Int? = null,
|
|
|
|
val imdbId: String? = null,
|
|
|
|
)
|
|
|
|
|
|
|
|
data class CustomSite(
|
|
|
|
@JsonProperty("parentJavaClass") val parentJavaClass: String,
|
|
|
|
@JsonProperty("name") val name: String,
|
|
|
|
@JsonProperty("url") val url: String,
|
|
|
|
@JsonProperty("lang") val lang: String,
|
|
|
|
)
|
|
|
|
|
2023-04-01 21:01:43 +00:00
|
|
|
// check if id is imdb/tmdb cause stremio addons like torrentio works base on imdbId
|
|
|
|
private fun isImdborTmdb(url: String?): Boolean {
|
|
|
|
return imdbUrlToIdNullable(url) != null || url?.startsWith("tmdb:") == true
|
|
|
|
}
|
|
|
|
|
2023-04-01 17:42:02 +00:00
|
|
|
private data class Manifest(val catalogs: List<Catalog>)
|
|
|
|
private data class Catalog(
|
|
|
|
var name: String?,
|
|
|
|
val id: String,
|
|
|
|
val type: String?,
|
|
|
|
val types: MutableList<String> = mutableListOf()
|
|
|
|
) {
|
|
|
|
init {
|
|
|
|
if (type != null) types.add(type)
|
|
|
|
}
|
|
|
|
|
2023-04-02 01:58:58 +00:00
|
|
|
suspend fun search(query: String, provider: StremioC): List<SearchResponse> {
|
2023-04-01 17:42:02 +00:00
|
|
|
val entries = mutableListOf<SearchResponse>()
|
|
|
|
types.forEach { type ->
|
|
|
|
val json =
|
2023-04-02 00:52:17 +00:00
|
|
|
app.get("${provider.mainUrl}/catalog/${type}/${id}/search=${query}.json").text
|
2023-04-01 17:42:02 +00:00
|
|
|
val res =
|
|
|
|
tryParseJson<CatalogResponse>(json)
|
|
|
|
?: return@forEach
|
|
|
|
res.metas?.forEach { entry ->
|
|
|
|
entries.add(entry.toSearchResponse(provider))
|
|
|
|
}
|
|
|
|
}
|
2023-04-04 06:30:20 +00:00
|
|
|
return entries.distinctBy { it.id }
|
2023-04-01 17:42:02 +00:00
|
|
|
}
|
|
|
|
|
2023-04-02 01:58:58 +00:00
|
|
|
suspend fun toHomePageList(provider: StremioC): HomePageList? {
|
2023-04-01 17:42:02 +00:00
|
|
|
val entries = mutableListOf<SearchResponse>()
|
|
|
|
types.forEach { type ->
|
2023-04-02 00:52:17 +00:00
|
|
|
val json = app.get("${provider.mainUrl}/catalog/${type}/${id}.json").text
|
2023-04-01 17:42:02 +00:00
|
|
|
val res =
|
|
|
|
tryParseJson<CatalogResponse>(json)
|
|
|
|
?: return@forEach
|
|
|
|
res.metas?.forEach { entry ->
|
|
|
|
entries.add(entry.toSearchResponse(provider))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return HomePageList(
|
2023-04-02 01:37:35 +00:00
|
|
|
"$type - ${name ?: id}",
|
2023-04-01 17:42:02 +00:00
|
|
|
entries
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private data class CatalogResponse(val metas: List<CatalogEntry>?, val meta: CatalogEntry?)
|
2023-04-04 05:17:12 +00:00
|
|
|
|
|
|
|
private data class Trailer(
|
|
|
|
val source: String?,
|
|
|
|
val type: String?
|
|
|
|
)
|
2023-04-01 17:42:02 +00:00
|
|
|
private data class CatalogEntry(
|
2023-04-04 05:17:12 +00:00
|
|
|
@JsonProperty("name") val name: String,
|
|
|
|
@JsonProperty("id") val id: String,
|
|
|
|
@JsonProperty("poster") val poster: String?,
|
|
|
|
@JsonProperty("background") val background: String?,
|
|
|
|
@JsonProperty("description") val description: String?,
|
|
|
|
@JsonProperty("imdbRating") val imdbRating: String?,
|
|
|
|
@JsonProperty("type") val type: String?,
|
|
|
|
@JsonProperty("videos") val videos: List<Video>?,
|
|
|
|
@JsonProperty("genre") val genre: List<String>?,
|
|
|
|
@JsonProperty("genres") val genres: List<String>?,
|
|
|
|
@JsonProperty("cast") val cast: List<String>?,
|
|
|
|
@JsonProperty("year") val yearNum: String? = null,
|
|
|
|
@JsonProperty("trailers") val trailersSources: ArrayList<Trailer>? = arrayListOf()
|
2023-04-01 17:42:02 +00:00
|
|
|
) {
|
2023-04-02 01:58:58 +00:00
|
|
|
fun toSearchResponse(provider: StremioC): SearchResponse {
|
2023-04-01 17:42:02 +00:00
|
|
|
return provider.newMovieSearchResponse(
|
|
|
|
fixTitle(name),
|
|
|
|
this.toJson(),
|
|
|
|
TvType.Others
|
|
|
|
) {
|
|
|
|
posterUrl = poster
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-04 04:15:57 +00:00
|
|
|
suspend fun toLoadResponse(provider: StremioC, imdbId: String?): LoadResponse {
|
2023-04-01 17:42:02 +00:00
|
|
|
if (videos == null || videos.isEmpty()) {
|
|
|
|
return provider.newMovieLoadResponse(
|
|
|
|
name,
|
2023-04-02 00:52:17 +00:00
|
|
|
"${provider.mainUrl}/meta/${type}/${id}.json",
|
2023-04-01 21:19:42 +00:00
|
|
|
TvType.Movie,
|
2023-04-04 04:15:57 +00:00
|
|
|
LoadData(type, id, imdbId = imdbId)
|
2023-04-01 17:42:02 +00:00
|
|
|
) {
|
|
|
|
posterUrl = poster
|
2023-04-02 01:37:35 +00:00
|
|
|
backgroundPosterUrl = background
|
|
|
|
rating = imdbRating.toRatingInt()
|
2023-04-01 17:42:02 +00:00
|
|
|
plot = description
|
2023-04-04 05:17:12 +00:00
|
|
|
year = yearNum?.toIntOrNull()
|
|
|
|
tags = genre ?: genres
|
|
|
|
addActors(cast)
|
|
|
|
addTrailer(trailersSources?.map { "https://www.youtube.com/watch?v=${it.source}" }?.randomOrNull())
|
2023-04-01 17:42:02 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
return provider.newTvSeriesLoadResponse(
|
|
|
|
name,
|
2023-04-02 00:52:17 +00:00
|
|
|
"${provider.mainUrl}/meta/${type}/${id}.json",
|
2023-04-01 21:19:42 +00:00
|
|
|
TvType.TvSeries,
|
2023-04-01 17:42:02 +00:00
|
|
|
videos.map {
|
2023-04-04 04:15:57 +00:00
|
|
|
it.toEpisode(provider, type, imdbId)
|
2023-04-01 17:42:02 +00:00
|
|
|
}
|
|
|
|
) {
|
|
|
|
posterUrl = poster
|
2023-04-02 01:37:35 +00:00
|
|
|
backgroundPosterUrl = background
|
|
|
|
rating = imdbRating.toRatingInt()
|
2023-04-01 17:42:02 +00:00
|
|
|
plot = description
|
2023-04-04 05:17:12 +00:00
|
|
|
year = yearNum?.toIntOrNull()
|
|
|
|
tags = genre ?: genres
|
|
|
|
addActors(cast)
|
|
|
|
addTrailer(trailersSources?.map { "https://www.youtube.com/watch?v=${it.source}" }?.randomOrNull())
|
2023-04-01 17:42:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private data class Video(
|
2023-04-02 00:52:17 +00:00
|
|
|
@JsonProperty("id") val id: String? = null,
|
|
|
|
@JsonProperty("title") val title: String? = null,
|
|
|
|
@JsonProperty("name") val name: String? = null,
|
|
|
|
@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,
|
2023-04-02 01:37:35 +00:00
|
|
|
@JsonProperty("description") val description: String? = null,
|
2023-04-01 17:42:02 +00:00
|
|
|
) {
|
2023-04-04 04:15:57 +00:00
|
|
|
fun toEpisode(provider: StremioC, type: String?, imdbId: String?): Episode {
|
2023-04-01 17:42:02 +00:00
|
|
|
return provider.newEpisode(
|
2023-04-04 04:15:57 +00:00
|
|
|
LoadData(type, id, seasonNumber, episode ?: number, imdbId)
|
2023-04-01 17:42:02 +00:00
|
|
|
) {
|
2023-04-02 01:37:35 +00:00
|
|
|
this.name = name ?: title
|
2023-04-01 17:42:02 +00:00
|
|
|
this.posterUrl = thumbnail
|
2023-04-02 01:37:35 +00:00
|
|
|
this.description = overview ?: description
|
2023-04-02 00:52:17 +00:00
|
|
|
this.season = seasonNumber
|
|
|
|
this.episode = episode ?: number
|
2023-04-01 17:42:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private data class StreamsResponse(val streams: List<Stream>)
|
|
|
|
private data class Subtitle(
|
|
|
|
val url: String?,
|
|
|
|
val lang: String?,
|
|
|
|
val id: String?,
|
|
|
|
)
|
|
|
|
|
|
|
|
private data class Stream(
|
|
|
|
val name: String?,
|
|
|
|
val title: String?,
|
|
|
|
val url: String?,
|
|
|
|
val description: String?,
|
|
|
|
val ytId: String?,
|
|
|
|
val externalUrl: String?,
|
|
|
|
val behaviorHints: JSONObject?,
|
|
|
|
val infoHash: String?,
|
|
|
|
val sources: List<String> = emptyList(),
|
|
|
|
val subtitles: List<Subtitle> = emptyList()
|
|
|
|
) {
|
|
|
|
suspend fun runCallback(
|
2023-04-02 01:58:58 +00:00
|
|
|
provider: StremioC,
|
2023-04-01 17:42:02 +00:00
|
|
|
subtitleCallback: (SubtitleFile) -> Unit,
|
|
|
|
callback: (ExtractorLink) -> Unit
|
|
|
|
) {
|
|
|
|
if (url != null) {
|
|
|
|
var referer: String? = null
|
|
|
|
try {
|
|
|
|
val headers = ((behaviorHints?.get("proxyHeaders") as? JSONObject)
|
|
|
|
?.get("request") as? JSONObject)
|
|
|
|
referer =
|
|
|
|
headers?.get("referer") as? String ?: headers?.get("origin") as? String
|
|
|
|
} catch (ex: Throwable) {
|
|
|
|
Log.e("Stremio", Log.getStackTraceString(ex))
|
|
|
|
}
|
|
|
|
callback.invoke(
|
|
|
|
ExtractorLink(
|
|
|
|
name ?: "",
|
|
|
|
title ?: name ?: "",
|
|
|
|
url,
|
2023-04-02 00:52:17 +00:00
|
|
|
if (provider.mainUrl.contains("kisskh")) "https://kisskh.me/" else referer
|
2023-04-01 17:42:02 +00:00
|
|
|
?: "",
|
|
|
|
getQualityFromName(description),
|
|
|
|
isM3u8 = URI(url).path.endsWith(".m3u8")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
subtitles.map { sub ->
|
|
|
|
subtitleCallback.invoke(
|
|
|
|
SubtitleFile(
|
|
|
|
SubtitleHelper.fromThreeLettersToLanguage(sub.lang ?: "") ?: sub.lang
|
|
|
|
?: "",
|
|
|
|
sub.url ?: return@map
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ytId != null) {
|
|
|
|
loadExtractor("https://www.youtube.com/watch?v=$ytId", subtitleCallback, callback)
|
|
|
|
}
|
|
|
|
if (externalUrl != null) {
|
|
|
|
loadExtractor(externalUrl, subtitleCallback, callback)
|
|
|
|
}
|
|
|
|
if (infoHash != null) {
|
|
|
|
val resp = app.get(TRACKER_LIST_URL).text
|
|
|
|
val otherTrackers = resp
|
|
|
|
.split("\n")
|
|
|
|
.filterIndexed { i, s -> i % 2 == 0 }
|
|
|
|
.filter { s -> s.isNotEmpty() }.joinToString("") { "&tr=$it" }
|
|
|
|
|
|
|
|
val sourceTrackers = sources
|
|
|
|
.filter { it.startsWith("tracker:") }
|
|
|
|
.map { it.removePrefix("tracker:") }
|
|
|
|
.filter { s -> s.isNotEmpty() }.joinToString("") { "&tr=$it" }
|
|
|
|
|
|
|
|
val magnet = "magnet:?xt=urn:btih:${infoHash}${sourceTrackers}${otherTrackers}"
|
|
|
|
callback.invoke(
|
|
|
|
ExtractorLink(
|
|
|
|
name ?: "",
|
|
|
|
title ?: name ?: "",
|
|
|
|
magnet,
|
|
|
|
"",
|
|
|
|
Qualities.Unknown.value
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|