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 c5b4d453..5ff3e74e 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TmdbProvider.kt @@ -1,17 +1,47 @@ package com.lagradost.cloudstream3.metaproviders import com.fasterxml.jackson.annotation.JsonProperty -import com.lagradost.cloudstream3.* +import com.lagradost.cloudstream3.Actor +import com.lagradost.cloudstream3.ErrorLoadingException +import com.lagradost.cloudstream3.HomePageList +import com.lagradost.cloudstream3.HomePageResponse +import com.lagradost.cloudstream3.LoadResponse 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.MainAPI +import com.lagradost.cloudstream3.MainPageRequest +import com.lagradost.cloudstream3.MovieLoadResponse +import com.lagradost.cloudstream3.MovieSearchResponse +import com.lagradost.cloudstream3.ProviderType +import com.lagradost.cloudstream3.SearchResponse +import com.lagradost.cloudstream3.TvSeriesLoadResponse +import com.lagradost.cloudstream3.TvSeriesSearchResponse +import com.lagradost.cloudstream3.TvType +import com.lagradost.cloudstream3.argamap +import com.lagradost.cloudstream3.newEpisode +import com.lagradost.cloudstream3.newHomePageResponse +import com.lagradost.cloudstream3.newMovieLoadResponse +import com.lagradost.cloudstream3.newMovieSearchResponse +import com.lagradost.cloudstream3.newTvSeriesLoadResponse +import com.lagradost.cloudstream3.newTvSeriesSearchResponse import com.lagradost.cloudstream3.utils.AppUtils.toJson import com.uwetrottmann.tmdb2.Tmdb -import com.uwetrottmann.tmdb2.entities.* +import com.uwetrottmann.tmdb2.entities.AppendToResponse +import com.uwetrottmann.tmdb2.entities.BaseMovie +import com.uwetrottmann.tmdb2.entities.BaseTvShow +import com.uwetrottmann.tmdb2.entities.CastMember +import com.uwetrottmann.tmdb2.entities.ContentRating +import com.uwetrottmann.tmdb2.entities.Movie +import com.uwetrottmann.tmdb2.entities.ReleaseDate +import com.uwetrottmann.tmdb2.entities.ReleaseDatesResult +import com.uwetrottmann.tmdb2.entities.TvSeason +import com.uwetrottmann.tmdb2.entities.TvShow +import com.uwetrottmann.tmdb2.entities.Videos import com.uwetrottmann.tmdb2.enumerations.AppendToResponseItem import com.uwetrottmann.tmdb2.enumerations.VideoType import retrofit2.awaitResponse -import java.util.* +import java.util.Calendar /** * episode and season starting from 1 @@ -54,36 +84,37 @@ open class TmdbProvider : MainAPI() { } private fun BaseTvShow.toSearchResponse(): TvSeriesSearchResponse { - return TvSeriesSearchResponse( - this.name ?: this.original_name, - getUrl(id, true), - apiName, - TvType.TvSeries, - getImageUrl(this.poster_path), - this.first_air_date?.let { + return newTvSeriesSearchResponse( + name = this.name ?: this.original_name, + url = getUrl(id, true), + type = TvType.TvSeries, + fix = false + ) { + this.id = this@toSearchResponse.id + this.posterUrl = getImageUrl(poster_path) + this.year = first_air_date?.let { Calendar.getInstance().apply { time = it }.get(Calendar.YEAR) - }, - null, - this.id - ) + } + } } private fun BaseMovie.toSearchResponse(): MovieSearchResponse { - return MovieSearchResponse( - this.title ?: this.original_title, - getUrl(id, false), - apiName, - TvType.TvSeries, - getImageUrl(this.poster_path), - this.release_date?.let { + return newMovieSearchResponse( + name = this.title ?: this.original_title, + url = getUrl(id, false), + type = TvType.Movie, + fix = false + ) { + this.id = this@toSearchResponse.id + this.posterUrl = getImageUrl(poster_path) + this.year = release_date?.let { Calendar.getInstance().apply { time = it }.get(Calendar.YEAR) - }, - this.id, - ) + } + } } private fun List?.toActors(): List>? { @@ -99,34 +130,36 @@ open class TmdbProvider : MainAPI() { val episodes = this.seasons?.filter { !disableSeasonZero || (it.season_number ?: 0) != 0 } ?.mapNotNull { season -> season.episodes?.map { episode -> - Episode( + newEpisode( TmdbLink( episode.external_ids?.imdb_id ?: this.external_ids?.imdb_id, this.id, episode.episode_number, episode.season_number, this.name ?: this.original_name, - ).toJson(), - episode.name, - episode.season_number, - episode.episode_number, - getImageUrl(episode.still_path), - episode.rating, - episode.overview, - episode.air_date?.time, - ) + ).toJson() + ) { + this.name = episode.name + this.season = episode.season_number + this.episode = episode.episode_number + this.rating = episode.rating + this.description = episode.overview + this.date = episode.air_date?.time + this.posterUrl = getImageUrl(episode.still_path) + } } ?: (1..(season.episode_count ?: 1)).map { episodeNum -> - Episode( - episode = episodeNum, - data = TmdbLink( + newEpisode( + TmdbLink( this.external_ids?.imdb_id, this.id, episodeNum, season.season_number, this.name ?: this.original_name, - ).toJson(), - season = season.season_number - ) + ).toJson() + ) { + this.episode = episodeNum + this.season = season.season_number + } } }?.flatten() ?: listOf() @@ -242,7 +275,7 @@ open class TmdbProvider : MainAPI() { } ) - return HomePageResponse( + return newHomePageResponse( listOf( // HomePageList("Popular Series", popularSeries), // HomePageList("Popular Movies", popularMovies), @@ -368,9 +401,7 @@ open class TmdbProvider : MainAPI() { val details = tmdb.tvService().tv(id, "en-US").awaitResponse().body() loadFromImdb(it, details?.seasons ?: listOf()) ?: loadFromTmdb(id, details?.seasons ?: listOf()) - } else { - fromImdb - } + } else fromImdb result } @@ -387,4 +418,4 @@ open class TmdbProvider : MainAPI() { it.movie?.toSearchResponse() ?: it.tvShow?.toSearchResponse() } } -} +} \ No newline at end of file diff --git a/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TraktProvider.kt b/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TraktProvider.kt index a1b9ff34..f84f0929 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TraktProvider.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/metaproviders/TraktProvider.kt @@ -25,6 +25,7 @@ import com.lagradost.cloudstream3.app import com.lagradost.cloudstream3.base64Decode import com.lagradost.cloudstream3.mainPageOf import com.lagradost.cloudstream3.mvvm.logError +import com.lagradost.cloudstream3.newEpisode import com.lagradost.cloudstream3.newHomePageResponse import com.lagradost.cloudstream3.newMovieLoadResponse import com.lagradost.cloudstream3.newMovieSearchResponse @@ -228,16 +229,15 @@ open class TraktProvider : MainAPI() { ).toJson() episodes.add( - Episode( - data = linkData.toJson(), - name = episode.title, - season = episode.season, - episode = episode.number, - posterUrl = fixPath(episode.images?.screenshot?.firstOrNull()), - rating = episode.rating?.times(10)?.roundToInt(), - description = episode.overview, - runTime = episode.runtime - ).apply { + newEpisode(linkData.toJson()) { + this.name = episode.title + this.season = episode.season + this.episode = episode.number + this.description = episode.overview + this.runTime = episode.runtime + this.posterUrl = fixPath(episode.images?.screenshot?.firstOrNull()) + this.rating = episode.rating?.times(10)?.roundToInt() + this.addDate(episode.firstAired, "yyyy-MM-dd'T'HH:mm:ss.SSSXXX") if (nextAir == null && this.date != null && this.date!! > unixTimeMS && this.season != 0) { nextAir = NextAiring( diff --git a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt index 50dd667b..fbd36bf7 100644 --- a/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt +++ b/library/src/commonMain/kotlin/com/lagradost/cloudstream3/MainAPI.kt @@ -978,7 +978,7 @@ data class TvSeriesSearchResponse( override var type: TvType? = null, override var posterUrl: String? = null, - val year: Int? = null, + var year: Int? = null, val episodes: Int? = null, override var id: Int? = null, override var quality: SearchQuality? = null, @@ -2002,4 +2002,4 @@ enum class TrackerType { } } } -} +} \ No newline at end of file