This Kotlin Multiplatform library is for accessing the TMDB API to get movie and TV show content. Using for Android, iOS, and JS projects.

Overview

Website | Forum | Documentation | TMDb 3 API

TMDb

Get movie and TV show content from TMDb in a fast and simple way.

Maven Central Build Status Issues Kotlin Gradle GitHub License


TMDb API

This library gives access to TMDb API version 3 and 4 for mobile, desktop, and web applications. It supports Swift, Kotlin, and JavaScript by setting up as a Kotlin Multiplatform project.

This library is mainly used and supported by Moviebase.

Adding to your project

The library is available on Maven Central.

Gradle

Add the Maven Central repository if it is not already there.

repositories {
    mavenCentral()
}

To use the library in a single-platform project, add a dependency.

dependencies {
    implementation("app.moviebase:tmdb-api:0.5.0")
}

In Kotlin Multiplatform projects, add the dependency to your commonMain source-set dependencies.

commonMain {
    dependencies {
        implementation("app.moviebase:tmdb-api:0.5.0")
    }
}

Maven

Add a dependency to the element.

<dependency>
    <groupId>app.moviebasegroupId>
    <artifactId>tmdb-apiartifactId>
    <version>0.5.0version>
dependency>

Usage

Most of the library follows the possibilities and naming at the official TMDb documentation.

The documentation of the endpoints can be found in Version 3 and Version 4.

Get information

For getting basic information about a movie or other media content.

val tmdb = Tmdb3("apiKey")
val movieDetail = tmdb.movies.getDetails(
    movieId = 12,
    language = "DE",
    appendResponses = listOf(AppendResponse.MOVIE_CREDITS)
)

Search

Search for TV shows by a query.

val tmdb = Tmdb3("apiKey")
val showPageResult = tmdb.search.findShows(
    query = "The Expanse",
    page = 1,
    language = "DE",
    region = "US",
    includeAdult = false
)

Discover

Discover a movie or TV show by the discover parameter class.

val discover = TmdbDiscover.Movie(
    sortBy = TmdbDiscoverMovieSortBy.POPULARITY,
    sortOrder = TmdbSortOrder.DESC,
    voteAverageGte = 5,
    voteCountGte = 200,
    releaseDate = TmdbDiscoverTimeRange.BetweenYears(from = 2020, to = 2021)
)

val discoverPageResult = tmdb.discover.discoverMovie(
    page = 1,
    region = "DE",
    language = "de",
    discover = discover
)

Alternatively, use predefined discover categories like upcoming, networks or on streaming.

val discoverCategory = DiscoverCategory.OnStreaming.Netflix(
    mediaType = TmdbMediaType.MOVIE,
    watchRegion = "DE"
)

val result = tmdb.discover.discoverByCategory(
    page = 1,
    region = "DE",
    language = "de",
    category = discoverCategory
)

Build image URL

You can build an image URL via the poster file path and size key. More information on the TMDb images site.

val url = TmdbImageUrlBuilder.build("nBNZadXqJSdt05SHLqgT0HuC5Gm.jpg", "w154")

Or create the URL by an image class with the best matched width/height.

val url = TmdbImageUrlBuilder.build(image = movie.posterImage, width = 200, height = 300)

For creating the poster URL by the movie item.

val url = TmdbImageUrlBuilder.buildPoster(item = movie, width = 200)


This library uses the TMDb but is not endorsed or certified by TMDb. These services are licensed under CC BY-NC 4.0.

