Always fetch episode id as EpisodeInfo does not contain it

This commit is contained in:
Claus Vium 2019-08-15 13:39:56 +02:00
parent 685e9e4f58
commit 14575f0a06
2 changed files with 69 additions and 88 deletions

View File

@ -50,12 +50,8 @@ namespace MediaBrowser.Providers.TV.TheTVDB
var language = item.GetPreferredMetadataLanguage();
if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
{
var episodeTvdbId = episode.GetProviderId(MetadataProviders.Tvdb);
// Process images
try
{
if (string.IsNullOrEmpty(episodeTvdbId))
{
var episodeInfo = new EpisodeInfo
{
@ -63,7 +59,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
ParentIndexNumber = episode.ParentIndexNumber.Value,
SeriesProviderIds = series.ProviderIds
};
episodeTvdbId = await _tvDbClientManager
string episodeTvdbId = await _tvDbClientManager
.GetEpisodeTvdbId(episodeInfo, language, cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(episodeTvdbId))
{
@ -71,7 +67,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
episodeInfo.ParentIndexNumber, episodeInfo.IndexNumber, series.GetProviderId(MetadataProviders.Tvdb));
return imageResult;
}
}
var episodeResult =
await _tvDbClientManager
@ -86,7 +81,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
}
catch (TvDbServerException e)
{
_logger.LogError(e, "Failed to retrieve episode images for {TvDbId}", episodeTvdbId);
_logger.LogError(e, "Failed to retrieve episode images for series {TvDbId}", series.GetProviderId(MetadataProviders.Tvdb));
}
}

View File

@ -36,37 +36,20 @@ namespace MediaBrowser.Providers.TV.TheTVDB
var list = new List<RemoteSearchResult>();
// The search query must either provide an episode number or date
if (!searchInfo.IndexNumber.HasValue || !searchInfo.PremiereDate.HasValue)
if (!searchInfo.IndexNumber.HasValue
|| !searchInfo.PremiereDate.HasValue
|| !TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds))
{
return list;
}
if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds))
var metadataResult = await GetEpisode(searchInfo, cancellationToken).ConfigureAwait(false);
if (!metadataResult.HasMetadata)
{
try
{
var episodeTvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb);
if (string.IsNullOrEmpty(episodeTvdbId))
{
searchInfo.SeriesProviderIds.TryGetValue(MetadataProviders.Tvdb.ToString(),
out var seriesTvdbId);
episodeTvdbId = await _tvDbClientManager
.GetEpisodeTvdbId(searchInfo, searchInfo.MetadataLanguage, cancellationToken)
.ConfigureAwait(false);
if (string.IsNullOrEmpty(episodeTvdbId))
{
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
searchInfo.ParentIndexNumber, searchInfo.IndexNumber, seriesTvdbId);
return list;
}
}
var episodeResult = await _tvDbClientManager.GetEpisodesAsync(Convert.ToInt32(episodeTvdbId),
searchInfo.MetadataLanguage, cancellationToken).ConfigureAwait(false);
var metadataResult = MapEpisodeToResult(searchInfo, episodeResult.Data);
if (metadataResult.HasMetadata)
{
var item = metadataResult.Item;
list.Add(new RemoteSearchResult
@ -80,13 +63,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
SearchProviderName = Name,
IndexNumberEnd = item.IndexNumberEnd
});
}
}
catch (TvDbServerException e)
{
_logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", searchInfo.IndexNumber);
}
}
return list;
}
@ -103,36 +79,46 @@ namespace MediaBrowser.Providers.TV.TheTVDB
if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds) &&
(searchInfo.IndexNumber.HasValue || searchInfo.PremiereDate.HasValue))
{
var tvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb);
try
result = await GetEpisode(searchInfo, cancellationToken).ConfigureAwait(false);
}
else
{
if (string.IsNullOrEmpty(tvdbId))
{
tvdbId = await _tvDbClientManager
.GetEpisodeTvdbId(searchInfo, searchInfo.MetadataLanguage, cancellationToken)
.ConfigureAwait(false);
if (string.IsNullOrEmpty(tvdbId))
{
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
searchInfo.ParentIndexNumber, searchInfo.IndexNumber, tvdbId);
_logger.LogDebug("No series identity found for {EpisodeName}", searchInfo.Name);
}
return result;
}
private async Task<MetadataResult<Episode>> GetEpisode(EpisodeInfo searchInfo, CancellationToken cancellationToken)
{
var result = new MetadataResult<Episode>
{
QueriedById = true
};
string seriesTvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb);
string episodeTvdbId = null;
try
{
episodeTvdbId = await _tvDbClientManager
.GetEpisodeTvdbId(searchInfo, searchInfo.MetadataLanguage, cancellationToken)
.ConfigureAwait(false);
if (string.IsNullOrEmpty(episodeTvdbId))
{
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
searchInfo.ParentIndexNumber, searchInfo.IndexNumber, seriesTvdbId);
return result;
}
var episodeResult = await _tvDbClientManager.GetEpisodesAsync(
Convert.ToInt32(tvdbId), searchInfo.MetadataLanguage,
Convert.ToInt32(episodeTvdbId), searchInfo.MetadataLanguage,
cancellationToken).ConfigureAwait(false);
result = MapEpisodeToResult(searchInfo, episodeResult.Data);
}
catch (TvDbServerException e)
{
_logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", tvdbId);
}
}
else
{
_logger.LogDebug("No series identity found for {EpisodeName}", searchInfo.Name);
_logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", episodeTvdbId ?? seriesTvdbId);
}
return result;