Add some error handling, grab imdb id and other minor fixes
This commit is contained in:
parent
2a26760911
commit
ecbc0538f6
|
@ -28,24 +28,24 @@ namespace MediaBrowser.Controller.Library
|
||||||
{
|
{
|
||||||
if (string.Equals(day, "Daily", StringComparison.OrdinalIgnoreCase))
|
if (string.Equals(day, "Daily", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return new DayOfWeek[]
|
return new[]
|
||||||
{
|
{
|
||||||
DayOfWeek.Sunday,
|
DayOfWeek.Sunday,
|
||||||
DayOfWeek.Monday,
|
DayOfWeek.Monday,
|
||||||
DayOfWeek.Tuesday,
|
DayOfWeek.Tuesday,
|
||||||
DayOfWeek.Wednesday,
|
DayOfWeek.Wednesday,
|
||||||
DayOfWeek.Thursday,
|
DayOfWeek.Thursday,
|
||||||
DayOfWeek.Friday,
|
DayOfWeek.Friday,
|
||||||
DayOfWeek.Saturday
|
DayOfWeek.Saturday
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Enum.TryParse(day, true, out DayOfWeek value))
|
if (Enum.TryParse(day, true, out DayOfWeek value))
|
||||||
{
|
{
|
||||||
return new DayOfWeek[]
|
return new[]
|
||||||
{
|
{
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return new DayOfWeek[] { };
|
return new DayOfWeek[] { };
|
||||||
|
|
|
@ -18,7 +18,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
{
|
{
|
||||||
public class TvdbEpisodeImageProvider : IRemoteImageProvider
|
public class TvdbEpisodeImageProvider : IRemoteImageProvider
|
||||||
{
|
{
|
||||||
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
|
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClient _httpClient;
|
||||||
private readonly TvDbClientManager _tvDbClientManager;
|
private readonly TvDbClientManager _tvDbClientManager;
|
||||||
|
|
||||||
|
@ -47,6 +46,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
{
|
{
|
||||||
var episode = (Episode)item;
|
var episode = (Episode)item;
|
||||||
var series = episode.Series;
|
var series = episode.Series;
|
||||||
|
var imageResult = new List<RemoteImageInfo>();
|
||||||
|
|
||||||
if (series != null && TvdbSeriesProvider.IsValidSeries(series.ProviderIds))
|
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 episodeResult = await _tvDbClientManager.TvDbClient.Episodes.GetAsync(Convert.ToInt32(tvdbId), cancellationToken);
|
||||||
|
|
||||||
var image = GetImageInfo(episodeResult.Data);
|
var image = GetImageInfo(episodeResult.Data);
|
||||||
return new List<RemoteImageInfo>
|
if (image != null)
|
||||||
{
|
{
|
||||||
image
|
imageResult.Add(image);
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RemoteImageInfo[] { };
|
return imageResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private RemoteImageInfo GetImageInfo(EpisodeRecord episode)
|
private RemoteImageInfo GetImageInfo(EpisodeRecord episode)
|
||||||
{
|
{
|
||||||
var height = 225;
|
|
||||||
var width = 400;
|
|
||||||
var url = string.Empty;
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(episode.Filename))
|
if (string.IsNullOrEmpty(episode.Filename))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -11,6 +11,7 @@ using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Providers;
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Model.Entities;
|
using MediaBrowser.Model.Entities;
|
||||||
using MediaBrowser.Model.Providers;
|
using MediaBrowser.Model.Providers;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using TvDbSharper;
|
using TvDbSharper;
|
||||||
using TvDbSharper.Dto;
|
using TvDbSharper.Dto;
|
||||||
using RatingType = MediaBrowser.Model.Dto.RatingType;
|
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 static readonly CultureInfo UsCulture = new CultureInfo("en-US");
|
||||||
|
|
||||||
private readonly IHttpClient _httpClient;
|
private readonly IHttpClient _httpClient;
|
||||||
|
private readonly ILogger _logger;
|
||||||
private readonly TvDbClientManager _tvDbClientManager;
|
private readonly TvDbClientManager _tvDbClientManager;
|
||||||
|
|
||||||
public TvdbSeasonImageProvider(IHttpClient httpClient)
|
public TvdbSeasonImageProvider(IHttpClient httpClient, ILogger logger)
|
||||||
{
|
{
|
||||||
_httpClient = httpClient;
|
_httpClient = httpClient;
|
||||||
|
_logger = logger;
|
||||||
_tvDbClientManager = TvDbClientManager.Instance;
|
_tvDbClientManager = TvDbClientManager.Instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,13 +62,14 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
return new RemoteImageInfo[] { };
|
return new RemoteImageInfo[] { };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var tvdbId = Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb));
|
||||||
var seasonNumber = season.IndexNumber.Value;
|
var seasonNumber = season.IndexNumber.Value;
|
||||||
var language = item.GetPreferredMetadataLanguage();
|
var language = item.GetPreferredMetadataLanguage();
|
||||||
_tvDbClientManager.TvDbClient.AcceptedLanguage = language;
|
_tvDbClientManager.TvDbClient.AcceptedLanguage = language;
|
||||||
var remoteImages = new List<RemoteImageInfo>();
|
var remoteImages = new List<RemoteImageInfo>();
|
||||||
|
|
||||||
var keyTypes = new[] {KeyType.Season, KeyType.Seasonwide, KeyType.Fanart};
|
var keyTypes = new[] {KeyType.Season, KeyType.Seasonwide, KeyType.Fanart};
|
||||||
// TODO error handling
|
foreach (var keyType in keyTypes)
|
||||||
foreach (KeyType keyType in keyTypes)
|
|
||||||
{
|
{
|
||||||
var imageQuery = new ImagesQuery
|
var imageQuery = new ImagesQuery
|
||||||
{
|
{
|
||||||
|
@ -74,15 +78,12 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
};
|
};
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var imageResults =
|
var imageResults = await _tvDbClientManager.TvDbClient.Series.GetImagesAsync(tvdbId, imageQuery, cancellationToken);
|
||||||
await _tvDbClientManager.TvDbClient.Series.GetImagesAsync(
|
|
||||||
Convert.ToInt32(series.GetProviderId(MetadataProviders.Tvdb)), imageQuery,
|
|
||||||
cancellationToken);
|
|
||||||
remoteImages.AddRange(GetImages(imageResults.Data, language));
|
remoteImages.AddRange(GetImages(imageResults.Data, language));
|
||||||
}
|
}
|
||||||
catch (TvDbServerException e)
|
catch (TvDbServerException e)
|
||||||
{
|
{
|
||||||
// TODO log
|
_logger.LogInformation(e, "No images of type {KeyType} found for series {TvdbId}", keyType, tvdbId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
result.Item = new Series();
|
result.Item = new Series();
|
||||||
result.HasMetadata = true;
|
result.HasMetadata = true;
|
||||||
|
|
||||||
FetchSeriesData(result, itemId.MetadataLanguage, itemId.ProviderIds, cancellationToken);
|
await FetchSeriesData(result, itemId.MetadataLanguage, itemId.ProviderIds, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -127,7 +127,7 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
var seriesResult = await _tvDbClientManager.TvDbClient.Series.GetAsync(Convert.ToInt32(tvdbId), cancellationToken);
|
var seriesResult = await _tvDbClientManager.TvDbClient.Series.GetAsync(Convert.ToInt32(tvdbId), cancellationToken);
|
||||||
|
|
||||||
// TODO error handling
|
// TODO error handling
|
||||||
MapSeriesToResult(result, seriesResult.Data, cancellationToken);
|
MapSeriesToResult(result, seriesResult.Data);
|
||||||
|
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
|
||||||
|
@ -161,51 +161,6 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
seriesProviderIds.TryGetValue(MetadataProviders.Zap2It.ToString(), out _);
|
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;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finds the series.
|
/// Finds the series.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -246,7 +201,16 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
_tvDbClientManager.TvDbClient.AcceptedLanguage = NormalizeLanguage(language);
|
_tvDbClientManager.TvDbClient.AcceptedLanguage = NormalizeLanguage(language);
|
||||||
var comparableName = GetComparableName(name);
|
var comparableName = GetComparableName(name);
|
||||||
var list = new List<Tuple<List<string>, RemoteSearchResult>>();
|
var list = new List<Tuple<List<string>, RemoteSearchResult>>();
|
||||||
TvDbResponse<SeriesSearchResult[]> result = await _tvDbClientManager.TvDbClient.Search.SearchSeriesByNameAsync(comparableName, cancellationToken);
|
TvDbResponse<SeriesSearchResult[]> 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<RemoteSearchResult>();
|
||||||
|
}
|
||||||
|
|
||||||
foreach (var seriesSearchResult in result.Data)
|
foreach (var seriesSearchResult in result.Data)
|
||||||
{
|
{
|
||||||
|
@ -265,8 +229,18 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
ImageUrl = TVUtils.BannerUrl + seriesSearchResult.Banner
|
ImageUrl = TVUtils.BannerUrl + seriesSearchResult.Banner
|
||||||
|
|
||||||
};
|
};
|
||||||
// TODO requires another query, is it worth it?
|
try
|
||||||
// remoteSearchResult.SetProviderId(MetadataProviders.Imdb, seriesSearchResult.Id);
|
{
|
||||||
|
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());
|
remoteSearchResult.SetProviderId(MetadataProviders.Tvdb, seriesSearchResult.Id.ToString());
|
||||||
list.Add(new Tuple<List<string>, RemoteSearchResult>(tvdbTitles, remoteSearchResult));
|
list.Add(new Tuple<List<string>, RemoteSearchResult>(tvdbTitles, remoteSearchResult));
|
||||||
}
|
}
|
||||||
|
@ -335,14 +309,13 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
return name.Trim();
|
return name.Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MapSeriesToResult(MetadataResult<Series> result, TvDbSharper.Dto.Series tvdbSeries, CancellationToken cancellationToken)
|
private static void MapSeriesToResult(MetadataResult<Series> result, TvDbSharper.Dto.Series tvdbSeries)
|
||||||
{
|
{
|
||||||
var episodeAirDates = new List<DateTime>();
|
|
||||||
Series series = result.Item;
|
Series series = result.Item;
|
||||||
series.SetProviderId(MetadataProviders.Tvdb, tvdbSeries.Id.ToString());
|
series.SetProviderId(MetadataProviders.Tvdb, tvdbSeries.Id.ToString());
|
||||||
series.Name = tvdbSeries.SeriesName;
|
series.Name = tvdbSeries.SeriesName;
|
||||||
series.Overview = (tvdbSeries.Overview ?? string.Empty).Trim();
|
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.AirDays = TVUtils.GetAirDays(tvdbSeries.AirsDayOfWeek);
|
||||||
series.AirTime = tvdbSeries.AirsTime;
|
series.AirTime = tvdbSeries.AirsTime;
|
||||||
|
|
||||||
|
@ -368,14 +341,13 @@ namespace MediaBrowser.Providers.TV.TheTVDB
|
||||||
series.AddGenre(genre);
|
series.AddGenre(genre);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO is network == studio?
|
|
||||||
series.AddStudio(tvdbSeries.Network);
|
series.AddStudio(tvdbSeries.Network);
|
||||||
|
|
||||||
// TODO is this necessary?
|
// TODO is this necessary?
|
||||||
if (result.Item.Status.HasValue && result.Item.Status.Value == SeriesStatus.Ended && episodeAirDates.Count > 0)
|
// if (result.Item.Status.HasValue && result.Item.Status.Value == SeriesStatus.Ended && episodeAirDates.Count > 0)
|
||||||
{
|
// {
|
||||||
result.Item.EndDate = episodeAirDates.Max();
|
// result.Item.EndDate = episodeAirDates.Max();
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void MapActorsToResult(MetadataResult<Series> result, IEnumerable<Actor> actors)
|
private static void MapActorsToResult(MetadataResult<Series> result, IEnumerable<Actor> actors)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user