Comments
  • MissingFieldException: 'known_for_department'

    MissingFieldException: 'known_for_department'

    I'm getting an exception with v0.6.3 when calling Tmdb3.find.find("tt11271038", "en", TmdbExternalSource.IMDB)

    Stacktrace:

        kotlinx.serialization.MissingFieldException: 
         Field 'known_for_department' is required for type with serial name 'app.moviebase.tmdb.model.TmdbCrew', but it was missing
            at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20)
            at app.moviebase.tmdb.model.TmdbCrew.<init>(TmdbPeopleModel.kt:115)
            at app.moviebase.tmdb.model.TmdbCrew$$serializer.deserialize(TmdbPeopleModel.kt:115)
            at app.moviebase.tmdb.model.TmdbCrew$$serializer.deserialize(TmdbPeopleModel.kt:115)
    
    
    bug 
    opened by edmundjohnson 3
  • TmdbVideoType does not contain element with name 'Bloopers'

    TmdbVideoType does not contain element with name 'Bloopers'

    Hi, I need some advice I don't know if I'm making a mistake somewhere but, whenever I try to get information about a movie, it throws me a mistake

    Try for example Avengers: Endgame TMDb ID = 299534

    It throws an error: app.moviebase.tmdb.model.TmdbVideoType does not contain element with name 'Bloopers'

    my method is

    `   private suspend fun fetchMovie(movieId: Int): TmdbMovieDetail? {
    
        return try {
            tmdbApi.movies.getDetails(
                movieId,
                "en-US",
                listOf(
                    AppendResponse.EXTERNAL_IDS,
                    AppendResponse.CREDITS,
                    AppendResponse.RELEASES_DATES,
                    AppendResponse.IMAGES,
                    AppendResponse.MOVIE_CREDITS,
                    AppendResponse.VIDEOS,
                    AppendResponse.CONTENT_RATING,
                    AppendResponse.WATCH_PROVIDERS
                )
            )
        } catch (e: ResponseException) {
            if (e.response.status == HttpStatusCode.NotFound) null else throw e
        }
    }
    

    `

    Process: com.octopus.mplay, PID: 25580 kotlinx.serialization.SerializationException: app.moviebase.tmdb.model.TmdbVideoType does not contain element with name 'Bloopers' at kotlinx.serialization.json.internal.JsonNamesMapKt.getJsonNameIndexOrThrow(JsonNamesMap.kt:63) at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeEnum(StreamingJsonDecoder.kt:265) at app.moviebase.tmdb.model.TmdbVideoType$$serializer.deserialize(TmdbModel.kt:108) at app.moviebase.tmdb.model.TmdbVideoType$$serializer.deserialize(TmdbModel.kt:108) at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:59) at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:36) at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) at kotlinx.serialization.encoding.AbstractDecoder.decodeNullableSerializableElement(AbstractDecoder.kt:79) at app.moviebase.tmdb.model.TmdbVideo$$serializer.deserialize(TmdbModel.kt:141) at app.moviebase.tmdb.model.TmdbVideo$$serializer.deserialize(TmdbModel.kt:141) at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:59) at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:36) at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70) at kotlinx.serialization.encoding.CompositeDecoder$DefaultImpls.decodeSerializableElement$default(Decoding.kt:535) at kotlinx.serialization.internal.ListLikeSerializer.readElement(CollectionSerializers.kt:80) at kotlinx.serialization.internal.AbstractCollectionSerializer.readElement$default(CollectionSerializers.kt:51) at kotlinx.serialization.internal.AbstractCollectionSerializer.merge(CollectionSerializers.kt:36) at kotlinx.serialization.internal.AbstractCollectionSerializer.deserialize(CollectionSerializers.kt:43) at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:59) at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:36) at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableElement(AbstractDecoder.kt:70) at app.moviebase.tmdb.model.TmdbResult$$serializer.deserialize(TmdbModel.kt:49) at app.moviebase.tmdb.model.TmdbResult$$serializer.deserialize(TmdbModel.kt:49) at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:59) at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:36) at kotlinx.serialization.encoding.AbstractDecoder.decodeSerializableValue(AbstractDecoder.kt:43) at kotlinx.serialization.encoding.AbstractDecoder.decodeNullableSerializableElement(AbstractDecoder.kt:79) at app.moviebase.tmdb.model.TmdbMovieDetail$$serializer.deserialize(TmdbMovieModel.kt:61) at app.moviebase.tmdb.model.TmdbMovieDetail$$serializer.deserialize(TmdbMovieModel.kt:61) at kotlinx.serialization.json.internal.PolymorphicKt.decodeSerializableValuePolymorphic(Polymorphic.kt:59) at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:36) at kotlinx.serialization.json.Json.decodeFromString(Json.kt:100) at io.ktor.serialization.kotlinx.KotlinxSerializationConverter.deserialize(KotlinxSerializationConverter.kt:55) at io.ktor.client.plugins.contentnegotiation.ContentNegotiation$Plugin$install$2.invokeSuspend(ContentNegotiation.kt:135) at io.ktor.client.plugins.contentnegotiation.ContentNegotiation$Plugin$install$2.invoke(Unknown Source:13) 2022-06-11 22:53:24.305 25580-25616/com.octopus.mplay E/AndroidRuntime: at io.ktor.client.plugins.contentnegotiation.ContentNegotiation$Plugin$install$2.invoke(Unknown Source:6) at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123) at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81) at io.ktor.client.HttpClient$4.invokeSuspend(HttpClient.kt:170) at io.ktor.client.HttpClient$4.invoke(Unknown Source:11) at io.ktor.client.HttpClient$4.invoke(Unknown Source:6) at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123) at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81) at io.ktor.util.pipeline.SuspendFunctionGun.proceedWith(SuspendFunctionGun.kt:91) at io.ktor.client.plugins.HttpCallValidator$Companion$install$2.invokeSuspend(HttpCallValidator.kt:140) at io.ktor.client.plugins.HttpCallValidator$Companion$install$2.invoke(Unknown Source:13) at io.ktor.client.plugins.HttpCallValidator$Companion$install$2.invoke(Unknown Source:6) at io.ktor.util.pipeline.SuspendFunctionGun.loop(SuspendFunctionGun.kt:123) at io.ktor.util.pipeline.SuspendFunctionGun.proceed(SuspendFunctionGun.kt:81) at io.ktor.util.pipeline.SuspendFunctionGun.execute$ktor_utils(SuspendFunctionGun.kt:101) at io.ktor.util.pipeline.Pipeline.execute(Pipeline.kt:77) at io.ktor.client.call.HttpClientCall.body(HttpClientCall.kt:87) at app.moviebase.tmdb.api.TmdbMoviesApi.getDetails(TmdbMoviesApi.kt:61) at app.moviebase.tmdb.api.TmdbMoviesApi$getDetails$1.invokeSuspend(Unknown Source:16) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:571) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)

    opened by ORRNY66 2
  • Crash due to missing gender

    Crash due to missing gender

    When calling:

    Tmdb3.find.find("tt10919380", "en", TmdbExternalSource.IMDB)
    

    I get an error:

    app.moviebase.tmdb.model.TmdbGender does not contain element with name '3'
    

    It would probably be fixed by adding the following to TmdbGender:

    @SerialName("3")
    NON_BINARY(3),
    

    Thank you!

    opened by edmundjohnson 2
  • Feature video url builder

    Feature video url builder

    Create the class TmdbVideoUrlBuilder to provide a method to generate Video URLs from the TmdbVideo entities received from the API.

    The current allowed Videos are from YouTube and Vimeo (From March 23, 2019, as was shown here

    The key value returned on the API represents the platform video ID and the site value the platform itself. A new enum has been created to model the site and depending on it we use a different base URL as is detailed here

    opened by JcMinarro 0
  • Add option to obtain movie's images

    Add option to obtain movie's images

    Current implementation of TmdbMoviesApi::getDetails acceptes a list of AppendResponse but images aren't processed when AppendResponse.IMAGES was included. Now a new field has been added to the TmdbMovieDetail that contains the lists of images from this movie.

    On the other hand, a new standalone method has been created to obtain only images from a movie as is detailed on the Official TMDB docs

    opened by JcMinarro 0
Releases(0.6.7)
Owner
Moviebase
Discover Movies & TV Shows on Android 🚀
Moviebase
API for accessing magtu pairs.

Magtu pairs api. What does it do? Provides easy access to parsed pairs. Makes possible to create your own bot implementations. How to use? Do a reques

Magtu Unofficial 3 Mar 17, 2022
API for accessing magtu pairs.

Magtu pairs api. What does it do? Provides easy access to parsed pairs. Makes possible to create your own bot implementations. How to use? Do a reques

Magtu Unofficial 3 Mar 17, 2022
Therapeutic is a platform to help easily connect patients or generally anyone struggling to get through tough times with motivating content and professional therapists.

Therapeutic Apk - https://github.com/develNerd/Therapeutic/blob/main/androidApp/release/androidApp-release6.apk Therapeutic is a Kotlin Mobile Multipl

Isaac Akakpo 1 Nov 23, 2022
Add page & limit as GET parameter to get all titans data in a paginated format

Add page & limit as GET parameter to get all titans data in a paginated format (default values : page=1 and limit=3). Here the page param is the page number which you require and limit is the maximum number of items per page. Sample Request :

krishna chaitanya 1 Jan 31, 2022
Create libraries for all types of Kotlin projects: android, JVM, Multiplatform, Gradle plugins, and so on.

JavierSC Kotlin template Create libraries for all types of Kotlin projects: android, JVM, Multiplatform, Gradle plugins, and so on. Features Easy to p

Javier Segovia Córdoba 2 Dec 14, 2022
An Android app built with Kotlin, consuming StarWars API to display characters of the popular StarWars Movie. It is built with the MVVM pattern and the latest Jetpack components.

StarWars An Android app built with Kotlin, consuming StarWars API to display characters of the popular StarWars Movie. It is built with the MVVM patte

Joel Kanyi 42 Nov 20, 2022
Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP)

