Add support for searching for episodes by premiere date and fixed timezones
This commit is contained in:
parent
e8189cd0f6
commit
f5bda652c4
|
@ -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<string> GetEpisodeTvdbId(int seriesTvdbId, int episodeNumber, int seasonNumber, CancellationToken cancellationToken)
|
||||
public async Task<string> 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
|||
var list = new List<RemoteSearchResult>();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user