Skip to content

Commit

Permalink
Refactor GetTvShowMethodInternal to include media language for videos…
Browse files Browse the repository at this point in the history
… method

This change renames the parameter "includeImageLanguage" with "includeMediaLanguage" and adjusts the logic to accommodate either images or videos. This lets user, specify a comma-separated list of language (such as 'hi-IN,en-US')
to filter out result instead of a single language.
See https://developer.themoviedb.org/reference/tv-series-videos
  • Loading branch information
DineshSolanki committed Jul 8, 2024
1 parent 35b084f commit 8a61a9a
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions TMDbLib/Client/TMDbClientTvShows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace TMDbLib.Client
{
public partial class TMDbClient
{
private async Task<T> GetTvShowMethodInternal<T>(int id, TvShowMethods tvShowMethod, string dateFormat = null, string language = null, string includeImageLanguage = null, int page = 0, CancellationToken cancellationToken = default) where T : new()
private async Task<T> GetTvShowMethodInternal<T>(int id, TvShowMethods tvShowMethod, string dateFormat = null, string language = null, string includeMediaLanguage = null, int page = 0, CancellationToken cancellationToken = default) where T : new()
{
RestRequest req = _client.Create("tv/{id}/{method}");
req.AddUrlSegment("id", id.ToString(CultureInfo.InvariantCulture));
Expand All @@ -35,10 +35,14 @@ public partial class TMDbClient
if (!string.IsNullOrWhiteSpace(language))
req.AddParameter("language", language);

includeImageLanguage ??= DefaultImageLanguage;
if (!string.IsNullOrWhiteSpace(includeImageLanguage))
req.AddParameter("include_image_language", includeImageLanguage);

includeMediaLanguage ??= DefaultImageLanguage;
if (!string.IsNullOrWhiteSpace(includeMediaLanguage))
{
req.AddParameter(
tvShowMethod == TvShowMethods.Videos ? "include_video_language" : "include_image_language",
includeMediaLanguage);
}

T resp = await req.GetOfT<T>(cancellationToken).ConfigureAwait(false);

return resp;
Expand Down Expand Up @@ -211,7 +215,7 @@ public async Task<ExternalIdsTvShow> GetTvShowExternalIdsAsync(int id, Cancellat
/// <param name="cancellationToken">A cancellation token</param>
public async Task<ImagesWithId> GetTvShowImagesAsync(int id, string language = null, string includeImageLanguage = null, CancellationToken cancellationToken = default)
{
return await GetTvShowMethodInternal<ImagesWithId>(id, TvShowMethods.Images, language: language, includeImageLanguage: includeImageLanguage, cancellationToken: cancellationToken).ConfigureAwait(false);
return await GetTvShowMethodInternal<ImagesWithId>(id, TvShowMethods.Images, language: language, includeMediaLanguage: includeImageLanguage, cancellationToken: cancellationToken).ConfigureAwait(false);
}

public async Task<SearchContainerWithId<ReviewBase>> GetTvShowReviewsAsync(int id, string language = null, int page = 0, CancellationToken cancellationToken = default)
Expand Down Expand Up @@ -315,9 +319,9 @@ public async Task<TranslationsContainerTv> GetTvShowTranslationsAsync(int id, Ca
return await GetTvShowMethodInternal<TranslationsContainerTv>(id, TvShowMethods.Translations, cancellationToken: cancellationToken).ConfigureAwait(false);
}

public async Task<ResultContainer<Video>> GetTvShowVideosAsync(int id, string language = null, CancellationToken cancellationToken = default)
public async Task<ResultContainer<Video>> GetTvShowVideosAsync(int id, string includeMediaLanguage = null, CancellationToken cancellationToken = default)
{
return await GetTvShowMethodInternal<ResultContainer<Video>>(id, TvShowMethods.Videos, language:language, cancellationToken: cancellationToken).ConfigureAwait(false);
return await GetTvShowMethodInternal<ResultContainer<Video>>(id, TvShowMethods.Videos, includeMediaLanguage:includeMediaLanguage, cancellationToken: cancellationToken).ConfigureAwait(false);
}

public async Task<SingleResultContainer<Dictionary<string, WatchProviders>>> GetTvShowWatchProvidersAsync(int id, CancellationToken cancellationToken = default)
Expand Down

0 comments on commit 8a61a9a

Please sign in to comment.