Add logging and fast return
This commit is contained in:
parent
370b7f8e12
commit
f059be8e4d
|
@ -15,6 +15,7 @@ using MediaBrowser.Model.Dto;
|
|||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.MediaInfo;
|
||||
using MediaBrowser.Model.Net;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace MediaBrowser.Providers.MediaInfo
|
||||
{
|
||||
|
@ -45,14 +46,17 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
};
|
||||
|
||||
private readonly IMediaEncoder _mediaEncoder;
|
||||
private readonly ILogger<EmbeddedImageProvider> _logger;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EmbeddedImageProvider"/> class.
|
||||
/// </summary>
|
||||
/// <param name="mediaEncoder">The media encoder for extracting attached/embedded images.</param>
|
||||
public EmbeddedImageProvider(IMediaEncoder mediaEncoder)
|
||||
/// <param name="logger">The logger.</param>
|
||||
public EmbeddedImageProvider(IMediaEncoder mediaEncoder, ILogger<EmbeddedImageProvider> logger)
|
||||
{
|
||||
_mediaEncoder = mediaEncoder;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
|
@ -117,6 +121,12 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
_ => Array.Empty<string>()
|
||||
};
|
||||
|
||||
if (imageFileNames.Length == 0)
|
||||
{
|
||||
_logger.LogWarning("Attempted to load unexpected image type: {Type}", type);
|
||||
return new DynamicImageResponse { HasImage = false };
|
||||
}
|
||||
|
||||
// Try attachments first
|
||||
var attachmentStream = item.GetMediaSources(false)
|
||||
.SelectMany(source => source.MediaAttachments)
|
||||
|
|
|
@ -11,6 +11,7 @@ using MediaBrowser.Model.Drawing;
|
|||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Providers.MediaInfo;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
using Moq;
|
||||
using Xunit;
|
||||
|
||||
|
@ -28,7 +29,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
|||
public void GetSupportedImages_AnyBaseItem_ReturnsExpected(Type type, params ImageType[] expected)
|
||||
{
|
||||
BaseItem item = (BaseItem)Activator.CreateInstance(type)!;
|
||||
var embeddedImageProvider = new EmbeddedImageProvider(Mock.Of<IMediaEncoder>());
|
||||
var embeddedImageProvider = new EmbeddedImageProvider(Mock.Of<IMediaEncoder>(), new NullLogger<EmbeddedImageProvider>());
|
||||
var actual = embeddedImageProvider.GetSupportedImages(item);
|
||||
Assert.Equal(expected.OrderBy(i => i.ToString()), actual.OrderBy(i => i.ToString()));
|
||||
}
|
||||
|
@ -36,7 +37,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
|||
[Fact]
|
||||
public async void GetImage_NoStreams_ReturnsNoImage()
|
||||
{
|
||||
var embeddedImageProvider = new EmbeddedImageProvider(null);
|
||||
var embeddedImageProvider = new EmbeddedImageProvider(null, new NullLogger<EmbeddedImageProvider>());
|
||||
|
||||
var input = GetMovie(new List<MediaAttachment>(), new List<MediaStream>());
|
||||
|
||||
|
@ -69,7 +70,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
|||
var mediaEncoder = new Mock<IMediaEncoder>(MockBehavior.Strict);
|
||||
mediaEncoder.Setup(encoder => encoder.ExtractVideoImage(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<MediaSourceInfo>(), It.IsAny<MediaStream>(), It.IsAny<int>(), It.IsAny<ImageFormat>(), It.IsAny<CancellationToken>()))
|
||||
.Returns<string, string, MediaSourceInfo, MediaStream, int, ImageFormat, CancellationToken>((_, _, _, _, index, ext, _) => Task.FromResult(pathPrefix + index + "." + ext));
|
||||
var embeddedImageProvider = new EmbeddedImageProvider(mediaEncoder.Object);
|
||||
var embeddedImageProvider = new EmbeddedImageProvider(mediaEncoder.Object, new NullLogger<EmbeddedImageProvider>());
|
||||
|
||||
var input = GetMovie(attachments, new List<MediaStream>());
|
||||
|
||||
|
@ -119,7 +120,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
|||
Assert.Equal(streams[index - 1], stream);
|
||||
return Task.FromResult(pathPrefix + index + "." + ext);
|
||||
});
|
||||
var embeddedImageProvider = new EmbeddedImageProvider(mediaEncoder.Object);
|
||||
var embeddedImageProvider = new EmbeddedImageProvider(mediaEncoder.Object, new NullLogger<EmbeddedImageProvider>());
|
||||
|
||||
var input = GetMovie(new List<MediaAttachment>(), streams);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user