Mockative Mocking for Kotlin/Native and Kotlin Multiplatform using the Kotlin Symbol Processing API (KSP). Installation Mockative uses KSP to generate

Mockative 121 Dec 26, 2022
BooksApp - Show the books list from an API with using retrofit2, picasso and JSON libraries

BooksApp Books App Show the books list from an API with using retrofit2, picasso

null 0 Jan 3, 2022
MMKV for Kotlin Multiplatform is a wrapper for MMKV using Kotlin API

MMKV for Kotlin Multiplatform is a wrapper for MMKV using Kotlin API

Ctrip, Inc. 65 Dec 29, 2022
Learn-kotlin - Learning more about Kotlin in various content

Kotlin study roadmap https://kotlinlang.org/docs/reference/ Getting Started Basi

Danilo Silva 0 Jan 7, 2022
Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Kotlin_practice_problems Repo: Programming problems with solutions in Kotlin to help avid Kotlin learners to get a strong hold on Kotlin programming.

Aman 0 Oct 14, 2021
Kotlin-koans - Kotlin Koans are a series of exercises to get you familiar with the Kotlin Syntax

kotlin-koans-edu Kotlin Koans are a series of exercises to get you familiar with

null 1 Jan 11, 2022
Movie Android App written in Kotlin, MVVM, Clean Architechture, Modularized, Coroutines, Android Architecture Components and Hilt

