TMDbLib Documentation

repository·master·Indexed 19 days ago

https://github.com/jellyfin/tmdblib

A .NET wrapper for the TMDb (The Movie Database) v3 API. TMDbLib provides strongly-typed access to movie, person, and collection data, featuring an asynchronous API and flag-based enums for requesting additional data like credits and videos.

Tokens
1.2K
Snippets
5
Records
6
Agent score
15%

What's inside TMDbLib

  1. TMDbLib usage tips and patterns

    master

    When using TMDbLib, keep the following patterns in mind:

    • Asynchronous API: All library methods are async and must be awaited.
    • Naming Convention: Methods are named predictably based on the resource, e.g., GetMovieAsync, GetPersonAsync.
    • Flag-based Enums: Most method enums use the [Flags] attribute, allowing you to combine multiple options using the bitwise OR operator (|).
    • Lazy Data Loading: TMDb returns minimal data by default. Properties like Credits or Videos will be null unless you explicitly request them via method enums (e.g., MovieMethods.Credits).
  2. Search for movies

    master

    Use SearchMovieAsync to find movies based on a search string. This returns a search results object containing a list of results and the total count found.

    using TMDbLib.Client;
    using TMDbLib.Objects.General;
    using TMDbLib.Objects.Search;
    
    var client = new TMDbClient("APIKey");
    var results = await client.SearchMovieAsync("007");
    
    Console.WriteLine($"Got {results.Results.Count:N0} of {results.TotalResults:N0} results");
    
    foreach (var result in results.Results)
        Console.WriteLine(result.Title);
  3. Get basic movie information

    master

    Initialize a TMDbClient with your API key and use GetMovieAsync with a movie ID to retrieve basic movie details. By default, TMDb returns minimal data, so most properties will be null unless specifically requested.

    using TMDbLib.Client;
    
    var client = new TMDbClient("APIKey");
    var movie = await client.GetMovieAsync(47964);
    
    Console.WriteLine($"Movie name: {movie.Title}");
  4. Work with movie collections

    master

    You can search for collections using SearchCollectionAsync and then retrieve the full collection details (including its parts/movies) using GetCollectionAsync with the collection's ID.

    using TMDbLib.Client;
    using TMDbLib.Objects.Collections;
    using TMDbLib.Objects.General;
    using TMDbLib.Objects.Search;
    
    var client = new TMDbClient("APIKey");
    var collections = await client.SearchCollectionAsync("James Bond");
    
    Console.WriteLine($"Got {collections.Results.Count:N0} collections");
    
    var jamesBond = await client.GetCollectionAsync(collections.Results.First().Id);
    Console.WriteLine($"Collection: {jamesBond.Name}");
    Console.WriteLine($"Got {jamesBond.Parts.Count:N0} James Bond movies");
    
    foreach (var part in jamesBond.Parts)
        Console.WriteLine(part.Title);
  5. Fetch additional movie data using MovieMethods

    master

    To avoid multiple API calls, you can fetch extra information (like credits or videos) in a single request by passing bitwise flags from the MovieMethods enum to GetMovieAsync.

    Note: Most properties on the returned object will remain null unless you explicitly request them using these flags.

    using TMDbLib.Client;
    using TMDbLib.Objects.Movies;
    
    var client = new TMDbClient("APIKey");
    // Use bitwise OR (|) to combine flags
    var movie = await client.GetMovieAsync(47964, MovieMethods.Credits | MovieMethods.Videos);
    
    Console.WriteLine($"Movie title: {movie.Title}");
    
    foreach (var cast in movie.Credits.Cast)
        Console.WriteLine($"{cast.Name} - {cast.Character}");
    
    Console.WriteLine();
    
    foreach (var video in movie.Videos.Results)
        Console.WriteLine($"Trailer: {video.Type} ({video.Site}), {video.Name}");