diff --git a/MediaBrowser.Controller/Library/TVUtils.cs b/MediaBrowser.Controller/Library/TVUtils.cs index 3080143ce9..0089f65d0d 100644 --- a/MediaBrowser.Controller/Library/TVUtils.cs +++ b/MediaBrowser.Controller/Library/TVUtils.cs @@ -28,24 +28,24 @@ namespace MediaBrowser.Controller.Library { if (string.Equals(day, "Daily", StringComparison.OrdinalIgnoreCase)) { - return new DayOfWeek[] - { - DayOfWeek.Sunday, - DayOfWeek.Monday, - DayOfWeek.Tuesday, - DayOfWeek.Wednesday, - DayOfWeek.Thursday, - DayOfWeek.Friday, - DayOfWeek.Saturday - }; + return new[] + { + DayOfWeek.Sunday, + DayOfWeek.Monday, + DayOfWeek.Tuesday, + DayOfWeek.Wednesday, + DayOfWeek.Thursday, + DayOfWeek.Friday, + DayOfWeek.Saturday + }; } if (Enum.TryParse(day, true, out DayOfWeek value)) { - return new DayOfWeek[] - { - value - }; + return new[] + { + value + }; } return new DayOfWeek[] { }; diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs index bc526e42a9..74165e4bd2 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbEpisodeImageProvider.cs @@ -18,7 +18,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB { public class TvdbEpisodeImageProvider : IRemoteImageProvider { - private readonly CultureInfo _usCulture = new CultureInfo("en-US"); private readonly IHttpClient _httpClient; private readonly TvDbClientManager _tvDbClientManager; @@ -47,6 +46,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB { var episode = (Episode)item; var series = episode.Series; + var imageResult = new List(); if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds)) { @@ -55,21 +55,17 @@ namespace MediaBrowser.Providers.TV.TheTVDB var episodeResult = await _tvDbClientManager.TvDbClient.Episodes.GetAsync(Convert.ToInt32(tvdbId), cancellationToken); var image = GetImageInfo(episodeResult.Data); - return new List + if (image != null) { - image - }; + imageResult.Add(image); + } } - return new RemoteImageInfo[] { }; + return imageResult; } private RemoteImageInfo GetImageInfo(EpisodeRecord episode) { - var height = 225; - var width = 400; - var url = string.Empty; - if (string.IsNullOrEmpty(episode.Filename)) { return null; diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs index e592b20042..8f763f2c53 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeasonImageProvider.cs @@ -11,6 +11,7 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Providers; +using Microsoft.Extensions.Logging; using TvDbSharper; using TvDbSharper.Dto; using RatingType = MediaBrowser.Model.Dto.RatingType; @@ -22,11 +23,13 @@ namespace MediaBrowser.Providers.TV.TheTVDB private static readonly CultureInfo UsCulture = new CultureInfo("en-US"); private readonly IHttpClient _httpClient; + private readonly ILogger _logger; private readonly TvDbClientManager _tvDbClientManager; - public TvdbSeasonImageProvider(IHttpClient httpClient) + public TvdbSeasonImageProvider(IHttpClient httpClient, ILogger logger) { _httpClient = httpClient; + _logger = logger; _tvDbClientManager = TvDbClientManager.Instance; } @@ -59,13 +62,14 @@ namespace MediaBrowser.Providers.TV.TheTVDB return new RemoteImageInfo[] { }; } + var tvdbId = Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb)); var seasonNumber = season.IndexNumber.Value; var language = item.GetPreferredMetadataLanguage(); _tvDbClientManager.TvDbClient.AcceptedLanguage = language; var remoteImages = new List(); + var keyTypes = new[] {KeyType.Season, KeyType.Seasonwide, KeyType.Fanart}; - // TODO error handling - foreach (KeyType keyType in keyTypes) + foreach (var keyType in keyTypes) { var imageQuery = new ImagesQuery { @@ -74,15 +78,12 @@ namespace MediaBrowser.Providers.TV.TheTVDB }; try { - var imageResults = - await _tvDbClientManager.TvDbClient.Series.GetImagesAsync( - Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb)), imageQuery, - cancellationToken); + var imageResults = await _tvDbClientManager.TvDbClient.Series.GetImagesAsync(tvdbId, imageQuery, cancellationToken); remoteImages.AddRange(GetImages(imageResults.Data, language)); } catch (TvDbServerException e) { - // TODO log + _logger.LogInformation(e, "No images of type {KeyType} found for series {TvdbId}", keyType, tvdbId); } } diff --git a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs index d0a1f5ec19..25bea7821f 100644 --- a/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs +++ b/MediaBrowser.Providers/TV/TheTVDB/TvdbSeriesProvider.cs @@ -95,7 +95,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB result.Item = new Series(); result.HasMetadata = true; - FetchSeriesData(result, itemId.MetadataLanguage, itemId.ProviderIds, cancellationToken); + await FetchSeriesData(result, itemId.MetadataLanguage, itemId.ProviderIds, cancellationToken); } return result; @@ -127,7 +127,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB var seriesResult = await _tvDbClientManager.TvDbClient.Series.GetAsync(Convert.ToInt32(tvdbId), cancellationToken); // TODO error handling - MapSeriesToResult(result, seriesResult.Data, cancellationToken); + MapSeriesToResult(result, seriesResult.Data); cancellationToken.ThrowIfCancellationRequested(); @@ -161,51 +161,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB seriesProviderIds.TryGetValue(MetadataProviders.Zap2It.ToString(), out _); } - // TODO caching - private bool IsCacheValid(string seriesDataPath, string preferredMetadataLanguage) - { - return true; -// try -// { -// var files = _fileSystem.GetFiles(seriesDataPath, new[] { ".xml" }, true, false) -// .ToList(); -// -// var seriesXmlFilename = preferredMetadataLanguage + ".xml"; -// -// const int cacheHours = 12; -// -// var seriesFile = files.FirstOrDefault(i => string.Equals(seriesXmlFilename, i.Name, StringComparison.OrdinalIgnoreCase)); -// // No need to check age if automatic updates are enabled -// if (seriesFile == null || !seriesFile.Exists || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(seriesFile)).TotalHours > cacheHours) -// { -// return false; -// } -// -// var actorsXml = files.FirstOrDefault(i => string.Equals("actors.xml", i.Name, StringComparison.OrdinalIgnoreCase)); -// // No need to check age if automatic updates are enabled -// if (actorsXml == null || !actorsXml.Exists || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(actorsXml)).TotalHours > cacheHours) -// { -// return false; -// } -// -// var bannersXml = files.FirstOrDefault(i => string.Equals("banners.xml", i.Name, StringComparison.OrdinalIgnoreCase)); -// // No need to check age if automatic updates are enabled -// if (bannersXml == null || !bannersXml.Exists || (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(bannersXml)).TotalHours > cacheHours) -// { -// return false; -// } -// return true; -// } -// catch (FileNotFoundException) -// { -// return false; -// } -// catch (IOException) -// { -// return false; -// } - } - /// /// Finds the series. /// @@ -246,7 +201,16 @@ namespace MediaBrowser.Providers.TV.TheTVDB _tvDbClientManager.TvDbClient.AcceptedLanguage = NormalizeLanguage(language); var comparableName = GetComparableName(name); var list = new List, RemoteSearchResult>>(); - TvDbResponse result = await _tvDbClientManager.TvDbClient.Search.SearchSeriesByNameAsync(comparableName, cancellationToken); + TvDbResponse result; + try + { + result = await _tvDbClientManager.TvDbClient.Search.SearchSeriesByNameAsync(comparableName, cancellationToken); + } + catch (TvDbServerException e) + { + _logger.LogError(e, "No series results found for {Name}", comparableName); + return new List(); + } foreach (var seriesSearchResult in result.Data) { @@ -265,8 +229,18 @@ namespace MediaBrowser.Providers.TV.TheTVDB ImageUrl = TVUtils.BannerUrl + seriesSearchResult.Banner }; - // TODO requires another query, is it worth it? - // remoteSearchResult.SetProviderId(MetadataProviders.Imdb, seriesSearchResult.Id); + try + { + var seriesSesult = + await _tvDbClientManager.TvDbClient.Series.GetAsync(seriesSearchResult.Id, cancellationToken); + remoteSearchResult.SetProviderId(MetadataProviders.Imdb, seriesSesult.Data.ImdbId); + remoteSearchResult.SetProviderId(MetadataProviders.Zap2It, seriesSesult.Data.Zap2itId); + } + catch (TvDbServerException e) + { + _logger.LogError(e, "Unable to retrieve series with id {TvdbId}", seriesSearchResult.Id); + } + remoteSearchResult.SetProviderId(MetadataProviders.Tvdb, seriesSearchResult.Id.ToString()); list.Add(new Tuple, RemoteSearchResult>(tvdbTitles, remoteSearchResult)); } @@ -335,14 +309,13 @@ namespace MediaBrowser.Providers.TV.TheTVDB return name.Trim(); } - private static void MapSeriesToResult(MetadataResult result, TvDbSharper.Dto.Series tvdbSeries, CancellationToken cancellationToken) + private static void MapSeriesToResult(MetadataResult result, TvDbSharper.Dto.Series tvdbSeries) { - var episodeAirDates = new List(); Series series = result.Item; series.SetProviderId(MetadataProviders.Tvdb, tvdbSeries.Id.ToString()); series.Name = tvdbSeries.SeriesName; series.Overview = (tvdbSeries.Overview ?? string.Empty).Trim(); - // TODO result.ResultLanguage = (seriesResponse.Data. ?? string.Empty).Trim(); + result.ResultLanguage = TvDbClientManager.Instance.TvDbClient.AcceptedLanguage; series.AirDays = TVUtils.GetAirDays(tvdbSeries.AirsDayOfWeek); series.AirTime = tvdbSeries.AirsTime; @@ -368,14 +341,13 @@ namespace MediaBrowser.Providers.TV.TheTVDB series.AddGenre(genre); } - // TODO is network == studio? series.AddStudio(tvdbSeries.Network); // TODO is this necessary? - if (result.Item.Status.HasValue && result.Item.Status.Value == SeriesStatus.Ended && episodeAirDates.Count > 0) - { - result.Item.EndDate = episodeAirDates.Max(); - } + // if (result.Item.Status.HasValue && result.Item.Status.Value == SeriesStatus.Ended && episodeAirDates.Count > 0) + // { + // result.Item.EndDate = episodeAirDates.Max(); + // } } private static void MapActorsToResult(MetadataResult result, IEnumerable actors)