mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Use firstOrNull
This commit is contained in:
parent
69a4b3c318
commit
a43bc28f92
1 changed files with 10 additions and 35 deletions
|
@ -273,46 +273,21 @@ open class TmdbProvider : MainAPI() {
|
|||
return if (isTvSeries) {
|
||||
val contentRatings = tmdb.tvService().content_ratings(id).awaitResponse().body()
|
||||
contentRatings?.results
|
||||
?.find { it.iso_3166_1 == country }
|
||||
?.rating
|
||||
?.find { it: ContentRating ->
|
||||
it.iso_3166_1 == country
|
||||
}?.rating
|
||||
} else {
|
||||
val releaseDates = tmdb.moviesService().releaseDates(id).awaitResponse().body()?.results
|
||||
val certification = findFirstNonEmptyCertificationWithCountry(releaseDates, country)
|
||||
if (!certification.isNullOrEmpty()) {
|
||||
certification
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val certification = releaseDates?.firstOrNull { it: ReleaseDatesResult ->
|
||||
it.iso_3166_1 == country
|
||||
}?.release_dates?.firstOrNull { it: ReleaseDate ->
|
||||
!it.certification.isNullOrBlank()
|
||||
}?.certification
|
||||
|
||||
certification
|
||||
}
|
||||
}
|
||||
|
||||
private fun findFirstNonEmptyCertificationWithCountry(
|
||||
releaseDatesResults: List<ReleaseDatesResult>?,
|
||||
country: String
|
||||
): String? {
|
||||
for (releaseDateResult in releaseDatesResults.orEmpty()) {
|
||||
if (releaseDateResult.iso_3166_1 == country) {
|
||||
val certification = findFirstNonEmptyCertification(releaseDateResult.release_dates)
|
||||
if (!certification.isNullOrEmpty()) {
|
||||
return certification
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
private fun findFirstNonEmptyCertification(releaseDates: List<ReleaseDate>?): String? {
|
||||
for (releaseDate in releaseDates.orEmpty()) {
|
||||
val certification = releaseDate.certification
|
||||
if (!certification.isNullOrBlank()) {
|
||||
return certification
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
// Possible to add recommendations and such here.
|
||||
override suspend fun load(url: String): LoadResponse? {
|
||||
// https://www.themoviedb.org/movie/7445-brothers
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue