using System; using System.Collections.Generic; using System.IO; using System.Linq; using MediaBrowser.Common.MediaInfo; using MediaBrowser.Model.Entities; using MediaBrowser.Model.IO; namespace MediaBrowser.Controller.MediaInfo { /// /// Class MediaEncoderHelpers /// public static class MediaEncoderHelpers { /// /// Gets the input argument. /// /// The video path. /// if set to true [is remote]. /// Type of the video. /// Type of the iso. /// The iso mount. /// The playable stream file names. /// The type. /// System.String[][]. public static string[] GetInputArgument(string videoPath, bool isRemote, VideoType videoType, IsoType? isoType, IIsoMount isoMount, IEnumerable playableStreamFileNames, out InputType type) { var inputPath = isoMount == null ? new[] { videoPath } : new[] { isoMount.MountedPath }; type = InputType.VideoFile; switch (videoType) { case VideoType.BluRay: type = InputType.Bluray; break; case VideoType.Dvd: type = InputType.Dvd; inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray(); break; case VideoType.Iso: if (isoType.HasValue) { switch (isoType.Value) { case IsoType.BluRay: type = InputType.Bluray; break; case IsoType.Dvd: type = InputType.Dvd; inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray(); break; } } break; case VideoType.VideoFile: { if (isRemote) { type = InputType.Url; } break; } } return inputPath; } public static List GetPlayableStreamFiles(string rootPath, IEnumerable filenames) { var allFiles = Directory .EnumerateFiles(rootPath, "*", SearchOption.AllDirectories) .ToList(); return filenames.Select(name => allFiles.FirstOrDefault(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase))) .Where(f => !string.IsNullOrEmpty(f)) .ToList(); } /// /// Gets the type of the input. /// /// The path. /// Type of the video. /// Type of the iso. /// InputType. public static InputType GetInputType(string path, VideoType? videoType, IsoType? isoType) { var type = InputType.AudioFile; if (videoType.HasValue) { switch (videoType.Value) { case VideoType.BluRay: type = InputType.Bluray; break; case VideoType.Dvd: type = InputType.Dvd; break; case VideoType.Iso: if (isoType.HasValue) { switch (isoType.Value) { case IsoType.BluRay: type = InputType.Bluray; break; case IsoType.Dvd: type = InputType.Dvd; break; } } break; } } return type; } } }