public async Task <IEnumerable <RemoteImageInfo> > GetImages(BaseItem item, CancellationToken cancellationToken) { var episode = (Episode)item; var series = episode.Series; var imageResult = new List <RemoteImageInfo>(); 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 { 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); } } var episodeResult = await _tvDbClientManager .GetEpisodesAsync(Convert.ToInt32(episodeTvdbId), language, cancellationToken) .ConfigureAwait(false); var image = GetImageInfo(episodeResult.Data); if (image != null) { imageResult.Add(image); } } catch (TvDbServerException e) { _logger.LogError(e, "Failed to retrieve episode images for {TvDbId}", episodeTvdbId); } } return(imageResult); }
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 {EpisodeTvDbId}, series id {SeriesTvdbId}", episodeTvdbId, seriesTvdbId); } return(result); }
public async Task <IEnumerable <RemoteSearchResult> > GetSearchResults(EpisodeInfo searchInfo, CancellationToken cancellationToken) { var list = new List <RemoteSearchResult>(); // The search query must either provide an episode number or date if (!searchInfo.IndexNumber.HasValue || !searchInfo.PremiereDate.HasValue) { return(list); } if (TvdbSeriesProvider.IsValidSeries(searchInfo.SeriesProviderIds)) { 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); }