TheMovieDbWrapper is a C# wrapper for TheMovieDb.org API providing cross-platform support for Xamarin, iOS, Android, and all flavors of .NET.
In the Nuget package manager UI, search for: TheMovieDbWrapper and then click the install button.
PM> Install-Package TheMovieDbWrapper
> dotnet add package TheMovieDbWrapper
The v1.0 release on 2021-10-27 introduces a minor breaking change when
registering your TheMovieDb.org credentials with our MovieDbFactory.
IMovieDbSettings
has been completely eliminated and simplifies the process of registering your credentials.
The current release supports common requests for movie, tv, and other information, such as:
The MovieDbFactory
class is the single entry point for retrieving information from TheMovieDb.org API. Before making any requests, you must register your TheMovieDb.org Bearer Token with our MovieDbFactory
class:
// your bearer token can be found on TheMovieDb.org's website under your account settings
// https://www.themoviedb.org/settings/api
string bearerToken = "your-bearer-token-from-TheMovieDb.org";
// RegisterSettings only needs to be called one time when your application starts-up.
MovieDbFactory.RegisterSettings( bearerToken );
Once your Bearer Token has been registered, you will then use the .Create<T>()
method to get a specific API request type. The full signature of the method is:
Lazy<T> MovieDbFactory.Create<T>() where T : IApiRequest
The IApiRequest
is a basic Interface providing a constraint for all our request interfaces/classes used in the factory. For example, to retrieve the API for movies:
// as the factory returns a Lazy<T> instance, just grab the Value from the Lazy<T>
// and assign to a local variable.
var movieApi = MovieDbFactory.Create<IApiMovieRequest>().Value;
The following interfaces are used with the MovieDbFactory.Create<T>()
method:
IApiRequest | Description |
---|---|
IApiConfigurationRequest |
Api for retrieving TheMovieDb.org configuration information. |
IApiMovieRequest |
Api for retrieving Movies. |
IApiMovieRatingRequest |
Api for retrieving movie ratings. |
IApiTVShowRequest |
Api for retrieving TV shows. |
IApiGenreRequest |
Api for retrieving Movie and TV genres. |
IApiCompanyRequest |
Api for retrieving production companies. |
IApiProfessionRequest |
Api for retrieving Movie/TV industry specific professions. |
IApiPeopleRequest |
Api for retrieving People. |
IApiDiscoverRequest |
Api for discovering movies. |
string bearerToken = "your-bearer-token-from-TheMovieDb.org";
// RegisterSettings only needs to be called one time when your application starts-up.
MovieDbFactory.RegisterSettings( bearerToken );
var movieApi = MovieDbFactory.Create<IApiMovieRequest>().Value;
ApiSearchResponse<MovieInfo> response = await movieApi.SearchByTitleAsync( "Star Trek" );
foreach( MovieInfo info in response.Results )
{
Console.WriteLine( $"{info.Title} ({info.ReleaseDate}): {info.Overview}" );
}
The above example returns an ApiSearchResponse<T>
which provides rich information about the results of your search, including the following:
Member | Type | Description |
---|---|---|
Results | IReadOnlyList<T> |
The list of results from the search. |
PageNumber | int |
The current page number of the search result. |
TotalPages | int |
The total number of pages found from the search result. |
TotalResults | int |
The total number of results from the search. |
ToString() | string |
Returns Page x of y (z total results) . |
Error | ApiError |
Contains specific error information if an error was encountered during the API call to TheMovieDb.org. |
RateLimit | ApiRateLimit |
Contains the current rate limits from your most recent API call to TheMovieDb.org. Note: TheMovieDb.org has removed all rate limits as of December of 2019. |
string bearerToken = "your-bearer-token-from-TheMovieDb.org";
// RegisterSettings only needs to be called one time when your application starts-up.
MovieDbFactory.RegisterSettings( bearerToken );
var movieApi = MovieDbFactory.Create<IApiMovieRequest>().Value;
ApiQueryResponse<Movie> response = await movieApi.FindByIdAsync( 140607 );
Movie movie = response.Item;
Console.WriteLine( movie.Id );
Console.WriteLine( movie.Title );
Console.WriteLine( movie.Tagline );
Console.WriteLine( movie.ReleaseDate );
Console.WriteLine( movie.Budget );
The above query returns an ApiQueryResponse<T>
which returns a single result as well as some common information previously seen in the ApiSearchResponse
:
Member | Type | Description |
---|---|---|
Item | T |
The item returned from the API call, where T is the specific type returned from the query, such as MovieInfo , Movie , MovieCredit , etc.. |
ToString() | string |
Typically returns a well formatted string representation of T . |
Error | ApiError |
If an error was encountered, the Error property will provide specific error information about the API call to TheMovieDb.org. |
RateLimit | ApiRateLimit |
Contains the current rate limits from your most recent API call to TheMovieDb.org. Note: TheMovieDb.org has removed all rate limits as of December of 2019. |
string bearerToken = "your-bearer-token-from-TheMovieDb.org";
// RegisterSettings only needs to be called one time when your application starts-up.
MovieDbFactory.RegisterSettings( bearerToken );
var movieApi = MovieDbFactory.Create<IApiMovieRequest>().Value;
int pageNumber = 1;
int totalPages;
do
{
ApiSearchResponse<MovieInfo> response = await movieApi.SearchByTitleAsync( "Harry", pageNumber );
// alternatively, just call response.ToString() which will provide the same paged information format as below:
Console.WriteLine( $"Page {response.PageNumber} of {response.TotalPages} ({response.TotalResults} total results)" );
foreach( MovieInfo info in response.Results )
{
Console.WriteLine( $"{info.Title} ({info.ReleaseDate}): {info.Overview}" );
}
totalPages = response.TotalPages;
} while( pageNumber++ < totalPages );