All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.app.moviebase.tmdb.url.TmdbUrlBuilder.kt Maven / Gradle / Ivy

The newest version!
package app.moviebase.tmdb.url

import app.moviebase.tmdb.TmdbWebConfig
import app.moviebase.tmdb.model.TmdbMediaType
import app.moviebase.tmdb.model.TmdbVideo
import app.moviebase.tmdb.model.TmdbVideoSite

object TmdbUrlBuilder {

    /**
     * Example: https://www.themoviedb.org/u/msbreviews
     */
    fun buildUserPage(userId: String) = "${TmdbWebConfig.BASE_WEBSITE_URL}/u/$userId"

    /**
     * Example: https://www.themoviedb.org/review/63501e9ed363e5007a664110
     */
    fun buildReviewPage(reviewId: Int) = "${TmdbWebConfig.BASE_WEBSITE_URL}/review/$reviewId"

    /**
     * Example: https://www.themoviedb.org/tv/96677-lupin/watch?locale=AU
     */
    fun buildWatch(mediaType: TmdbMediaType, mediaId: Int, region: String): String {
        require(mediaType == TmdbMediaType.MOVIE || mediaType == TmdbMediaType.SHOW) { "Only movie and tv are supported" }

        val tmdbMediaType = if (mediaType == TmdbMediaType.MOVIE) "movie" else "tv"
        return "${TmdbWebConfig.BASE_WEBSITE_URL}/$tmdbMediaType/$mediaId/watch?locale=$region"
    }

    /**
     * Build the video URL depending on the site the video is from
     */
    fun buildVideo(tmdbVideo: TmdbVideo): String? = when (tmdbVideo.site) {
        TmdbVideoSite.YOUTUBE -> "https://www.youtube.com/watch?v=${tmdbVideo.key}"
        TmdbVideoSite.VIMEO -> "https://vimeo.com/${tmdbVideo.key}"
        else -> null
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy