Fix a copy paste mistake and add series end date
This commit is contained in:
parent
23c867f946
commit
ced9868357
|
@ -94,7 +94,7 @@ namespace MediaBrowser.Providers.TV
|
|||
|
||||
public Task<TvDbResponse<SeriesSearchResult[]>> GetSeriesByZap2ItIdAsync(string zap2ItId, CancellationToken cancellationToken)
|
||||
{
|
||||
return TryGetValue("series" + zap2ItId,() => TvDbClient.Search.SearchSeriesByImdbIdAsync(zap2ItId, cancellationToken));
|
||||
return TryGetValue("series" + zap2ItId,() => TvDbClient.Search.SearchSeriesByZap2ItIdAsync(zap2ItId, cancellationToken));
|
||||
}
|
||||
public Task<TvDbResponse<Actor[]>> GetActorsAsync(int tvdbId, CancellationToken cancellationToken)
|
||||
{
|
||||
|
@ -111,6 +111,18 @@ namespace MediaBrowser.Providers.TV
|
|||
return TryGetValue("languages",() => TvDbClient.Languages.GetAllAsync(cancellationToken));
|
||||
}
|
||||
|
||||
public Task<TvDbResponse<EpisodesSummary>> GetSeriesEpisodeSummaryAsync(int tvdbId, CancellationToken cancellationToken)
|
||||
{
|
||||
return TryGetValue("seriesepisodesummary" + tvdbId,
|
||||
() => TvDbClient.Series.GetEpisodesSummaryAsync(tvdbId, cancellationToken));
|
||||
}
|
||||
|
||||
public Task<TvDbResponse<EpisodeRecord[]>> GetEpisodesPageAsync(int tvdbId, EpisodeQuery episodeQuery, CancellationToken cancellationToken)
|
||||
{
|
||||
return TryGetValue("episodespage" + tvdbId + episodeQuery.AiredSeason,
|
||||
() => TvDbClient.Series.GetEpisodesAsync(tvdbId, 1, episodeQuery, cancellationToken));
|
||||
}
|
||||
|
||||
private async Task<T> TryGetValue<T>(object key, Func<Task<T>> resultFactory)
|
||||
{
|
||||
if (_cache.TryGetValue(key, out T cachedValue))
|
||||
|
|
|
@ -329,7 +329,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
return name.Trim();
|
||||
}
|
||||
|
||||
private static void MapSeriesToResult(MetadataResult<Series> result, TvDbSharper.Dto.Series tvdbSeries)
|
||||
private void MapSeriesToResult(MetadataResult<Series> result, TvDbSharper.Dto.Series tvdbSeries)
|
||||
{
|
||||
Series series = result.Item;
|
||||
series.SetProviderId(MetadataProviders.Tvdb, tvdbSeries.Id.ToString());
|
||||
|
@ -363,11 +363,30 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
|
||||
series.AddStudio(tvdbSeries.Network);
|
||||
|
||||
// TODO is this necessary?
|
||||
// if (result.Item.Status.HasValue && result.Item.Status.Value == SeriesStatus.Ended && episodeAirDates.Count > 0)
|
||||
// {
|
||||
// result.Item.EndDate = episodeAirDates.Max();
|
||||
// }
|
||||
if (result.Item.Status.HasValue && result.Item.Status.Value == SeriesStatus.Ended)
|
||||
{
|
||||
try
|
||||
{
|
||||
var episodeSummary = _tvDbClientManager
|
||||
.GetSeriesEpisodeSummaryAsync(tvdbSeries.Id, CancellationToken.None).Result.Data;
|
||||
var maxSeasonNumber = episodeSummary.AiredSeasons.Select(s => Convert.ToInt32(s)).Max();
|
||||
var episodeQuery = new EpisodeQuery
|
||||
{
|
||||
AiredSeason = maxSeasonNumber
|
||||
};
|
||||
var episodesPage =
|
||||
_tvDbClientManager.GetEpisodesPageAsync(tvdbSeries.Id, episodeQuery, CancellationToken.None).Result.Data;
|
||||
result.Item.EndDate = episodesPage.Select(e =>
|
||||
{
|
||||
DateTime.TryParse(e.FirstAired, out var firstAired);
|
||||
return firstAired;
|
||||
}).Max();
|
||||
}
|
||||
catch (TvDbServerException e)
|
||||
{
|
||||
_logger.LogError(e, "Failed to find series end date for series {TvdbId}", tvdbSeries.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void MapActorsToResult(MetadataResult<Series> result, IEnumerable<Actor> actors)
|
||||
|
|
Loading…
Reference in New Issue
Block a user