Add support for searching for episodes by premiere date and fixed timezones

This commit is contained in:
Claus Vium 2019-02-11 20:33:44 +01:00
parent e8189cd0f6
commit f5bda652c4
4 changed files with 27 additions and 22 deletions

View File

@ -165,21 +165,27 @@ namespace MediaBrowser.Providers.TV
{ {
searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(), searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(),
out var seriesTvdbId); 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");
} }
public async Task<string> GetEpisodeTvdbId(int seriesTvdbId, int episodeNumber, int seasonNumber, CancellationToken cancellationToken) return GetEpisodeTvdbId(Convert.ToInt32(seriesTvdbId), episodeQuery, cancellationToken);
}
public async Task<string> GetEpisodeTvdbId(int seriesTvdbId, EpisodeQuery episodeQuery, CancellationToken cancellationToken)
{ {
var episodeQuery = new EpisodeQuery var episodePage = await GetEpisodesPageAsync(Convert.ToInt32(seriesTvdbId), episodeQuery, cancellationToken);
{
AiredSeason = seasonNumber,
AiredEpisode = episodeNumber
};
var episodePage = await GetEpisodesPageAsync(Convert.ToInt32(seriesTvdbId),
episodeQuery, cancellationToken);
return episodePage.Data.FirstOrDefault()?.Id.ToString(); return episodePage.Data.FirstOrDefault()?.Id.ToString();
} }

View File

@ -60,15 +60,17 @@ namespace MediaBrowser.Providers.TV.TheTVDB
{ {
if (string.IsNullOrEmpty(episodeTvdbId)) if (string.IsNullOrEmpty(episodeTvdbId))
{ {
var episodeNumber = episode.IndexNumber.Value; var episodeInfo = new EpisodeInfo
var seasonNumber = episode.ParentIndexNumber.Value; {
episodeTvdbId = await _tvDbClientManager.GetEpisodeTvdbId( IndexNumber = episode.IndexNumber.Value,
Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb)), episodeNumber, seasonNumber, ParentIndexNumber = episode.ParentIndexNumber.Value,
cancellationToken); SeriesProviderIds = series.ProviderIds
};
episodeTvdbId = await _tvDbClientManager.GetEpisodeTvdbId(episodeInfo, cancellationToken);
if (string.IsNullOrEmpty(episodeTvdbId)) if (string.IsNullOrEmpty(episodeTvdbId))
{ {
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}", _logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
seasonNumber, episodeNumber); episodeInfo.ParentIndexNumber, episodeInfo.IndexNumber);
return imageResult; return imageResult;
} }
} }

View File

@ -36,7 +36,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
var list = new List<RemoteSearchResult>(); var list = new List<RemoteSearchResult>();
// The search query must either provide an episode number or date // 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) if (!searchInfo.IndexNumber.HasValue || !searchInfo.PremiereDate.HasValue)
{ {
return list; return list;
@ -172,8 +171,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
if (DateTime.TryParse(episode.FirstAired, out var date)) 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.PremiereDate = date;
item.ProductionYear = date.Year; item.ProductionYear = date.Year;
} }

View File

@ -349,8 +349,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
if (DateTime.TryParse(tvdbSeries.FirstAired, out var date)) 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.PremiereDate = date;
series.ProductionYear = date.Year; series.ProductionYear = date.Year;
} }