Fix InvalidOperationException in TvdbSeriesProvider

This commit is contained in:
Gary Wilber 2020-09-27 16:22:52 -07:00
parent 800c039612
commit 303eccaffe

View File

@ -123,7 +123,7 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
await _tvdbClientManager await _tvdbClientManager
.GetSeriesByIdAsync(Convert.ToInt32(tvdbId), metadataLanguage, cancellationToken) .GetSeriesByIdAsync(Convert.ToInt32(tvdbId), metadataLanguage, cancellationToken)
.ConfigureAwait(false); .ConfigureAwait(false);
MapSeriesToResult(result, seriesResult.Data, metadataLanguage); await MapSeriesToResult(result, seriesResult.Data, metadataLanguage).ConfigureAwait(false);
} }
catch (TvDbServerException e) catch (TvDbServerException e)
{ {
@ -297,7 +297,7 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
return name.Trim(); return name.Trim();
} }
private void MapSeriesToResult(MetadataResult<Series> result, TvDbSharper.Dto.Series tvdbSeries, string metadataLanguage) private async Task MapSeriesToResult(MetadataResult<Series> result, TvDbSharper.Dto.Series tvdbSeries, string metadataLanguage)
{ {
Series series = result.Item; Series series = result.Item;
series.SetProviderId(MetadataProvider.Tvdb, tvdbSeries.Id.ToString()); series.SetProviderId(MetadataProvider.Tvdb, tvdbSeries.Id.ToString());
@ -340,20 +340,25 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
{ {
try try
{ {
var episodeSummary = _tvdbClientManager var episodeSummary = await _tvdbClientManager.GetSeriesEpisodeSummaryAsync(tvdbSeries.Id, metadataLanguage, CancellationToken.None).ConfigureAwait(false);
.GetSeriesEpisodeSummaryAsync(tvdbSeries.Id, metadataLanguage, CancellationToken.None).Result.Data;
var maxSeasonNumber = episodeSummary.AiredSeasons.Select(s => Convert.ToInt32(s)).Max(); if (episodeSummary.Data.AiredSeasons.Length > 0)
var episodeQuery = new EpisodeQuery
{ {
AiredSeason = maxSeasonNumber var maxSeasonNumber = episodeSummary.Data.AiredSeasons.Select(s => Convert.ToInt32(s)).Max();
}; var episodeQuery = new EpisodeQuery
var episodesPage =
_tvdbClientManager.GetEpisodesPageAsync(tvdbSeries.Id, episodeQuery, metadataLanguage, CancellationToken.None).Result.Data;
result.Item.EndDate = episodesPage.Select(e =>
{ {
DateTime.TryParse(e.FirstAired, out var firstAired); AiredSeason = maxSeasonNumber
return firstAired; };
}).Max(); var episodesPage = await _tvdbClientManager.GetEpisodesPageAsync(tvdbSeries.Id, episodeQuery, metadataLanguage, CancellationToken.None).ConfigureAwait(false);
var episodeDates = episodesPage.Data
.Select(e => DateTime.TryParse(e.FirstAired, out var firstAired) ? firstAired : (DateTime?)null)
.Where(dt => dt.HasValue);
if (episodeDates.Any())
{
result.Item.EndDate = episodeDates.Max().Value;
}
}
} }
catch (TvDbServerException e) catch (TvDbServerException e)
{ {