From a86b71899ec52c44ddc6c3018e8cc5e9d7ff4d62 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Thu, 27 Dec 2018 18:27:57 -0500 Subject: Add GPL modules --- .../MediaEncoding/MediaEncoderHelpers.cs | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs (limited to 'MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs') diff --git a/MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs b/MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs new file mode 100644 index 000000000..70e4db84f --- /dev/null +++ b/MediaBrowser.Controller/MediaEncoding/MediaEncoderHelpers.cs @@ -0,0 +1,53 @@ +using MediaBrowser.Model.IO; +using MediaBrowser.Model.MediaInfo; +using System; +using System.IO; +using System.Linq; + +namespace MediaBrowser.Controller.MediaEncoding +{ + /// + /// Class MediaEncoderHelpers + /// + public static class MediaEncoderHelpers + { + /// + /// Gets the input argument. + /// + /// The file system. + /// The video path. + /// The protocol. + /// The iso mount. + /// The playable stream file names. + /// System.String[][]. + public static string[] GetInputArgument(IFileSystem fileSystem, string videoPath, MediaProtocol protocol, IIsoMount isoMount, string[] playableStreamFileNames) + { + if (playableStreamFileNames.Length > 0) + { + if (isoMount == null) + { + return GetPlayableStreamFiles(fileSystem, videoPath, playableStreamFileNames); + } + return GetPlayableStreamFiles(fileSystem, isoMount.MountedPath, playableStreamFileNames); + } + + return new[] {videoPath}; + } + + private static string[] GetPlayableStreamFiles(IFileSystem fileSystem, string rootPath, string[] filenames) + { + if (filenames.Length == 0) + { + return new string[]{}; + } + + var allFiles = fileSystem + .GetFilePaths(rootPath, true) + .ToArray(); + + return filenames.Select(name => allFiles.FirstOrDefault(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase))) + .Where(f => !string.IsNullOrEmpty(f)) + .ToArray(); + } + } +} -- cgit v1.2.3