using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Model.IO;
namespace MediaBrowser.Controller.MediaEncoding
{
///
/// Class MediaEncoderHelpers.
///
public static class MediaEncoderHelpers
{
///
/// Gets the input argument.
///
/// The file system.
/// The video path.
/// The iso mount.
/// The playable stream file names.
/// string[].
public static string[] GetInputArgument(IFileSystem fileSystem, string videoPath, IIsoMount isoMount, IReadOnlyCollection playableStreamFileNames)
{
if (playableStreamFileNames.Count > 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, IEnumerable filenames)
{
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();
}
}
}