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) {
|
return if (isTvSeries) {
|
||||||
val contentRatings = tmdb.tvService().content_ratings(id).awaitResponse().body()
|
val contentRatings = tmdb.tvService().content_ratings(id).awaitResponse().body()
|
||||||
contentRatings?.results
|
contentRatings?.results
|
||||||
?.find { it.iso_3166_1 == country }
|
?.find { it: ContentRating ->
|
||||||
?.rating
|
it.iso_3166_1 == country
|
||||||
|
}?.rating
|
||||||
} else {
|
} else {
|
||||||
val releaseDates = tmdb.moviesService().releaseDates(id).awaitResponse().body()?.results
|
val releaseDates = tmdb.moviesService().releaseDates(id).awaitResponse().body()?.results
|
||||||
val certification = findFirstNonEmptyCertificationWithCountry(releaseDates, country)
|
val certification = releaseDates?.firstOrNull { it: ReleaseDatesResult ->
|
||||||
if (!certification.isNullOrEmpty()) {
|
it.iso_3166_1 == country
|
||||||
certification
|
}?.release_dates?.firstOrNull { it: ReleaseDate ->
|
||||||
} else {
|
!it.certification.isNullOrBlank()
|
||||||
null
|
}?.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.
|
// Possible to add recommendations and such here.
|
||||||
override suspend fun load(url: String): LoadResponse? {
|
override suspend fun load(url: String): LoadResponse? {
|
||||||
// https://www.themoviedb.org/movie/7445-brothers
|
// https://www.themoviedb.org/movie/7445-brothers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue