MediaEncoderHelpers.cs 1.7 KB

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