Handle unexpected case more gracefully
This commit is contained in:
parent
1d729b2b0f
commit
370b7f8e12
|
@ -114,7 +114,7 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||||
ImageType.Primary => _primaryImageFileNames,
|
ImageType.Primary => _primaryImageFileNames,
|
||||||
ImageType.Backdrop => _backdropImageFileNames,
|
ImageType.Backdrop => _backdropImageFileNames,
|
||||||
ImageType.Logo => _logoImageFileNames,
|
ImageType.Logo => _logoImageFileNames,
|
||||||
_ => throw new ArgumentException("Unexpected image type: " + type)
|
_ => Array.Empty<string>()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Try attachments first
|
// Try attachments first
|
||||||
|
|
|
@ -46,6 +46,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
[InlineData("chapter", null, 1, ImageType.Chapter, null)] // unexpected type, nothing found
|
||||||
[InlineData("unmatched", null, 1, ImageType.Primary, null)] // doesn't default on no match
|
[InlineData("unmatched", null, 1, ImageType.Primary, null)] // doesn't default on no match
|
||||||
[InlineData("clearlogo.png", null, 1, ImageType.Logo, ImageFormat.Png)] // extract extension from name
|
[InlineData("clearlogo.png", null, 1, ImageType.Logo, ImageFormat.Png)] // extract extension from name
|
||||||
[InlineData("backdrop", "image/bmp", 2, ImageType.Backdrop, ImageFormat.Bmp)] // extract extension from mimetype
|
[InlineData("backdrop", "image/bmp", 2, ImageType.Backdrop, ImageFormat.Bmp)] // extract extension from mimetype
|
||||||
|
@ -87,14 +88,15 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(null, null, 1, ImageType.Backdrop, false, ImageFormat.Jpg)] // no label, can only find primary
|
[InlineData("chapter", null, 1, ImageType.Chapter, null)] // unexpected type, nothing found
|
||||||
[InlineData(null, null, 1, ImageType.Primary, true, ImageFormat.Jpg)] // no label, finds primary
|
[InlineData(null, null, 1, ImageType.Backdrop, null)] // no label, can only find primary
|
||||||
[InlineData("backdrop", null, 2, ImageType.Backdrop, true, ImageFormat.Jpg)] // uses label to find index 2, not just pulling first stream
|
[InlineData(null, null, 1, ImageType.Primary, ImageFormat.Jpg)] // no label, finds primary
|
||||||
[InlineData("cover", null, 2, ImageType.Primary, true, ImageFormat.Jpg)] // uses label to find index 2, not just pulling first stream
|
[InlineData("backdrop", null, 2, ImageType.Backdrop, ImageFormat.Jpg)] // uses label to find index 2, not just pulling first stream
|
||||||
[InlineData(null, "mjpeg", 1, ImageType.Primary, true, ImageFormat.Jpg)]
|
[InlineData("cover", null, 2, ImageType.Primary, ImageFormat.Jpg)] // uses label to find index 2, not just pulling first stream
|
||||||
[InlineData(null, "png", 1, ImageType.Primary, true, ImageFormat.Png)]
|
[InlineData(null, "mjpeg", 1, ImageType.Primary, ImageFormat.Jpg)]
|
||||||
[InlineData(null, "gif", 1, ImageType.Primary, true, ImageFormat.Gif)]
|
[InlineData(null, "png", 1, ImageType.Primary, ImageFormat.Png)]
|
||||||
public async void GetImage_Embedded_ReturnsCorrectSelection(string label, string? codec, int targetIndex, ImageType type, bool hasImage, ImageFormat expectedFormat)
|
[InlineData(null, "gif", 1, ImageType.Primary, ImageFormat.Gif)]
|
||||||
|
public async void GetImage_Embedded_ReturnsCorrectSelection(string label, string? codec, int targetIndex, ImageType type, ImageFormat? expectedFormat)
|
||||||
{
|
{
|
||||||
var streams = new List<MediaStream>();
|
var streams = new List<MediaStream>();
|
||||||
for (int i = 1; i <= targetIndex; i++)
|
for (int i = 1; i <= targetIndex; i++)
|
||||||
|
@ -123,9 +125,13 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
||||||
|
|
||||||
var actual = await embeddedImageProvider.GetImage(input, type, CancellationToken.None);
|
var actual = await embeddedImageProvider.GetImage(input, type, CancellationToken.None);
|
||||||
Assert.NotNull(actual);
|
Assert.NotNull(actual);
|
||||||
Assert.Equal(hasImage, actual.HasImage);
|
if (expectedFormat == null)
|
||||||
if (hasImage)
|
|
||||||
{
|
{
|
||||||
|
Assert.False(actual.HasImage);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Assert.True(actual.HasImage);
|
||||||
Assert.Equal(pathPrefix + targetIndex + "." + expectedFormat, actual.Path, StringComparer.OrdinalIgnoreCase);
|
Assert.Equal(pathPrefix + targetIndex + "." + expectedFormat, actual.Path, StringComparer.OrdinalIgnoreCase);
|
||||||
Assert.Equal(expectedFormat, actual.Format);
|
Assert.Equal(expectedFormat, actual.Format);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user