A simple and lightweight library that wraps The Movie Database api and makes it super easy to get movie/tv/actor data and more.
Via Package Manager:
Install-Package TMdbEasy
Via .NET CLI
dotnet add package TMdbEasy
If your application uses an IOC container then the simplest and advised way to set up TmdbEasy is to register all the key services with the IOC container. TmdbEasy also works just fine with apps that don't use an IOC container.
TmdbEasy comes with baked in support for ASP.NET Core's default IOC container via an extension method called AddTmdbEasy()
.
Using the method as shown below will register all the required TmdbEasy services for you.
public void ConfigureServices(IServiceCollection services)
{
// Typically get these options from IConfiguration, Environment variables etc
var options = new TmdbEasyOptions();
// Adds TmdbEasy to your app
services.AddTmdbEasy(options);
}
The AddTmdbEasy()
method accepts an immutable options parameter that allows configuration of TmdbEasy at a global level.
public TmdbEasyOptions(string apiKey = null, bool useSsl = true, string defaultLanguage = "en", IJsonDeserializer customJsonSerializer = null)
{
ApiKey = apiKey;
UseSsl = useSsl;
DefaultLanguage = defaultLanguage;
JsonDeserializer = customJsonSerializer ?? new NewtonSoftDeserializer();
}
All requests will default to using the apiKey
and language
properties set at this level. This can however be overriden on a per request basis, should your app opt to use different api keys/languages for different users.
Newtonsoft is used by default for the deserialization of all http responses.
If for whatever reason, you wish to use a different JSON deserializer with TmdbEasy, this can be done easily by providing a new instance of IJsonDeserializer
on the options.
As of v1 the following services are supported. We aim to add more over the coming months.
- IMovieApi
- IConfigApi
- IReviewApi
- IChangesApi
- ICompaniesApi
- ICollectionApi
- ICreditApi
- INetworksApi
- ITelevisionApi
We have attempted to mirror the TMDb api as closely as possible and believe the methods are super simple to use. There really isn't that much to say. Inject the service api of your choice and off you go. Lets look at a few examples:
Inject the IMovieApi
into a controller and find a specific movie
public class MovieController : Controller
{
private readonly IMovieApi _movieApi;
public HomeController(IMovieApi movieApi)
{
_movieApi = movieApi;
}
public async Task<IActionResult> Index()
{
int movieId = 550; //taken from the UI or wherever
var movie = await _movieApi.GetDetailsAsync(movieId);
return View(movie);
}
}
This time we override the default apiKey
and language
.
public class MovieController : Controller
{
private readonly IMovieApi _movieApi;
public HomeController(IMovieApi movieApi)
{
_movieApi = movieApi;
}
public async Task<IActionResult> Index()
{
int movieId = 550; //taken from the UI or wherever
string apiKey = "xyz123"; // tyically you'd get this from the HttpContext or Database etc
string language = "en"; // get the users chosen language from somewhere or set a default
var movie = await _movieApi.GetDetailsAsync(movieId, language, apiKey);
return View(movie);
}
}
Lets try a console app.
// configure the library
var options = new TmdbEasyOptions();
var client = new tmdbEasyClient(options);
// Get an endpoint
var movieApi = new MovieApi(client);
// Get the data
var jobs = await movieApi.GetJobsAsync();
- Fork the repo
- Create an account on the (The Movie DB - https://www.themoviedb.org/)
- Get a free Api Key under Profile & Settings -> Settings -> API -> API KEY (v3 auth)
- Add the key as an environment variable on your machine with the name
tmdbapikey
(you'll need this to run integration tests) - Make changes and test (update tests appropriately)
- Submit a PR
Copyright © Tony Karalis and contributors.
TmdbEasy is provided as-is under the MIT license. For more information see LICENSE.
All film-related data and metadata gathered via this library is supplied by The Movie Database (TMDb). TmdbEasy uses the TMDb API but is not endorsed or certified in any way by TMDb.