Skip to content

Commit

Permalink
Merge pull request jellyfin#406 from TheUltimateC0der/feature/watchpr…
Browse files Browse the repository at this point in the history
…oviders

Implemented Watch Providers endpoints
  • Loading branch information
LordMike committed Apr 27, 2022
2 parents 8f1b563 + 5b82edd commit ac529fe
Show file tree
Hide file tree
Showing 7 changed files with 5,477 additions and 1 deletion.
64 changes: 64 additions & 0 deletions TMDbLib/Client/TMDbClientWatchProviders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using System.Threading;
using System.Threading.Tasks;
using TMDbLib.Objects.General;
using TMDbLib.Rest;

namespace TMDbLib.Client
{
public partial class TMDbClient
{
/// <summary>
/// Returns a list of all of the countries TMDb has watch provider (OTT/streaming) data for.
/// </summary>
/// <param name="cancellationToken">A cancellation token</param>
/// <remarks>Uses <see cref="DefaultLanguage"/> to translate data</remarks>
public async Task<ResultContainer<WatchProviderRegion>> GetWatchProviderRegionsAsync(CancellationToken cancellationToken = default)
{
RestRequest req = _client.Create("watch/providers/regions");
if (DefaultLanguage != null)
req.AddParameter("language", DefaultLanguage);

ResultContainer<WatchProviderRegion> response = await req.GetOfT<ResultContainer<WatchProviderRegion>>(cancellationToken).ConfigureAwait(false);

return response;
}

/// <summary>
/// Returns a list of the watch provider (OTT/streaming) data TMDb has available for movies.
/// </summary>
/// <param name="cancellationToken">A cancellation token</param>
/// <remarks>Uses <see cref="DefaultCountry"/> and <see cref="DefaultLanguage"/> to filter or translate data</remarks>
public async Task<ResultContainer<WatchProviderItem>> GetMovieWatchProvidersAsync(CancellationToken cancellationToken = default)
{
RestRequest req = _client.Create("watch/providers/movie");
if (DefaultLanguage != null)
req.AddParameter("language", DefaultLanguage);

if (DefaultCountry != null)
req.AddParameter("watch_region", DefaultCountry);

ResultContainer<WatchProviderItem> response = await req.GetOfT<ResultContainer<WatchProviderItem>>(cancellationToken).ConfigureAwait(false);

return response;
}

/// <summary>
/// Returns a list of the watch provider (OTT/streaming) data TMDb has available for shows.
/// </summary>
/// <param name="cancellationToken">A cancellation token</param>
/// <remarks>Uses <see cref="DefaultCountry"/> and <see cref="DefaultLanguage"/> to filter or translate data</remarks>
public async Task<ResultContainer<WatchProviderItem>> GetTvWatchProvidersAsync(CancellationToken cancellationToken = default)
{
RestRequest req = _client.Create("watch/providers/tv");
if (DefaultLanguage != null)
req.AddParameter("language", DefaultLanguage);

if (DefaultCountry != null)
req.AddParameter("watch_region", DefaultCountry);

ResultContainer<WatchProviderItem> response = await req.GetOfT<ResultContainer<WatchProviderItem>>(cancellationToken).ConfigureAwait(false);

return response;
}
}
}
19 changes: 19 additions & 0 deletions TMDbLib/Objects/General/WatchProviderRegion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using Newtonsoft.Json;

namespace TMDbLib.Objects.General
{
public class WatchProviderRegion
{
/// <summary>
/// A country code, e.g. US
/// </summary>
[JsonProperty("iso_3166_1")]
public string Iso_3166_1 { get; set; }

[JsonProperty("english_name")]
public string EnglishName { get; set; }

[JsonProperty("native_name")]
public string NativeName { get; set; }
}
}
2 changes: 1 addition & 1 deletion TMDbLib/TMDbLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Authors>LordMike;Naliath</Authors>
<TargetFrameworks>net45;netstandard2.1;netstandard2.0;netstandard1.2</TargetFrameworks>
<TargetFrameworks>netstandard2.1;netstandard2.0;netstandard1.2</TargetFrameworks>
<AssemblyName>TMDbLib</AssemblyName>
<PackageId>TMDbLib</PackageId>
<Description>.NET Client library for The Movie Database (https://www.themoviedb.org/)</Description>
Expand Down
34 changes: 34 additions & 0 deletions TMDbLibTests/ClientWatchProvidersTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System.Threading.Tasks;
using TMDbLib.Objects.General;
using TMDbLibTests.JsonHelpers;
using Xunit;

namespace TMDbLibTests
{
public class ClientWatchProvidersTests : TestBase
{
[Fact]
public async Task TestGetRegions()
{
ResultContainer<WatchProviderRegion> watchProviderRegions = await TMDbClient.GetWatchProviderRegionsAsync();

await Verify(watchProviderRegions);
}

[Fact]
public async Task TestGetMovieWatchProviders()
{
ResultContainer<WatchProviderItem> watchProviders = await TMDbClient.GetMovieWatchProvidersAsync();

await Verify(watchProviders);
}

[Fact]
public async Task TestGetTvWatchProviders()
{
ResultContainer<WatchProviderItem> watchProviders = await TMDbClient.GetTvWatchProvidersAsync();

await Verify(watchProviders);
}
}
}
Loading

0 comments on commit ac529fe

Please sign in to comment.