mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Support showing content ratings for TmdbProvider
This commit is contained in:
parent
c9bffef7cb
commit
69a4b3c318
7 changed files with 71 additions and 0 deletions
|
@ -1193,6 +1193,7 @@ interface LoadResponse {
|
||||||
var syncData: MutableMap<String, String>
|
var syncData: MutableMap<String, String>
|
||||||
var posterHeaders: Map<String, String>?
|
var posterHeaders: Map<String, String>?
|
||||||
var backgroundPosterUrl: String?
|
var backgroundPosterUrl: String?
|
||||||
|
var contentRating: String?
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val malIdPrefix = malApi.idPrefix
|
private val malIdPrefix = malApi.idPrefix
|
||||||
|
@ -1490,6 +1491,7 @@ data class TorrentLoadResponse(
|
||||||
override var syncData: MutableMap<String, String> = mutableMapOf(),
|
override var syncData: MutableMap<String, String> = mutableMapOf(),
|
||||||
override var posterHeaders: Map<String, String>? = null,
|
override var posterHeaders: Map<String, String>? = null,
|
||||||
override var backgroundPosterUrl: String? = null,
|
override var backgroundPosterUrl: String? = null,
|
||||||
|
override var contentRating: String? = null,
|
||||||
) : LoadResponse
|
) : LoadResponse
|
||||||
|
|
||||||
data class AnimeLoadResponse(
|
data class AnimeLoadResponse(
|
||||||
|
@ -1521,6 +1523,7 @@ data class AnimeLoadResponse(
|
||||||
override var nextAiring: NextAiring? = null,
|
override var nextAiring: NextAiring? = null,
|
||||||
override var seasonNames: List<SeasonData>? = null,
|
override var seasonNames: List<SeasonData>? = null,
|
||||||
override var backgroundPosterUrl: String? = null,
|
override var backgroundPosterUrl: String? = null,
|
||||||
|
override var contentRating: String? = null,
|
||||||
) : LoadResponse, EpisodeResponse {
|
) : LoadResponse, EpisodeResponse {
|
||||||
override fun getLatestEpisodes(): Map<DubStatus, Int?> {
|
override fun getLatestEpisodes(): Map<DubStatus, Int?> {
|
||||||
return episodes.map { (status, episodes) ->
|
return episodes.map { (status, episodes) ->
|
||||||
|
@ -1583,6 +1586,7 @@ data class LiveStreamLoadResponse(
|
||||||
override var syncData: MutableMap<String, String> = mutableMapOf(),
|
override var syncData: MutableMap<String, String> = mutableMapOf(),
|
||||||
override var posterHeaders: Map<String, String>? = null,
|
override var posterHeaders: Map<String, String>? = null,
|
||||||
override var backgroundPosterUrl: String? = null,
|
override var backgroundPosterUrl: String? = null,
|
||||||
|
override var contentRating: String? = null,
|
||||||
) : LoadResponse
|
) : LoadResponse
|
||||||
|
|
||||||
data class MovieLoadResponse(
|
data class MovieLoadResponse(
|
||||||
|
@ -1606,6 +1610,7 @@ data class MovieLoadResponse(
|
||||||
override var syncData: MutableMap<String, String> = mutableMapOf(),
|
override var syncData: MutableMap<String, String> = mutableMapOf(),
|
||||||
override var posterHeaders: Map<String, String>? = null,
|
override var posterHeaders: Map<String, String>? = null,
|
||||||
override var backgroundPosterUrl: String? = null,
|
override var backgroundPosterUrl: String? = null,
|
||||||
|
override var contentRating: String? = null,
|
||||||
) : LoadResponse
|
) : LoadResponse
|
||||||
|
|
||||||
suspend fun <T> MainAPI.newMovieLoadResponse(
|
suspend fun <T> MainAPI.newMovieLoadResponse(
|
||||||
|
@ -1730,6 +1735,7 @@ data class TvSeriesLoadResponse(
|
||||||
override var nextAiring: NextAiring? = null,
|
override var nextAiring: NextAiring? = null,
|
||||||
override var seasonNames: List<SeasonData>? = null,
|
override var seasonNames: List<SeasonData>? = null,
|
||||||
override var backgroundPosterUrl: String? = null,
|
override var backgroundPosterUrl: String? = null,
|
||||||
|
override var contentRating: String? = null,
|
||||||
) : LoadResponse, EpisodeResponse {
|
) : LoadResponse, EpisodeResponse {
|
||||||
override fun getLatestEpisodes(): Map<DubStatus, Int?> {
|
override fun getLatestEpisodes(): Map<DubStatus, Int?> {
|
||||||
val maxSeason =
|
val maxSeason =
|
||||||
|
|
|
@ -151,6 +151,8 @@ open class TmdbProvider : MainAPI() {
|
||||||
recommendations = (this@toLoadResponse.recommendations
|
recommendations = (this@toLoadResponse.recommendations
|
||||||
?: 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,6 +195,8 @@ open class TmdbProvider : MainAPI() {
|
||||||
recommendations = (this@toLoadResponse.recommendations
|
recommendations = (this@toLoadResponse.recommendations
|
||||||
?: 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,6 +268,51 @@ open class TmdbProvider : MainAPI() {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open suspend fun fetchContentRating(id: Int?, country: String, isTvSeries: Boolean): String? {
|
||||||
|
id ?: return null
|
||||||
|
return if (isTvSeries) {
|
||||||
|
val contentRatings = tmdb.tvService().content_ratings(id).awaitResponse().body()
|
||||||
|
contentRatings?.results
|
||||||
|
?.find { 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
@ -675,6 +675,7 @@ open class ResultFragmentPhone : FullScreenPlayer() {
|
||||||
resultMetaYear.setText(d.yearText)
|
resultMetaYear.setText(d.yearText)
|
||||||
resultMetaDuration.setText(d.durationText)
|
resultMetaDuration.setText(d.durationText)
|
||||||
resultMetaRating.setText(d.ratingText)
|
resultMetaRating.setText(d.ratingText)
|
||||||
|
resultMetaContentRating.setText(d.contentRatingText)
|
||||||
resultCastText.setText(d.actorsText)
|
resultCastText.setText(d.actorsText)
|
||||||
resultNextAiring.setText(d.nextAiringEpisode)
|
resultNextAiring.setText(d.nextAiringEpisode)
|
||||||
resultNextAiringTime.setText(d.nextAiringDate)
|
resultNextAiringTime.setText(d.nextAiringDate)
|
||||||
|
|
|
@ -780,6 +780,7 @@ class ResultFragmentTv : Fragment() {
|
||||||
resultMetaYear.setText(d.yearText)
|
resultMetaYear.setText(d.yearText)
|
||||||
resultMetaDuration.setText(d.durationText)
|
resultMetaDuration.setText(d.durationText)
|
||||||
resultMetaRating.setText(d.ratingText)
|
resultMetaRating.setText(d.ratingText)
|
||||||
|
resultMetaContentRating.setText(d.contentRatingText)
|
||||||
resultCastText.setText(d.actorsText)
|
resultCastText.setText(d.actorsText)
|
||||||
resultNextAiring.setText(d.nextAiringEpisode)
|
resultNextAiring.setText(d.nextAiringEpisode)
|
||||||
resultNextAiringTime.setText(d.nextAiringDate)
|
resultNextAiringTime.setText(d.nextAiringDate)
|
||||||
|
|
|
@ -100,6 +100,7 @@ data class ResultData(
|
||||||
val plotText: UiText,
|
val plotText: UiText,
|
||||||
val apiName: UiText,
|
val apiName: UiText,
|
||||||
val ratingText: UiText?,
|
val ratingText: UiText?,
|
||||||
|
val contentRatingText: UiText?,
|
||||||
val vpnText: UiText?,
|
val vpnText: UiText?,
|
||||||
val metaText: UiText?,
|
val metaText: UiText?,
|
||||||
val durationText: UiText?,
|
val durationText: UiText?,
|
||||||
|
@ -219,6 +220,7 @@ fun LoadResponse.toResultData(repo: APIRepository): ResultData {
|
||||||
apiName = txt(apiName),
|
apiName = txt(apiName),
|
||||||
ratingText = rating?.div(1000f)
|
ratingText = rating?.div(1000f)
|
||||||
?.let { if (it <= 0.1f) null else txt(R.string.rating_format, it) },
|
?.let { if (it <= 0.1f) null else txt(R.string.rating_format, it) },
|
||||||
|
contentRatingText = txt(contentRating),
|
||||||
vpnText = txt(
|
vpnText = txt(
|
||||||
when (repo.vpnStatus) {
|
when (repo.vpnStatus) {
|
||||||
VPNStatus.None -> null
|
VPNStatus.None -> null
|
||||||
|
|
|
@ -388,6 +388,12 @@
|
||||||
android:id="@+id/result_meta_duration"
|
android:id="@+id/result_meta_duration"
|
||||||
style="@style/ResultInfoText"
|
style="@style/ResultInfoText"
|
||||||
tools:text="121min" />
|
tools:text="121min" />
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/result_meta_content_rating"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
style="@style/SmallBlackButton"
|
||||||
|
tools:text="PG-13" />
|
||||||
</com.lagradost.cloudstream3.widget.FlowLayout>
|
</com.lagradost.cloudstream3.widget.FlowLayout>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
|
|
|
@ -407,6 +407,12 @@ https://developer.android.com/design/ui/tv/samples/jet-fit
|
||||||
android:id="@+id/result_meta_duration"
|
android:id="@+id/result_meta_duration"
|
||||||
style="@style/ResultInfoText"
|
style="@style/ResultInfoText"
|
||||||
tools:text="121min" />
|
tools:text="121min" />
|
||||||
|
|
||||||
|
<com.google.android.material.button.MaterialButton
|
||||||
|
android:id="@+id/result_meta_content_rating"
|
||||||
|
android:layout_gravity="center_vertical"
|
||||||
|
style="@style/SmallWhiteButton"
|
||||||
|
tools:text="PG-13" />
|
||||||
</com.lagradost.cloudstream3.widget.FlowLayout>
|
</com.lagradost.cloudstream3.widget.FlowLayout>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue