Merge pull request #4221 from Spacetech/tvdb_series_provider_InvalidOperationException

Fix InvalidOperationException in TvdbSeriesProvider.MapSeriesToResult
This commit is contained in:
dkanada 2020-10-10 15:55:11 +09:00 committed by GitHub
commit 6478e70f06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text; using System.Text;
@ -123,7 +124,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 +298,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 +341,21 @@ 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.Max(s => Convert.ToInt32(s, CultureInfo.InvariantCulture));
}; 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);
result.Item.EndDate = episodesPage.Data
.Select(e => DateTime.TryParse(e.FirstAired, out var firstAired) ? firstAired : (DateTime?)null)
.Max();
}
} }
catch (TvDbServerException e) catch (TvDbServerException e)
{ {