From 5a35077a4f457426b18c071c429767e4d9f23dcb Mon Sep 17 00:00:00 2001 From: hexated Date: Fri, 11 Aug 2023 20:22:36 +0700 Subject: [PATCH] StremioX & StremioC: added imdb id --- StremioX/build.gradle.kts | 2 +- StremioX/src/main/kotlin/com/hexated/StremioC.kt | 13 ++++++++----- StremioX/src/main/kotlin/com/hexated/StremioX.kt | 12 ++++++++++-- StremioX/src/main/kotlin/com/hexated/Utils.kt | 10 ++++++++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/StremioX/build.gradle.kts b/StremioX/build.gradle.kts index 5e6b7146..3366ed71 100644 --- a/StremioX/build.gradle.kts +++ b/StremioX/build.gradle.kts @@ -1,5 +1,5 @@ // use an integer for version numbers -version = 9 +version = 10 cloudstream { diff --git a/StremioX/src/main/kotlin/com/hexated/StremioC.kt b/StremioX/src/main/kotlin/com/hexated/StremioC.kt index 9c766240..4d972d31 100644 --- a/StremioX/src/main/kotlin/com/hexated/StremioC.kt +++ b/StremioX/src/main/kotlin/com/hexated/StremioC.kt @@ -5,6 +5,7 @@ import com.hexated.SubsExtractors.invokeOpenSubs import com.hexated.SubsExtractors.invokeWatchsomuch import com.lagradost.cloudstream3.* import com.lagradost.cloudstream3.LoadResponse.Companion.addActors +import com.lagradost.cloudstream3.LoadResponse.Companion.addImdbId import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.AppUtils.parseJson @@ -27,7 +28,7 @@ class StremioC : MainAPI() { val res = tryParseJson(request("${mainUrl}/manifest.json").body.string()) ?: return null val lists = mutableListOf() res.catalogs.apmap { catalog -> - catalog.toHomePageList(this)?.let { + catalog.toHomePageList(this).let { if (it.list.isNotEmpty()) lists.add(it) } } @@ -47,7 +48,7 @@ class StremioC : MainAPI() { return list.distinct() } - override suspend fun load(url: String): LoadResponse? { + override suspend fun load(url: String): LoadResponse { val res = parseJson(url) mainUrl = if ((res.type == "movie" || res.type == "series") && isImdborTmdb(res.id)) cinemataUrl else mainUrl @@ -161,7 +162,7 @@ class StremioC : MainAPI() { return entries } - suspend fun toHomePageList(provider: StremioC): HomePageList? { + suspend fun toHomePageList(provider: StremioC): HomePageList { val entries = mutableListOf() types.forEach { type -> val json = request("${provider.mainUrl}/catalog/${type}/${id}.json").body.string() @@ -211,7 +212,7 @@ class StremioC : MainAPI() { } suspend fun toLoadResponse(provider: StremioC, imdbId: String?): LoadResponse { - if (videos == null || videos.isEmpty()) { + if (videos.isNullOrEmpty()) { return provider.newMovieLoadResponse( name, "${provider.mainUrl}/meta/${type}/${id}.json", @@ -226,6 +227,7 @@ class StremioC : MainAPI() { tags = genre ?: genres addActors(cast) addTrailer(trailersSources?.map { "https://www.youtube.com/watch?v=${it.source}" }?.randomOrNull()) + addImdbId(imdbId) } } else { return provider.newTvSeriesLoadResponse( @@ -244,6 +246,7 @@ class StremioC : MainAPI() { tags = genre ?: genres addActors(cast) addTrailer(trailersSources?.map { "https://www.youtube.com/watch?v=${it.source}" }?.randomOrNull()) + addImdbId(imdbId) } } @@ -337,7 +340,7 @@ class StremioC : MainAPI() { val resp = app.get(TRACKER_LIST_URL).text val otherTrackers = resp .split("\n") - .filterIndexed { i, s -> i % 2 == 0 } + .filterIndexed { i, _ -> i % 2 == 0 } .filter { s -> s.isNotEmpty() }.joinToString("") { "&tr=$it" } val sourceTrackers = sources diff --git a/StremioX/src/main/kotlin/com/hexated/StremioX.kt b/StremioX/src/main/kotlin/com/hexated/StremioX.kt index 339c5277..7f2419fe 100644 --- a/StremioX/src/main/kotlin/com/hexated/StremioX.kt +++ b/StremioX/src/main/kotlin/com/hexated/StremioX.kt @@ -4,6 +4,8 @@ import com.fasterxml.jackson.annotation.JsonProperty import com.hexated.SubsExtractors.invokeOpenSubs import com.hexated.SubsExtractors.invokeWatchsomuch import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.LoadResponse.Companion.addImdbId +import com.lagradost.cloudstream3.LoadResponse.Companion.addTMDbId import com.lagradost.cloudstream3.LoadResponse.Companion.addTrailer import com.lagradost.cloudstream3.utils.* import com.lagradost.cloudstream3.utils.AppUtils.parseJson @@ -123,7 +125,8 @@ open class StremioX : MainAPI() { val title = res.title ?: res.name ?: return null val poster = getOriImageUrl(res.posterPath) val bgPoster = getOriImageUrl(res.backdropPath) - val year = (res.releaseDate ?: res.firstAirDate)?.split("-")?.first()?.toIntOrNull() + val releaseDate = res.releaseDate ?: res.firstAirDate + val year = releaseDate?.split("-")?.first()?.toIntOrNull() val rating = res.vote_average.toString().toRatingInt() val genres = res.genres?.mapNotNull { it.name } val isAnime = @@ -155,7 +158,7 @@ open class StremioX : MainAPI() { eps.seasonNumber, eps.episodeNumber ).toJson(), - name = eps.name, + name = eps.name + if (isUpcoming(eps.airDate)) " - [UPCOMING]" else "", season = eps.seasonNumber, episode = eps.episodeNumber, posterUrl = getImageUrl(eps.stillPath), @@ -179,6 +182,8 @@ open class StremioX : MainAPI() { this.recommendations = recommendations this.actors = actors addTrailer(trailer) + addTMDbId(data.id.toString()) + addImdbId(res.external_ids?.imdb_id) } } else { newMovieLoadResponse( @@ -188,6 +193,7 @@ open class StremioX : MainAPI() { LoadData(res.external_ids?.imdb_id).toJson() ) { this.posterUrl = poster + this.comingSoon = isUpcoming(releaseDate) this.backgroundPosterUrl = bgPoster this.year = year this.plot = res.overview @@ -197,6 +203,8 @@ open class StremioX : MainAPI() { this.recommendations = recommendations this.actors = actors addTrailer(trailer) + addTMDbId(data.id.toString()) + addImdbId(res.external_ids?.imdb_id) } } } diff --git a/StremioX/src/main/kotlin/com/hexated/Utils.kt b/StremioX/src/main/kotlin/com/hexated/Utils.kt index e75201fd..a75987a5 100644 --- a/StremioX/src/main/kotlin/com/hexated/Utils.kt +++ b/StremioX/src/main/kotlin/com/hexated/Utils.kt @@ -1,9 +1,12 @@ package com.hexated +import com.lagradost.cloudstream3.APIHolder import com.lagradost.nicehttp.Requests.Companion.await import okhttp3.OkHttpClient import okhttp3.Request import okhttp3.Response +import java.text.SimpleDateFormat +import java.util.Locale import java.util.concurrent.TimeUnit const val defaultTimeOut = 30L @@ -54,6 +57,13 @@ fun getEpisodeSlug( } } +fun isUpcoming(dateString: String?): Boolean { + if (dateString == null) return false + val format = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()) + val dateTime = format.parse(dateString)?.time ?: return false + return APIHolder.unixTimeMS < dateTime +} + fun fixUrl(url: String, domain: String): String { if (url.startsWith("http")) { return url