diff options
| author | Luke <luke.pulverenti@gmail.com> | 2017-08-05 15:05:30 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-08-05 15:05:30 -0400 |
| commit | d8c2dd253277ba2ce7a5a7496b278db0e4e85106 (patch) | |
| tree | 176e34705fb03d79d9302cf7f8f8aa3f88958cca /MediaBrowser.Providers | |
| parent | e169eaee6cb2f91e4102f4fe7ac9075659feba95 (diff) | |
| parent | 804f19fc424e72ede16e66bc7809eab3450e528e (diff) | |
Merge pull request #2795 from MediaBrowser/dev
Dev
Diffstat (limited to 'MediaBrowser.Providers')
| -rw-r--r-- | MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs | 4 | ||||
| -rw-r--r-- | MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs | 78 | ||||
| -rw-r--r-- | MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs | 138 |
3 files changed, 78 insertions, 142 deletions
diff --git a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs index cc5e7aef9b..e406932ed8 100644 --- a/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/AudioImageProvider.cs @@ -41,9 +41,7 @@ namespace MediaBrowser.Providers.MediaInfo var audio = (Audio)item; var imageStreams = - audio.GetMediaSources(false) - .Take(1) - .SelectMany(i => i.MediaStreams) + audio.GetMediaStreams(MediaStreamType.EmbeddedImage) .Where(i => i.Type == MediaStreamType.EmbeddedImage) .ToList(); diff --git a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs index 06267f33a9..143ec8fdd6 100644 --- a/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs +++ b/MediaBrowser.Providers/MediaInfo/FFProbeVideoInfo.cs @@ -80,35 +80,45 @@ namespace MediaBrowser.Providers.MediaInfo try { - if (item.VideoType == VideoType.BluRay || (item.IsoType.HasValue && item.IsoType == IsoType.BluRay)) - { - var inputPath = isoMount != null ? isoMount.MountedPath : item.Path; + List<string> streamFileNames = null; - blurayDiscInfo = GetBDInfo(inputPath); + if (item.VideoType == VideoType.Iso) + { + item.IsoType = DetermineIsoType(isoMount); } - OnPreFetch(item, isoMount, blurayDiscInfo); - - // If we didn't find any satisfying the min length, just take them all if (item.VideoType == VideoType.Dvd || (item.IsoType.HasValue && item.IsoType == IsoType.Dvd)) { - if (item.PlayableStreamFileNames.Count == 0) + streamFileNames = FetchFromDvdLib(item, isoMount); + + if (streamFileNames.Count == 0) { _logger.Error("No playable vobs found in dvd structure, skipping ffprobe."); return ItemUpdateType.MetadataImport; } } - if (item.VideoType == VideoType.BluRay || (item.IsoType.HasValue && item.IsoType == IsoType.BluRay)) + else if (item.VideoType == VideoType.BluRay || (item.IsoType.HasValue && item.IsoType == IsoType.BluRay)) { - if (item.PlayableStreamFileNames.Count == 0) + var inputPath = isoMount != null ? isoMount.MountedPath : item.Path; + + blurayDiscInfo = GetBDInfo(inputPath); + + streamFileNames = blurayDiscInfo.Files; + + if (streamFileNames.Count == 0) { _logger.Error("No playable vobs found in bluray structure, skipping ffprobe."); return ItemUpdateType.MetadataImport; } } - var result = await GetMediaInfo(item, isoMount, cancellationToken).ConfigureAwait(false); + if (streamFileNames == null) + { + streamFileNames = new List<string>(); + } + + var result = await GetMediaInfo(item, isoMount, streamFileNames, cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); @@ -126,10 +136,9 @@ namespace MediaBrowser.Providers.MediaInfo return ItemUpdateType.MetadataImport; } - private const string SchemaVersion = "6"; - - private async Task<Model.MediaInfo.MediaInfo> GetMediaInfo(Video item, + private Task<Model.MediaInfo.MediaInfo> GetMediaInfo(Video item, IIsoMount isoMount, + List<string> streamFileNames, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); @@ -138,9 +147,9 @@ namespace MediaBrowser.Providers.MediaInfo ? MediaProtocol.Http : MediaProtocol.File; - var result = await _mediaEncoder.GetMediaInfo(new MediaInfoRequest + return _mediaEncoder.GetMediaInfo(new MediaInfoRequest { - PlayableStreamFileNames = item.PlayableStreamFileNames, + PlayableStreamFileNames = streamFileNames, MountedIso = isoMount, ExtractChapters = true, VideoType = item.VideoType, @@ -148,12 +157,7 @@ namespace MediaBrowser.Providers.MediaInfo InputPath = item.Path, Protocol = protocol - }, cancellationToken).ConfigureAwait(false); - - //Directory.CreateDirectory(_fileSystem.GetDirectoryName(cachePath)); - //_json.SerializeToFile(result, cachePath); - - return result; + }, cancellationToken); } protected async Task Fetch(Video video, @@ -266,7 +270,7 @@ namespace MediaBrowser.Providers.MediaInfo { var video = (Video)item; - video.PlayableStreamFileNames = blurayInfo.Files.ToList(); + //video.PlayableStreamFileNames = blurayInfo.Files.ToList(); // Use BD Info if it has multiple m2ts. Otherwise, treat it like a video file and rely more on ffprobe output if (blurayInfo.Files.Count > 1) @@ -559,31 +563,7 @@ namespace MediaBrowser.Providers.MediaInfo } } - /// <summary> - /// Called when [pre fetch]. - /// </summary> - /// <param name="item">The item.</param> - /// <param name="mount">The mount.</param> - /// <param name="blurayDiscInfo">The bluray disc information.</param> - private void OnPreFetch(Video item, IIsoMount mount, BlurayDiscInfo blurayDiscInfo) - { - if (item.VideoType == VideoType.Iso) - { - item.IsoType = DetermineIsoType(mount); - } - - if (item.VideoType == VideoType.Dvd || (item.IsoType.HasValue && item.IsoType == IsoType.Dvd)) - { - FetchFromDvdLib(item, mount); - } - - if (blurayDiscInfo != null) - { - item.PlayableStreamFileNames = blurayDiscInfo.Files.ToList(); - } - } - - private void FetchFromDvdLib(Video item, IIsoMount mount) + private List<string> FetchFromDvdLib(Video item, IIsoMount mount) { var path = mount == null ? item.Path : mount.MountedPath; var dvd = new Dvd(path, _fileSystem); @@ -598,7 +578,7 @@ namespace MediaBrowser.Providers.MediaInfo item.RunTimeTicks = GetRuntime(primaryTitle); } - item.PlayableStreamFileNames = GetPrimaryPlaylistVobFiles(item, mount, titleNumber) + return GetPrimaryPlaylistVobFiles(item, mount, titleNumber) .Select(Path.GetFileName) .ToList(); } diff --git a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs index bb1c4e6472..cdf5772c23 100644 --- a/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs +++ b/MediaBrowser.Providers/MediaInfo/VideoImageProvider.cs @@ -18,44 +18,17 @@ namespace MediaBrowser.Providers.MediaInfo { public class VideoImageProvider : IDynamicImageProvider, IHasItemChangeMonitor, IHasOrder { - private readonly IIsoManager _isoManager; private readonly IMediaEncoder _mediaEncoder; - private readonly IServerConfigurationManager _config; - private readonly ILibraryManager _libraryManager; private readonly ILogger _logger; private readonly IFileSystem _fileSystem; - public VideoImageProvider(IIsoManager isoManager, IMediaEncoder mediaEncoder, IServerConfigurationManager config, ILibraryManager libraryManager, ILogger logger, IFileSystem fileSystem) + public VideoImageProvider(IMediaEncoder mediaEncoder, ILogger logger, IFileSystem fileSystem) { - _isoManager = isoManager; _mediaEncoder = mediaEncoder; - _config = config; - _libraryManager = libraryManager; _logger = logger; _fileSystem = fileSystem; } - /// <summary> - /// The null mount task result - /// </summary> - protected readonly Task<IIsoMount> NullMountTaskResult = Task.FromResult<IIsoMount>(null); - - /// <summary> - /// Mounts the iso if needed. - /// </summary> - /// <param name="item">The item.</param> - /// <param name="cancellationToken">The cancellation token.</param> - /// <returns>Task{IIsoMount}.</returns> - protected Task<IIsoMount> MountIsoIfNeeded(Video item, CancellationToken cancellationToken) - { - if (item.VideoType == VideoType.Iso) - { - return _isoManager.Mount(item.Path, cancellationToken); - } - - return NullMountTaskResult; - } - public IEnumerable<ImageType> GetSupportedImages(IHasImages item) { return new List<ImageType> { ImageType.Primary }; @@ -71,8 +44,8 @@ namespace MediaBrowser.Providers.MediaInfo return Task.FromResult(new DynamicImageResponse { HasImage = false }); } - // Can't extract from iso's if we weren't unable to determine iso type - if (video.VideoType == VideoType.Iso && !video.IsoType.HasValue) + // No support for this + if (video.VideoType == VideoType.Iso) { return Task.FromResult(new DynamicImageResponse { HasImage = false }); } @@ -89,81 +62,66 @@ namespace MediaBrowser.Providers.MediaInfo public async Task<DynamicImageResponse> GetVideoImage(Video item, CancellationToken cancellationToken) { - var isoMount = await MountIsoIfNeeded(item, cancellationToken).ConfigureAwait(false); - - try - { - var protocol = item.LocationType == LocationType.Remote - ? MediaProtocol.Http - : MediaProtocol.File; + var protocol = item.LocationType == LocationType.Remote + ? MediaProtocol.Http + : MediaProtocol.File; - var inputPath = MediaEncoderHelpers.GetInputArgument(_fileSystem, item.Path, protocol, isoMount, item.PlayableStreamFileNames); + var inputPath = MediaEncoderHelpers.GetInputArgument(_fileSystem, item.Path, protocol, null, item.GetPlayableStreamFileNames()); - var mediaStreams = - item.GetMediaSources(false) - .Take(1) - .SelectMany(i => i.MediaStreams) - .ToList(); + var mediaStreams = + item.GetMediaStreams(); - var imageStreams = - mediaStreams - .Where(i => i.Type == MediaStreamType.EmbeddedImage) - .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(); + 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; + string extractedImagePath; - if (imageStream != null) + 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) { - // 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) { - if (mediaStream.Type == MediaStreamType.Video || - mediaStream.Type == MediaStreamType.EmbeddedImage) - { - videoIndex++; - } - if (mediaStream == imageStream) - { - break; - } + videoIndex++; + } + if (mediaStream == imageStream) + { + break; } - - extractedImagePath = await _mediaEncoder.ExtractVideoImage(inputPath, item.Container, protocol, imageStream, 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); - var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); + extractedImagePath = await _mediaEncoder.ExtractVideoImage(inputPath, item.Container, protocol, imageStream, 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, item.Container, protocol, videoStream, item.Video3DFormat, imageOffset, cancellationToken).ConfigureAwait(false); - } + var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); - return new DynamicImageResponse - { - Format = ImageFormat.Jpg, - HasImage = true, - Path = extractedImagePath, - Protocol = MediaProtocol.File - }; + extractedImagePath = await _mediaEncoder.ExtractVideoImage(inputPath, item.Container, protocol, videoStream, item.Video3DFormat, imageOffset, cancellationToken).ConfigureAwait(false); } - finally + + return new DynamicImageResponse { - if (isoMount != null) - { - isoMount.Dispose(); - } - } + Format = ImageFormat.Jpg, + HasImage = true, + Path = extractedImagePath, + Protocol = MediaProtocol.File + }; } public string Name |
