Add additional Series Image lookup

This commit is contained in:
crobibero 2020-11-12 14:02:57 -07:00
parent 0fd12b6f8f
commit a0f43f4953
2 changed files with 30 additions and 11 deletions

View File

@ -17,7 +17,7 @@
<PackageReference Include="Jellyfin.Controller" Version="10.6.0" />
<PackageReference Include="Jellyfin.Data" Version="10.6.0" />
<PackageReference Include="Jellyfin.Model" Version="10.6.0" />
<PackageReference Include="TvMaze.Api.Client" Version="0.0.29" />
<PackageReference Include="TvMaze.Api.Client" Version="0.0.33" />
</ItemGroup>
<!-- Code Analyzers-->

View File

@ -11,6 +11,7 @@ using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using Microsoft.Extensions.Logging;
using TvMaze.Api.Client;
using TvMaze.Api.Client.Models;
namespace Jellyfin.Plugin.TvMaze.Providers
{
@ -48,6 +49,8 @@ namespace Jellyfin.Plugin.TvMaze.Providers
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
yield return ImageType.Primary;
yield return ImageType.Backdrop;
yield return ImageType.Banner;
}
/// <inheritdoc />
@ -65,23 +68,27 @@ namespace Jellyfin.Plugin.TvMaze.Providers
return Enumerable.Empty<RemoteImageInfo>();
}
var tvMazeSeries = await _tvMazeClient.Shows.GetShowMainInformation(tvMazeId.Value).ConfigureAwait(false);
if (tvMazeSeries == null)
var images = await _tvMazeClient.Shows.GetShowImagesAsync(tvMazeId.Value).ConfigureAwait(false);
if (images == null)
{
_logger.LogDebug("[GetImages] No series found.");
_logger.LogDebug("[GetImages] No images found.");
return Enumerable.Empty<RemoteImageInfo>();
}
var imageResults = new List<RemoteImageInfo>();
if (tvMazeSeries.Image?.Original != null)
// Order by type, then by Main=true
foreach (var image in images.OrderBy(o => o.Type).ThenByDescending(o => o.Main))
{
imageResults.Add(new RemoteImageInfo
if (image.Resolutions.Original != null && image.Type.HasValue)
{
Url = tvMazeSeries.Image.Original,
ProviderName = TvMazePlugin.ProviderName,
Language = "en",
Type = ImageType.Primary
});
imageResults.Add(new RemoteImageInfo
{
Url = image.Resolutions.Original.Url,
ProviderName = TvMazePlugin.ProviderName,
Language = "en",
Type = GetImageType(image.Type.Value)
});
}
}
_logger.LogInformation("[GetImages] Images found for {name}: {@images}", item.Name, imageResults);
@ -103,5 +110,17 @@ namespace Jellyfin.Plugin.TvMaze.Providers
Url = url
});
}
private static ImageType GetImageType(ShowImageType showImageType)
{
return showImageType switch
{
ShowImageType.Poster => ImageType.Primary,
ShowImageType.Banner => ImageType.Banner,
ShowImageType.Background => ImageType.Backdrop,
ShowImageType.Typography => ImageType.Logo,
_ => throw new ArgumentOutOfRangeException(nameof(showImageType), showImageType, "Unknown ShowImageType")
};
}
}
}