metaproviders: use new* methods

This commit is contained in:
Luna712 2024-07-26 14:58:23 -06:00 committed by GitHub
parent 2fc279f4ae
commit 70190f79c0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 88 additions and 57 deletions

View file

@ -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<CastMember?>?.toActors(): List<Pair<Actor, String?>>? {
@ -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()
}
}
}
}

View file

@ -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(

View file

@ -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 {
}
}
}
}
}