Movie Android App written in Kotlin, MVVM, Clean Architechture, Modularized, Coroutines, Android Architecture Components and Hilt.

Klejvi Kapaj 16 Dec 27, 2022
💖 "It's showtime!" - Loritta's Content Website

?? Showtime ?? Showtime is Loritta's content website, this project has everything that requires... Server Side Generation, to improve the website SEO.

Loritta 5 Dec 8, 2021
WriterAI is an AI-based content writing tool

WriterAI is an AI-based content writing tool that can turn your unstructured text into engaging content and generate up to 5 different paragraphs with an input of just 5 words! Using the power of artificial intelligence, this tool helps you write an engaging piece of content and end up with something professional. You can use it for writing emails, blogs, articles, letters, thesis and even e-books! It is completely free to use and open-source :)

Vaibhav Jaiswal 21 Dec 26, 2022
TheMovies 🎬 A demo project for The Movie DB based on Kotlin MVVM architecture and material design & animations.

A simple project for The Movie DB based on Kotlin MVVM clean architecture and material design & animations. How to build on your environment

Jaewoong Eum 420 Nov 29, 2022
A simple App which fetches data from NewYork times api and show news to the user

Stay-TheNewsApp This is a simple java app, which fetches data from NewYork times api and show news to the user, News can be seen from various categori

Gautam Garg 0 Dec 7, 2021
Maintenance mode library for spring boot web and security projects.

spring-boot-starter-maintenance spring-boot-starter-maintenance is a maintenance mode library for spring boot web and security projects. Download Grad

Viascom 3 Nov 3, 2022