diff options
Diffstat (limited to 'MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs')
| -rw-r--r-- | MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs | 70 |
1 files changed, 55 insertions, 15 deletions
diff --git a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs index f3235a102..5fc363062 100644 --- a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs @@ -10,6 +10,8 @@ using MediaBrowser.Model.Logging; using MediaBrowser.Model.MediaInfo; using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Threading; using System.Threading.Tasks; using CommonIO; @@ -93,26 +95,66 @@ namespace MediaBrowser.Providers.MediaInfo try { - // If we know the duration, grab it from 10% into the video. Otherwise just 10 seconds in. - // Always use 10 seconds for dvd because our duration could be out of whack - var imageOffset = item.VideoType != VideoType.Dvd && item.RunTimeTicks.HasValue && - item.RunTimeTicks.Value > 0 - ? TimeSpan.FromTicks(Convert.ToInt64(item.RunTimeTicks.Value * .1)) - : TimeSpan.FromSeconds(10); - var protocol = item.LocationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File; var inputPath = MediaEncoderHelpers.GetInputArgument(_fileSystem, item.Path, protocol, isoMount, item.PlayableStreamFileNames); - var stream = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, item.Video3DFormat, imageOffset, cancellationToken).ConfigureAwait(false); + var mediaStreams = + item.GetMediaSources(false) + .Take(1) + .SelectMany(i => i.MediaStreams) + .ToList(); + + var imageStreams = + mediaStreams + .Where(i => i.Type == MediaStreamType.EmbeddedImage) + .ToList(); + + var imageStream = imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("front", StringComparison.OrdinalIgnoreCase) != -1) ?? + imageStreams.FirstOrDefault(i => (i.Comment ?? string.Empty).IndexOf("cover", StringComparison.OrdinalIgnoreCase) != -1) ?? + imageStreams.FirstOrDefault(); + + string extractedImagePath; + + if (imageStream != null) + { + // Instead of using the raw stream index, we need to use nth video/embedded image stream + var videoIndex = -1; + foreach (var mediaStream in mediaStreams) + { + if (mediaStream.Type == MediaStreamType.Video || + mediaStream.Type == MediaStreamType.EmbeddedImage) + { + videoIndex++; + } + if (mediaStream == imageStream) + { + break; + } + } + + extractedImagePath = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, videoIndex, cancellationToken).ConfigureAwait(false); + } + else + { + // If we know the duration, grab it from 10% into the video. Otherwise just 10 seconds in. + // Always use 10 seconds for dvd because our duration could be out of whack + var imageOffset = item.VideoType != VideoType.Dvd && item.RunTimeTicks.HasValue && + item.RunTimeTicks.Value > 0 + ? TimeSpan.FromTicks(Convert.ToInt64(item.RunTimeTicks.Value * .1)) + : TimeSpan.FromSeconds(10); + + extractedImagePath = await _mediaEncoder.ExtractVideoImage(inputPath, protocol, item.Video3DFormat, imageOffset, cancellationToken).ConfigureAwait(false); + } return new DynamicImageResponse { Format = ImageFormat.Jpg, HasImage = true, - Stream = stream + Path = extractedImagePath, + Protocol = MediaProtocol.File }; } finally @@ -151,14 +193,12 @@ namespace MediaBrowser.Providers.MediaInfo } } - public bool HasChanged(IHasMetadata item, MetadataStatus status, IDirectoryService directoryService) + public bool HasChanged(IHasMetadata item, IDirectoryService directoryService) { - if (status.ItemDateModified.HasValue) + var file = directoryService.GetFile(item.Path); + if (file != null && file.LastWriteTimeUtc != item.DateModified) { - if (status.ItemDateModified.Value != item.DateModified) - { - return true; - } + return true; } return false; |
