MediaEncoderHelpers.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using MediaBrowser.Model.IO;
  7. namespace MediaBrowser.Controller.MediaEncoding
  8. {
  9. /// <summary>
  10. /// Class MediaEncoderHelpers.
  11. /// </summary>
  12. public static class MediaEncoderHelpers
  13. {
  14. /// <summary>
  15. /// Gets the input argument.
  16. /// </summary>
  17. /// <param name="fileSystem">The file system.</param>
  18. /// <param name="videoPath">The video path.</param>
  19. /// <param name="isoMount">The iso mount.</param>
  20. /// <param name="playableStreamFileNames">The playable stream file names.</param>
  21. /// <returns>string[].</returns>
  22. public static string[] GetInputArgument(IFileSystem fileSystem, string videoPath, IIsoMount isoMount, IReadOnlyCollection<string> playableStreamFileNames)
  23. {
  24. if (playableStreamFileNames.Count > 0)
  25. {
  26. if (isoMount == null)
  27. {
  28. return GetPlayableStreamFiles(fileSystem, videoPath, playableStreamFileNames);
  29. }
  30. return GetPlayableStreamFiles(fileSystem, isoMount.MountedPath, playableStreamFileNames);
  31. }
  32. return new[] { videoPath };
  33. }
  34. private static string[] GetPlayableStreamFiles(IFileSystem fileSystem, string rootPath, IEnumerable<string> filenames)
  35. {
  36. var allFiles = fileSystem
  37. .GetFilePaths(rootPath, true)
  38. .ToArray();
  39. return filenames.Select(name => allFiles.FirstOrDefault(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
  40. .Where(f => !string.IsNullOrEmpty(f))
  41. .ToArray();
  42. }
  43. }
  44. }