From aae259d2cd06dc59d279cf04b0f94a09d485cba0 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Mon, 20 Aug 2012 15:16:51 -0400 Subject: Initial check-in of VideoInfoProvider, although it's currently disabled. --- .../Providers/AudioInfoProvider.cs | 21 +++-- .../Providers/BaseMetadataProvider.cs | 3 + .../Providers/VideoInfoProvider.cs | 89 ++++++++++++++++++++++ 3 files changed, 105 insertions(+), 8 deletions(-) create mode 100644 MediaBrowser.Controller/Providers/VideoInfoProvider.cs (limited to 'MediaBrowser.Controller/Providers') diff --git a/MediaBrowser.Controller/Providers/AudioInfoProvider.cs b/MediaBrowser.Controller/Providers/AudioInfoProvider.cs index 8894f87ed6..0f513f3698 100644 --- a/MediaBrowser.Controller/Providers/AudioInfoProvider.cs +++ b/MediaBrowser.Controller/Providers/AudioInfoProvider.cs @@ -229,21 +229,26 @@ namespace MediaBrowser.Controller.Providers { base.Init(); + EnsureCacheSubFolders(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory); + } + + internal static void EnsureCacheSubFolders(string root) + { // Do this now so that we don't have to do this on every operation, which would require us to create a lock in order to maintain thread-safety for (int i = 0; i <= 9; i++) { - EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, i.ToString())); + EnsureDirectory(Path.Combine(root, i.ToString())); } - EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "a")); - EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "b")); - EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "c")); - EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "d")); - EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "e")); - EnsureDirectory(Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, "f")); + EnsureDirectory(Path.Combine(root, "a")); + EnsureDirectory(Path.Combine(root, "b")); + EnsureDirectory(Path.Combine(root, "c")); + EnsureDirectory(Path.Combine(root, "d")); + EnsureDirectory(Path.Combine(root, "e")); + EnsureDirectory(Path.Combine(root, "f")); } - private void EnsureDirectory(string path) + private static void EnsureDirectory(string path) { if (!Directory.Exists(path)) { diff --git a/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs b/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs index 03684e8ee1..0cd7c08d0b 100644 --- a/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs +++ b/MediaBrowser.Controller/Providers/BaseMetadataProvider.cs @@ -47,6 +47,9 @@ namespace MediaBrowser.Controller.Providers // Run this provider after all first priority providers Second, + // Run this provider after all second priority providers + Third, + // Run this provider last Last } diff --git a/MediaBrowser.Controller/Providers/VideoInfoProvider.cs b/MediaBrowser.Controller/Providers/VideoInfoProvider.cs new file mode 100644 index 0000000000..8b140bfc06 --- /dev/null +++ b/MediaBrowser.Controller/Providers/VideoInfoProvider.cs @@ -0,0 +1,89 @@ +using System.ComponentModel.Composition; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using MediaBrowser.Controller.Events; +using MediaBrowser.Controller.FFMpeg; +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Controller.Providers +{ + //[Export(typeof(BaseMetadataProvider))] + public class VideoInfoProvider : BaseMetadataProvider + { + public override bool Supports(BaseEntity item) + { + return item is Video; + } + + public override MetadataProviderPriority Priority + { + // Give this second priority + // Give metadata xml providers a chance to fill in data first + // Then we can skip this step whenever possible + get { return MetadataProviderPriority.Second; } + } + + public override async Task Fetch(BaseEntity item, ItemResolveEventArgs args) + { + Video video = item as Video; + + if (video.VideoType != VideoType.VideoFile) + { + // Not supported yet + return; + } + + if (CanSkip(video)) + { + return; + } + + string outputDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeVideoCacheDirectory, item.Id.ToString().Substring(0, 1)); + + string outputPath = Path.Combine(outputDirectory, item.Id + "-" + item.DateModified.Ticks + ".js"); + + FFProbeResult data = await FFProbe.Run(video, outputPath); + } + + /// + /// Determines if there's already enough info in the Video object to allow us to skip running ffprobe + /// + private bool CanSkip(Video video) + { + if (video.AudioStreams == null || !video.AudioStreams.Any()) + { + return false; + } + + if (string.IsNullOrEmpty(video.Codec)) + { + return false; + } + + if (string.IsNullOrEmpty(video.ScanType)) + { + return false; + } + + if (string.IsNullOrEmpty(video.FrameRate)) + { + return false; + } + + if (video.Height == 0 || video.Width == 0 || video.BitRate == 0) + { + return false; + } + + return true; + } + + public override void Init() + { + base.Init(); + + AudioInfoProvider.EnsureCacheSubFolders(Kernel.Instance.ApplicationPaths.FFProbeVideoCacheDirectory); + } + } +} -- cgit v1.2.3