Merge pull request #1628 from cvium/fix_tvdb_ep_provider_id

Always fetch episode id as EpisodeInfo does not contain it
This commit is contained in:
Anthony Lavado 2019-08-17 02:10:36 -04:00 committed by GitHub
commit f1f4b1a184
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 88 deletions

View File

@ -50,12 +50,8 @@ namespace MediaBrowser.Providers.TV.TheTVDB
var language = item.GetPreferredMetadataLanguage(); var language = item.GetPreferredMetadataLanguage();
if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds)) if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
{ {
var episodeTvdbId = episode.GetProviderId(MetadataProviders.Tvdb);
// Process images // Process images
try try
{
if (string.IsNullOrEmpty(episodeTvdbId))
{ {
var episodeInfo = new EpisodeInfo var episodeInfo = new EpisodeInfo
{ {
@ -63,15 +59,17 @@ namespace MediaBrowser.Providers.TV.TheTVDB
ParentIndexNumber = episode.ParentIndexNumber.Value, ParentIndexNumber = episode.ParentIndexNumber.Value,
SeriesProviderIds = series.ProviderIds SeriesProviderIds = series.ProviderIds
}; };
episodeTvdbId = await _tvDbClientManager string episodeTvdbId = await _tvDbClientManager
.GetEpisodeTvdbId(episodeInfo, language, cancellationToken).ConfigureAwait(false); .GetEpisodeTvdbId(episodeInfo, language, cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(episodeTvdbId)) if (string.IsNullOrEmpty(episodeTvdbId))
{ {
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}", _logger.LogError(
episodeInfo.ParentIndexNumber, episodeInfo.IndexNumber, series.GetProviderId(MetadataProviders.Tvdb)); "Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
episodeInfo.ParentIndexNumber,
episodeInfo.IndexNumber,
series.GetProviderId(MetadataProviders.Tvdb));
return imageResult; return imageResult;
} }
}
var episodeResult = var episodeResult =
await _tvDbClientManager await _tvDbClientManager
@ -86,7 +84,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
} }
catch (TvDbServerException e) 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>(); 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
if (!searchInfo.IndexNumber.HasValue || !searchInfo.PremiereDate.HasValue) if (!searchInfo.IndexNumber.HasValue
|| !searchInfo.PremiereDate.HasValue
|| !TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds))
{ {
return list; 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; 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; var item = metadataResult.Item;
list.Add(new RemoteSearchResult list.Add(new RemoteSearchResult
@ -80,13 +63,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
SearchProviderName = Name, SearchProviderName = Name,
IndexNumberEnd = item.IndexNumberEnd IndexNumberEnd = item.IndexNumberEnd
}); });
}
}
catch (TvDbServerException e)
{
_logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", searchInfo.IndexNumber);
}
}
return list; return list;
} }
@ -103,36 +79,46 @@ namespace MediaBrowser.Providers.TV.TheTVDB
if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds) && if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds) &&
(searchInfo.IndexNumber.HasValue || searchInfo.PremiereDate.HasValue)) (searchInfo.IndexNumber.HasValue || searchInfo.PremiereDate.HasValue))
{ {
var tvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb); result = await GetEpisode(searchInfo, cancellationToken).ConfigureAwait(false);
try }
else
{ {
if (string.IsNullOrEmpty(tvdbId)) _logger.LogDebug("No series identity found for {EpisodeName}", searchInfo.Name);
{ }
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);
return result; 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( var episodeResult = await _tvDbClientManager.GetEpisodesAsync(
Convert.ToInt32(tvdbId), searchInfo.MetadataLanguage, Convert.ToInt32(episodeTvdbId), searchInfo.MetadataLanguage,
cancellationToken).ConfigureAwait(false); cancellationToken).ConfigureAwait(false);
result = MapEpisodeToResult(searchInfo, episodeResult.Data); result = MapEpisodeToResult(searchInfo, episodeResult.Data);
} }
catch (TvDbServerException e) catch (TvDbServerException e)
{ {
_logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", tvdbId); _logger.LogError(e, "Failed to retrieve episode with id {EpisodeTvDbId}, series id {SeriesTvdbId}", episodeTvdbId, seriesTvdbId);
}
}
else
{
_logger.LogDebug("No series identity found for {EpisodeName}", searchInfo.Name);
} }
return result; return result;