2021-03-27 23:05:36 +01:00
TMDbLib [](https://github.com/LordMike/TMDbLib/actions/workflows/dotnet.yml) [](https://www.nuget.org/packages/Tmdblib) [](https://github.com/LordMike/TMDbLib/packages/691970)
2013-02-16 21:04:49 +01:00
=======
2013-02-16 21:05:40 +01:00
A near-complete wrapper for v3 of TMDb's API (TheMovieDb - https://www.themoviedb.org/).
2013-02-16 21:04:49 +01:00
2021-03-28 19:01:35 +02:00
## Using alpha packages
All commits to master produce an Alpha package that can be [found here ](https://github.com/LordMike/TMDbLib/packages/691970 ). [Read more on how to use these packages ](https://blog.mbwarez.dk/consuming-my-nuget-packages-from-github/ ).
2021-03-27 23:05:36 +01:00
2016-08-01 23:01:33 +02:00
Index
2013-02-16 21:04:49 +01:00
---------
2016-08-01 23:01:33 +02:00
- [Nuget ](#nuget )
2016-11-30 20:18:20 +01:00
- [Documentation ](#documentation )
2016-08-01 23:01:33 +02:00
- [Examples ](#examples )
2016-08-02 21:40:41 +02:00
- [Tips ](#tips )
2013-02-16 21:04:49 +01:00
2016-11-30 20:18:20 +01:00
Documentation
--------
Most of the library is self-explaining, and closely follows the possibilities at the official TMDb documentation site: [developers.themoviedb.org ](https://developers.themoviedb.org/3/getting-started ).
2013-02-16 21:04:49 +01:00
Examples
2016-11-26 09:57:59 +00:00
--------
2016-08-01 23:10:47 +02:00
2013-02-16 21:04:49 +01:00
Simple example, getting the basic info for "A good day to die hard".
2018-10-14 12:30:57 +02:00
```csharp
TMDbClient client = new TMDbClient("APIKey");
Movie movie = client.GetMovieAsync(47964).Result;
Console.WriteLine($"Movie name: {movie.Title}");
```
2013-02-16 21:04:49 +01:00
Using the extra features of TMDb, we can fetch more info in one go (here we fetch casts as well as trailers):
2018-10-14 12:30:57 +02:00
```csharp
TMDbClient client = new TMDbClient("APIKey");
2021-03-27 23:45:33 +01:00
Movie movie = await client.GetMovieAsync(47964, MovieMethods.Credits | MovieMethods.Videos);
2018-10-14 12:30:57 +02:00
Console.WriteLine($"Movie title: {movie.Title}");
foreach (Cast cast in movie.Credits.Cast)
Console.WriteLine($"{cast.Name} - {cast.Character}");
2013-02-16 21:04:49 +01:00
2018-10-14 12:30:57 +02:00
Console.WriteLine();
foreach (Video video in movie.Videos.Results)
Console.WriteLine($"Trailer: {video.Type} ({video.Site}), {video.Name}");
```
2013-02-16 21:04:49 +01:00
It is likewise simple to search for people or movies, for example here we search for "007". This yields basically every James Bond film ever made:
2018-10-14 12:30:57 +02:00
```csharp
TMDbClient client = new TMDbClient("APIKey");
SearchContainer< SearchMovie > results = client.SearchMovieAsync("007").Result;
2016-08-01 23:10:47 +02:00
2018-10-14 12:30:57 +02:00
Console.WriteLine($"Got {results.Results.Count:N0} of {results.TotalResults:N0} results");
foreach (SearchMovie result in results.Results)
Console.WriteLine(result.Title);
```
2013-02-16 21:04:49 +01:00
However, another way to get all James Bond movies, is to use the collection-approach. TMDb makes collections for series of movies, such as Die Hard and James Bond. I know there is one, so I will show how to search for the collection, and then list all movies in it:
2018-10-14 12:30:57 +02:00
```csharp
TMDbClient client = new TMDbClient("APIKey");
SearchContainer< SearchCollection > collectons = client.SearchCollectionAsync("James Bond").Result;
Console.WriteLine($"Got {collectons.Results.Count:N0} collections");
2016-08-01 23:10:47 +02:00
2018-10-14 12:30:57 +02:00
Collection jamesBonds = client.GetCollectionAsync(collectons.Results.First().Id).Result;
2021-03-27 23:45:33 +01:00
Console.WriteLine($"Collection: {jamesBonds.Name}");
2018-10-14 12:30:57 +02:00
Console.WriteLine();
2016-08-01 23:10:47 +02:00
2018-10-14 12:30:57 +02:00
Console.WriteLine($"Got {jamesBonds.Parts.Count:N0} James Bond Movies");
foreach (SearchMovie part in jamesBonds.Parts)
2021-03-27 23:45:33 +01:00
Console.WriteLine(part.Title);
2018-10-14 12:30:57 +02:00
```
2013-02-16 21:04:49 +01:00
2016-08-02 21:40:41 +02:00
Tips
---------
* All methods are `async` and awaitable
* Most methods are very straightforward, and do as they are named, `GetMovie` , `GetPerson` etc.
2016-08-02 21:41:47 +02:00
* Almost all enums are of the `[Flags]` type. This means you can combine them: `MovieMethods.Casts | MovieMethods.Trailers`
2021-03-28 19:01:35 +02:00
* TMDb are big fans of serving as little as possible, so most properties on primary classes like `Movie` are null, until you request the extra data using the enums like above.