From 4120f8b86569539eb6c919256a7c68d2ddf6fe10 Mon Sep 17 00:00:00 2001 From: LagradOst Date: Fri, 4 Feb 2022 22:25:09 +0100 Subject: [PATCH] trailers.to recommendations --- .../metaproviders/TmdbProvider.kt | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt index 4ef7ee29..a2bebe8f 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt @@ -131,14 +131,15 @@ open class TmdbProvider : MainAPI() { this.genres?.mapNotNull { it.name }, this.episode_run_time?.average()?.toInt(), null, - this.recommendations?.results?.map { it.toSearchResponse() } + (this.recommendations ?: this.similar)?.results?.map { it.toSearchResponse() } ) } private fun Movie.toLoadResponse(): MovieLoadResponse { + println("TRAILRES::::::: ${this.similar} :::: ${this.recommendations} ") return MovieLoadResponse( this.title ?: this.original_title, - getUrl(id, true), + getUrl(id, false), this@TmdbProvider.apiName, TvType.Movie, TmdbLink( @@ -160,7 +161,7 @@ open class TmdbProvider : MainAPI() { this.genres?.mapNotNull { it.name }, this.runtime, null, - this.recommendations?.results?.map { it.toSearchResponse() } + (this.recommendations ?: this.similar)?.results?.map { it.toSearchResponse() } ) } @@ -246,10 +247,26 @@ open class TmdbProvider : MainAPI() { return if (useMetaLoadResponse) { return if (isTvSeries) { val body = tmdb.tvService().tv(id, "en-US").awaitResponse().body() - body?.toLoadResponse() + val response = body?.toLoadResponse() + if (response != null && response.recommendations.isNullOrEmpty()) { + tmdb.tvService().recommendations(id, 1,"en-US").awaitResponse().body()?.let { + it.results?.map { res -> res.toSearchResponse() } + }?.let { list -> + response.recommendations = list + } + } + response } else { val body = tmdb.moviesService().summary(id, "en-US").awaitResponse().body() - body?.toLoadResponse() + val response = body?.toLoadResponse() + if (response != null && response.recommendations.isNullOrEmpty()) { + tmdb.moviesService().recommendations(id, 1,"en-US").awaitResponse().body()?.let { + it.results?.map { res -> res.toSearchResponse() } + }?.let { list -> + response.recommendations = list + } + } + response } } else { loadFromTmdb(id)?.let { return it }