MediaEncoderHelpers.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using MediaBrowser.Model.IO;
  5. using MediaBrowser.Model.MediaInfo;
  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="protocol">The protocol.</param>
  19. /// <param name="isoMount">The iso mount.</param>
  20. /// <param name="playableStreamFileNames">The playable stream file names.</param>
  21. /// <returns>System.String[][].</returns>
  22. public static string[] GetInputArgument(IFileSystem fileSystem, string videoPath, MediaProtocol protocol, IIsoMount isoMount, string[] playableStreamFileNames)
  23. {
  24. if (playableStreamFileNames.Length > 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, string[] filenames)
  35. {
  36. if (filenames.Length == 0)
  37. {
  38. return new string[] { };
  39. }
  40. var allFiles = fileSystem
  41. .GetFilePaths(rootPath, true)
  42. .ToArray();
  43. return filenames.Select(name => allFiles.FirstOrDefault(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
  44. .Where(f => !string.IsNullOrEmpty(f))
  45. .ToArray();
  46. }
  47. }
  48. }