|
@@ -3,10 +3,12 @@
|
|
|
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
+using System.Collections.Immutable;
|
|
|
using System.Linq;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
+using MediaBrowser.Controller.Entities.TV;
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
|
|
using MediaBrowser.Controller.Providers;
|
|
|
using MediaBrowser.Model.Drawing;
|
|
@@ -22,6 +24,27 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
/// </summary>
|
|
|
public class EmbeddedImageProvider : IDynamicImageProvider, IHasOrder
|
|
|
{
|
|
|
+ private static readonly string[] _primaryImageFileNames =
|
|
|
+ {
|
|
|
+ "poster",
|
|
|
+ "folder",
|
|
|
+ "cover",
|
|
|
+ "default"
|
|
|
+ };
|
|
|
+
|
|
|
+ private static readonly string[] _backdropImageFileNames =
|
|
|
+ {
|
|
|
+ "backdrop",
|
|
|
+ "fanart",
|
|
|
+ "background",
|
|
|
+ "art"
|
|
|
+ };
|
|
|
+
|
|
|
+ private static readonly string[] _logoImageFileNames =
|
|
|
+ {
|
|
|
+ "logo",
|
|
|
+ };
|
|
|
+
|
|
|
private readonly IMediaEncoder _mediaEncoder;
|
|
|
private readonly ILogger<EmbeddedImageProvider> _logger;
|
|
|
|
|
@@ -41,7 +64,25 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
/// <inheritdoc />
|
|
|
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
|
|
|
{
|
|
|
- return new[] { ImageType.Primary };
|
|
|
+ if (item is Video)
|
|
|
+ {
|
|
|
+ if (item is Episode)
|
|
|
+ {
|
|
|
+ return new List<ImageType>
|
|
|
+ {
|
|
|
+ ImageType.Primary,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ return new List<ImageType>
|
|
|
+ {
|
|
|
+ ImageType.Primary,
|
|
|
+ ImageType.Backdrop,
|
|
|
+ ImageType.Logo,
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ return ImmutableList<ImageType>.Empty;
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc />
|
|
@@ -62,10 +103,10 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
return Task.FromResult(new DynamicImageResponse { HasImage = false });
|
|
|
}
|
|
|
|
|
|
- return GetEmbeddedImage(video, cancellationToken);
|
|
|
+ return GetEmbeddedImage(video, type, cancellationToken);
|
|
|
}
|
|
|
|
|
|
- private async Task<DynamicImageResponse> GetEmbeddedImage(Video item, CancellationToken cancellationToken)
|
|
|
+ private async Task<DynamicImageResponse> GetEmbeddedImage(Video item, ImageType type, CancellationToken cancellationToken)
|
|
|
{
|
|
|
MediaSourceInfo mediaSource = new MediaSourceInfo
|
|
|
{
|
|
@@ -74,27 +115,53 @@ namespace MediaBrowser.Providers.MediaInfo
|
|
|
Protocol = item.PathProtocol ?? MediaProtocol.File,
|
|
|
};
|
|
|
|
|
|
+ string[] imageFileNames;
|
|
|
+ switch (type)
|
|
|
+ {
|
|
|
+ case ImageType.Backdrop:
|
|
|
+ imageFileNames = _backdropImageFileNames;
|
|
|
+ break;
|
|
|
+ case ImageType.Logo:
|
|
|
+ imageFileNames = _logoImageFileNames;
|
|
|
+ break;
|
|
|
+ case ImageType.Primary:
|
|
|
+ default:
|
|
|
+ imageFileNames = _primaryImageFileNames;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
var imageStreams =
|
|
|
item.GetMediaStreams()
|
|
|
.Where(i => i.Type == MediaStreamType.EmbeddedImage)
|
|
|
.ToList();
|
|
|
|
|
|
- string extractedImagePath;
|
|
|
-
|
|
|
- if (imageStreams.Count == 0)
|
|
|
+ if (!imageStreams.Any())
|
|
|
{
|
|
|
// Can't extract if we don't have any EmbeddedImage streams
|
|
|
return new DynamicImageResponse { HasImage = false };
|
|
|
}
|
|
|
- else
|
|
|
- {
|
|
|
- var imageStream = imageStreams.Find(i => (i.Comment ?? string.Empty).Contains("front", StringComparison.OrdinalIgnoreCase))
|
|
|
- ?? imageStreams.Find(i => (i.Comment ?? string.Empty).Contains("cover", StringComparison.OrdinalIgnoreCase))
|
|
|
- ?? imageStreams[0];
|
|
|
|
|
|
- extractedImagePath = await _mediaEncoder.ExtractVideoImage(item.Path, item.Container, mediaSource, imageStream, imageStream.Index, cancellationToken).ConfigureAwait(false);
|
|
|
+ // Extract first stream containing an element of imageFileNames
|
|
|
+ var imageStream = imageStreams
|
|
|
+ .Where(stream => !string.IsNullOrEmpty(stream.Comment))
|
|
|
+ .First(stream => imageFileNames.Any(name => stream.Comment.Contains(name, StringComparison.OrdinalIgnoreCase)));
|
|
|
+
|
|
|
+ // Primary type only: default to first image if none found by label
|
|
|
+ if (imageStream == null)
|
|
|
+ {
|
|
|
+ if (type == ImageType.Primary)
|
|
|
+ {
|
|
|
+ imageStream = imageStreams[0];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // No streams matched, abort
|
|
|
+ return new DynamicImageResponse { HasImage = false };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ string extractedImagePath = await _mediaEncoder.ExtractVideoImage(item.Path, item.Container, mediaSource, imageStream, imageStream.Index, cancellationToken).ConfigureAwait(false);
|
|
|
+
|
|
|
return new DynamicImageResponse
|
|
|
{
|
|
|
Format = ImageFormat.Jpg,
|