|
@@ -125,7 +125,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
|
tmdbId,
|
|
tmdbId,
|
|
language: TmdbUtils.NormalizeLanguage(language),
|
|
language: TmdbUtils.NormalizeLanguage(language),
|
|
includeImageLanguage: imageLanguages,
|
|
includeImageLanguage: imageLanguages,
|
|
- extraMethods: TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.Keywords | TvShowMethods.ExternalIds | TvShowMethods.Videos | TvShowMethods.ContentRatings,
|
|
|
|
|
|
+ extraMethods: TvShowMethods.Credits | TvShowMethods.Images | TvShowMethods.Keywords | TvShowMethods.ExternalIds | TvShowMethods.Videos | TvShowMethods.ContentRatings | TvShowMethods.EpisodeGroups,
|
|
cancellationToken: cancellationToken).ConfigureAwait(false);
|
|
cancellationToken: cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
if (series != null)
|
|
if (series != null)
|
|
@@ -136,6 +136,56 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
|
return series;
|
|
return series;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Gets a tv show episode group from the TMDb API based on the show id and the display order.
|
|
|
|
+ /// </summary>
|
|
|
|
+ /// <param name="tvShowId">The tv show's TMDb id.</param>
|
|
|
|
+ /// <param name="displayOrder">The display order.</param>
|
|
|
|
+ /// <param name="language">The tv show's language.</param>
|
|
|
|
+ /// <param name="imageLanguages">A comma-separated list of image languages.</param>
|
|
|
|
+ /// <param name="cancellationToken">The cancellation token.</param>
|
|
|
|
+ /// <returns>The TMDb tv show episode group information or null if not found.</returns>
|
|
|
|
+ public async Task<TvGroupCollection> GetSeriesGroupAsync(int tvShowId, string displayOrder, string language, string imageLanguages, CancellationToken cancellationToken)
|
|
|
|
+ {
|
|
|
|
+ var key = $"group-{tvShowId.ToString(CultureInfo.InvariantCulture)}-{displayOrder}-{language}";
|
|
|
|
+ if (_memoryCache.TryGetValue(key, out TvGroupCollection group))
|
|
|
|
+ {
|
|
|
|
+ return group;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ await EnsureClientConfigAsync().ConfigureAwait(false);
|
|
|
|
+
|
|
|
|
+ TvGroupType? groupType =
|
|
|
|
+ displayOrder == "absolute" ? TvGroupType.Absolute :
|
|
|
|
+ displayOrder == "dvd" ? TvGroupType.DVD :
|
|
|
|
+ null;
|
|
|
|
+
|
|
|
|
+ if (groupType == null)
|
|
|
|
+ {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var series = await GetSeriesAsync(tvShowId, language, imageLanguages, cancellationToken);
|
|
|
|
+ var episodeGroupId = series.EpisodeGroups.Results.Find(g => g.Type == groupType)?.Id;
|
|
|
|
+
|
|
|
|
+ if (episodeGroupId == null)
|
|
|
|
+ {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ group = await _tmDbClient.GetTvEpisodeGroupsAsync(
|
|
|
|
+ episodeGroupId,
|
|
|
|
+ language: TmdbUtils.NormalizeLanguage(language),
|
|
|
|
+ cancellationToken: cancellationToken).ConfigureAwait(false);
|
|
|
|
+
|
|
|
|
+ if (group != null)
|
|
|
|
+ {
|
|
|
|
+ _memoryCache.Set(key, group, TimeSpan.FromHours(CacheDurationInHours));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return group;
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets a tv season from the TMDb API based on the tv show's TMDb id.
|
|
/// Gets a tv season from the TMDb API based on the tv show's TMDb id.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -177,13 +227,14 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
|
/// <param name="tvShowId">The tv show's TMDb id.</param>
|
|
/// <param name="tvShowId">The tv show's TMDb id.</param>
|
|
/// <param name="seasonNumber">The season number.</param>
|
|
/// <param name="seasonNumber">The season number.</param>
|
|
/// <param name="episodeNumber">The episode number.</param>
|
|
/// <param name="episodeNumber">The episode number.</param>
|
|
|
|
+ /// <param name="displayOrder">The display order.</param>
|
|
/// <param name="language">The episode's language.</param>
|
|
/// <param name="language">The episode's language.</param>
|
|
/// <param name="imageLanguages">A comma-separated list of image languages.</param>
|
|
/// <param name="imageLanguages">A comma-separated list of image languages.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <param name="cancellationToken">The cancellation token.</param>
|
|
/// <returns>The TMDb tv episode information or null if not found.</returns>
|
|
/// <returns>The TMDb tv episode information or null if not found.</returns>
|
|
- public async Task<TvEpisode> GetEpisodeAsync(int tvShowId, int seasonNumber, int episodeNumber, string language, string imageLanguages, CancellationToken cancellationToken)
|
|
|
|
|
|
+ public async Task<TvEpisode> GetEpisodeAsync(int tvShowId, int seasonNumber, int episodeNumber, string displayOrder, string language, string imageLanguages, CancellationToken cancellationToken)
|
|
{
|
|
{
|
|
- var key = $"episode-{tvShowId.ToString(CultureInfo.InvariantCulture)}-s{seasonNumber.ToString(CultureInfo.InvariantCulture)}e{episodeNumber.ToString(CultureInfo.InvariantCulture)}-{language}";
|
|
|
|
|
|
+ var key = $"episode-{tvShowId.ToString(CultureInfo.InvariantCulture)}-s{seasonNumber.ToString(CultureInfo.InvariantCulture)}e{episodeNumber.ToString(CultureInfo.InvariantCulture)}-{displayOrder}-{language}";
|
|
if (_memoryCache.TryGetValue(key, out TvEpisode episode))
|
|
if (_memoryCache.TryGetValue(key, out TvEpisode episode))
|
|
{
|
|
{
|
|
return episode;
|
|
return episode;
|
|
@@ -191,6 +242,18 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
|
|
|
|
|
|
await EnsureClientConfigAsync().ConfigureAwait(false);
|
|
await EnsureClientConfigAsync().ConfigureAwait(false);
|
|
|
|
|
|
|
|
+ var group = await GetSeriesGroupAsync(tvShowId, displayOrder, language, imageLanguages, cancellationToken);
|
|
|
|
+ if (group != null)
|
|
|
|
+ {
|
|
|
|
+ var season = group.Groups.Find(s => s.Order == seasonNumber);
|
|
|
|
+ var ep = season?.Episodes.Find(e => e.Order == episodeNumber - 1);
|
|
|
|
+ if (ep != null)
|
|
|
|
+ {
|
|
|
|
+ seasonNumber = ep.SeasonNumber;
|
|
|
|
+ episodeNumber = ep.EpisodeNumber;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
episode = await _tmDbClient.GetTvEpisodeAsync(
|
|
episode = await _tmDbClient.GetTvEpisodeAsync(
|
|
tvShowId,
|
|
tvShowId,
|
|
seasonNumber,
|
|
seasonNumber,
|