Always fetch episode id as EpisodeInfo does not contain it

pull/1628/head
Claus Vium 5 years ago
parent 685e9e4f58
commit 14575f0a06

@ -50,27 +50,22 @@ 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
{
var episodeInfo = new EpisodeInfo
{
IndexNumber = episode.IndexNumber.Value,
ParentIndexNumber = episode.ParentIndexNumber.Value,
SeriesProviderIds = series.ProviderIds
};
string episodeTvdbId = await _tvDbClientManager
.GetEpisodeTvdbId(episodeInfo, language, cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(episodeTvdbId))
{
var episodeInfo = new EpisodeInfo
{
IndexNumber = episode.IndexNumber.Value,
ParentIndexNumber = episode.ParentIndexNumber.Value,
SeriesProviderIds = series.ProviderIds
};
episodeTvdbId = await _tvDbClientManager
.GetEpisodeTvdbId(episodeInfo, language, cancellationToken).ConfigureAwait(false);
if (string.IsNullOrEmpty(episodeTvdbId))
{
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
episodeInfo.ParentIndexNumber, episodeInfo.IndexNumber, series.GetProviderId(MetadataProviders.Tvdb));
return imageResult;
}
_logger.LogError("Episode {SeasonNumber}x{EpisodeNumber} not found for series {SeriesTvdbId}",
episodeInfo.ParentIndexNumber, episodeInfo.IndexNumber, series.GetProviderId(MetadataProviders.Tvdb));
return imageResult;
}
var episodeResult =
@ -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));
}
}

@ -36,58 +36,34 @@ 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
{
IndexNumber = item.IndexNumber,
Name = item.Name,
ParentIndexNumber = item.ParentIndexNumber,
PremiereDate = item.PremiereDate,
ProductionYear = item.ProductionYear,
ProviderIds = item.ProviderIds,
SearchProviderName = Name,
IndexNumberEnd = item.IndexNumberEnd
});
}
}
catch (TvDbServerException e)
{
_logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", searchInfo.IndexNumber);
}
return list;
}
var item = metadataResult.Item;
list.Add(new RemoteSearchResult
{
IndexNumber = item.IndexNumber,
Name = item.Name,
ParentIndexNumber = item.ParentIndexNumber,
PremiereDate = item.PremiereDate,
ProductionYear = item.ProductionYear,
ProviderIds = item.ProviderIds,
SearchProviderName = Name,
IndexNumberEnd = item.IndexNumberEnd
});
return list;
}
@ -103,32 +79,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds) &&
(searchInfo.IndexNumber.HasValue || searchInfo.PremiereDate.HasValue))
{
var tvdbId = searchInfo.GetProviderId(MetadataProviders.Tvdb);
try
{
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);
return result;
}
}
var episodeResult = await _tvDbClientManager.GetEpisodesAsync(
Convert.ToInt32(tvdbId), searchInfo.MetadataLanguage,
cancellationToken).ConfigureAwait(false);
result = MapEpisodeToResult(searchInfo, episodeResult.Data);
}
catch (TvDbServerException e)
{
_logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", tvdbId);
}
result = await GetEpisode(searchInfo, cancellationToken).ConfigureAwait(false);
}
else
{
@ -138,6 +89,41 @@ namespace MediaBrowser.Providers.TV.TheTVDB
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(episodeTvdbId), searchInfo.MetadataLanguage,
cancellationToken).ConfigureAwait(false);
result = MapEpisodeToResult(searchInfo, episodeResult.Data);
}
catch (TvDbServerException e)
{
_logger.LogError(e, "Failed to retrieve episode with id {TvDbId}", episodeTvdbId ?? seriesTvdbId);
}
return result;
}
private static MetadataResult<Episode> MapEpisodeToResult(EpisodeInfo id, EpisodeRecord episode)
{
var result = new MetadataResult<Episode>

Loading…
Cancel
Save