MediaEncoderHelpers.cs 2.0 KB

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