Fetch image keytypes before querying images

pull/3566/head
Claus Vium 4 years ago
parent 2307052efc
commit 8c0168ef72

@ -229,6 +229,51 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
return GetEpisodesPageAsync(tvdbId, 1, episodeQuery, language, cancellationToken);
}
public async Task<IEnumerable<KeyType>> GetImageKeyTypesForSeriesAsync(int tvdbId, string language, CancellationToken cancellationToken)
{
var cacheKey = GenerateKey(nameof(TvDbClient.Series.GetImagesSummaryAsync), tvdbId);
var imagesSummary = await TryGetValue(cacheKey, language, () => TvDbClient.Series.GetImagesSummaryAsync(tvdbId, cancellationToken)).ConfigureAwait(false);
var keyTypes = new List<KeyType>();
if (imagesSummary.Data.Fanart > 0)
{
keyTypes.Add(KeyType.Fanart);
}
if (imagesSummary.Data.Series > 0)
{
keyTypes.Add(KeyType.Series);
}
if (imagesSummary.Data.Poster > 0)
{
keyTypes.Add(KeyType.Poster);
}
return keyTypes;
}
public async Task<IEnumerable<KeyType>> GetImageKeyTypesForSeasonAsync(int tvdbId, string language, CancellationToken cancellationToken)
{
var cacheKey = GenerateKey(nameof(TvDbClient.Series.GetImagesSummaryAsync), tvdbId);
var imagesSummary = await TryGetValue(cacheKey, language, () => TvDbClient.Series.GetImagesSummaryAsync(tvdbId, cancellationToken)).ConfigureAwait(false);
var keyTypes = new List<KeyType>();
if (imagesSummary.Data.Season > 0)
{
keyTypes.Add(KeyType.Season);
}
if (imagesSummary.Data.Fanart > 0)
{
keyTypes.Add(KeyType.Fanart);
}
// TODO seasonwide is not supported in TvDbSharper
return keyTypes;
}
private async Task<T> TryGetValue<T>(string key, string language, Func<Task<T>> resultFactory)
{
if (_cache.TryGetValue(key, out T cachedValue))

@ -65,7 +65,7 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
var language = item.GetPreferredMetadataLanguage();
var remoteImages = new List<RemoteImageInfo>();
var keyTypes = new[] { KeyType.Season, KeyType.Seasonwide, KeyType.Fanart };
var keyTypes = await _tvdbClientManager.GetImageKeyTypesForSeasonAsync(tvdbId, language, cancellationToken).ConfigureAwait(false);
foreach (var keyType in keyTypes)
{
var imageQuery = new ImagesQuery

@ -59,9 +59,10 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
var language = item.GetPreferredMetadataLanguage();
var remoteImages = new List<RemoteImageInfo>();
var keyTypes = new[] { KeyType.Poster, KeyType.Series, KeyType.Fanart };
var tvdbId = Convert.ToInt32(item.GetProviderId(MetadataProvider.Tvdb));
foreach (KeyType keyType in keyTypes)
var allowedKeyTypes = await _tvdbClientManager.GetImageKeyTypesForSeriesAsync(tvdbId, language, cancellationToken)
.ConfigureAwait(false);
foreach (KeyType keyType in allowedKeyTypes)
{
var imageQuery = new ImagesQuery
{

@ -247,10 +247,15 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
{
Name = tvdbTitles.FirstOrDefault(),
ProductionYear = firstAired.Year,
SearchProviderName = Name,
ImageUrl = TvdbUtils.BannerUrl + seriesSearchResult.Banner
SearchProviderName = Name
};
if (!string.IsNullOrEmpty(seriesSearchResult.Banner))
{
// Results from their Search endpoints already include the /banners/ part in the url, because reasons...
remoteSearchResult.ImageUrl = TvdbUtils.TvdbImageBaseUrl + seriesSearchResult.Banner;
}
try
{
var seriesSesult =
@ -365,10 +370,14 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
Type = PersonType.Actor,
Name = (actor.Name ?? string.Empty).Trim(),
Role = actor.Role,
ImageUrl = TvdbUtils.BannerUrl + actor.Image,
SortOrder = actor.SortOrder
};
if (!string.IsNullOrEmpty(actor.Image))
{
personInfo.ImageUrl = TvdbUtils.TvdbImageBaseUrl + actor.Image;
}
if (!string.IsNullOrWhiteSpace(personInfo.Name))
{
result.AddPerson(personInfo);

@ -9,7 +9,8 @@ namespace MediaBrowser.Providers.Plugins.TheTvdb
{
public const string TvdbApiKey = "OG4V3YJ3FAP7FP2K";
public const string TvdbBaseUrl = "https://www.thetvdb.com/";
public const string BannerUrl = TvdbBaseUrl + "banners/";
public const string TvdbImageBaseUrl = "https://www.thetvdb.com";
public const string BannerUrl = TvdbImageBaseUrl + "/banners/";
public static ImageType GetImageTypeFromKeyType(string keyType)
{

Loading…
Cancel
Save