Remove manual isTvSeries check

This commit is contained in:
Luna712 2023-10-24 12:49:34 -06:00
parent 97dedd6859
commit dc010bf034

View file

@ -152,7 +152,7 @@ open class TmdbProvider : MainAPI() {
?: this@toLoadResponse.similar)?.results?.map { it.toSearchResponse() } ?: this@toLoadResponse.similar)?.results?.map { it.toSearchResponse() }
addActors(credits?.cast?.toList().toActors()) addActors(credits?.cast?.toList().toActors())
contentRating = fetchContentRating(id, "US", true) contentRating = fetchContentRating(id, "US")
} }
} }
@ -196,7 +196,7 @@ open class TmdbProvider : MainAPI() {
?: this@toLoadResponse.similar)?.results?.map { it.toSearchResponse() } ?: this@toLoadResponse.similar)?.results?.map { it.toSearchResponse() }
addActors(credits?.cast?.toList().toActors()) addActors(credits?.cast?.toList().toActors())
contentRating = fetchContentRating(id, "US", false) contentRating = fetchContentRating(id, "US")
} }
} }
@ -268,14 +268,14 @@ open class TmdbProvider : MainAPI() {
return null return null
} }
open suspend fun fetchContentRating(id: Int?, country: String, isTvSeries: Boolean): String? { open suspend fun fetchContentRating(id: Int?, country: String): String? {
id ?: return null id ?: return null
return if (isTvSeries) {
val contentRatings = tmdb.tvService().content_ratings(id).awaitResponse().body() val contentRatings = tmdb.tvService().content_ratings(id).awaitResponse().body()?.results
contentRatings?.results return if (!contentRatings.isNullOrEmpty()) {
?.find { it: ContentRating -> contentRatings.firstOrNull { it: ContentRating ->
it.iso_3166_1 == country it.iso_3166_1 == country
}?.rating }?.rating
} else { } else {
val releaseDates = tmdb.moviesService().releaseDates(id).awaitResponse().body()?.results val releaseDates = tmdb.moviesService().releaseDates(id).awaitResponse().body()?.results
val certification = releaseDates?.firstOrNull { it: ReleaseDatesResult -> val certification = releaseDates?.firstOrNull { it: ReleaseDatesResult ->