diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs b/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs index 1bf4f6e03..6d17d4b13 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvDbClientManager.cs @@ -165,21 +165,27 @@ namespace MediaBrowser.Providers.TV { searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), out var seriesTvdbId); - var episodeNumber = searchInfo.IndexNumber.Value; - var seasonNumber = searchInfo.ParentIndexNumber.Value; - return GetEpisodeTvdbId(Convert.ToInt32(seriesTvdbId), episodeNumber, seasonNumber, cancellationToken); + var episodeQuery = new EpisodeQuery(); + + // Prefer SxE over premiere date as it is more robust + if (searchInfo.IndexNumber.HasValue && searchInfo.ParentIndexNumber.HasValue) + { + episodeQuery.AiredEpisode = searchInfo.IndexNumber.Value; + episodeQuery.AiredSeason = searchInfo.ParentIndexNumber.Value; + } + else if (searchInfo.PremiereDate.HasValue) + { + // tvdb expects yyyy-mm-dd format + episodeQuery.FirstAired = searchInfo.PremiereDate.Value.ToString("yyyy-MM-dd"); + } + + return GetEpisodeTvdbId(Convert.ToInt32(seriesTvdbId), episodeQuery, cancellationToken); } - public async Task GetEpisodeTvdbId(int seriesTvdbId, int episodeNumber, int seasonNumber, CancellationToken cancellationToken) + public async Task GetEpisodeTvdbId(int seriesTvdbId, EpisodeQuery episodeQuery, CancellationToken cancellationToken) { - var episodeQuery = new EpisodeQuery - { - AiredSeason = seasonNumber, - AiredEpisode = episodeNumber - }; - var episodePage = await GetEpisodesPageAsync(Convert.ToInt32(seriesTvdbId), - episodeQuery, cancellationToken); + var episodePage = await GetEpisodesPageAsync(Convert.ToInt32(seriesTvdbId), episodeQuery, cancellationToken); return episodePage.Data.FirstOrDefault()?.Id.ToString(); } diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs index 3a559727d..49468531d 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs @@ -60,15 +60,17 @@ namespace MediaBrowser.Providers.TV.TheTVDB { if (string.IsNullOrEmpty(episodeTvdbId)) { - var episodeNumber = episode.IndexNumber.Value; - var seasonNumber = episode.ParentIndexNumber.Value; - episodeTvdbId = await _tvDbClientManager.GetEpisodeTvdbId( - Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb)), episodeNumber, seasonNumber, - cancellationToken); + var episodeInfo = new EpisodeInfo + { + IndexNumber = episode.IndexNumber.Value, + ParentIndexNumber = episode.ParentIndexNumber.Value, + SeriesProviderIds = series.ProviderIds + }; + episodeTvdbId = await _tvDbClientManager.GetEpisodeTvdbId(episodeInfo, cancellationToken); if (string.IsNullOrEmpty(episodeTvdbId)) { _logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}", - seasonNumber, episodeNumber); + episodeInfo.ParentIndexNumber, episodeInfo.IndexNumber); return imageResult; } } diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs index f4dc22a80..2a52b76eb 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeProvider.cs @@ -36,7 +36,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB var list = new List(); // The search query must either provide an episode number or date - // TODO premieredate functionality is dead, could grab all episodes and search for it if (!searchInfo.IndexNumber.HasValue || !searchInfo.PremiereDate.HasValue) { return list; @@ -172,8 +171,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB if (DateTime.TryParse(episode.FirstAired, out var date)) { - date = date.ToUniversalTime(); - + // dates from tvdb are UTC but without offset or Z item.PremiereDate = date; item.ProductionYear = date.Year; } diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs index 342591da0..8e5616d15 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs @@ -349,8 +349,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB if (DateTime.TryParse(tvdbSeries.FirstAired, out var date)) { - date = date.ToUniversalTime(); - + // dates from tvdb are UTC but without offset or Z series.PremiereDate = date; series.ProductionYear = date.Year; }