MediaEncoderHelpers.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using MediaBrowser.Common.MediaInfo;
  6. using MediaBrowser.Model.Entities;
  7. using MediaBrowser.Model.IO;
  8. namespace MediaBrowser.Controller.MediaInfo
  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="videoPath">The video path.</param>
  19. /// <param name="isRemote">if set to <c>true</c> [is remote].</param>
  20. /// <param name="videoType">Type of the video.</param>
  21. /// <param name="isoType">Type of the iso.</param>
  22. /// <param name="isoMount">The iso mount.</param>
  23. /// <param name="playableStreamFileNames">The playable stream file names.</param>
  24. /// <param name="type">The type.</param>
  25. /// <returns>System.String[][].</returns>
  26. public static string[] GetInputArgument(string videoPath, bool isRemote, VideoType videoType, IsoType? isoType, IIsoMount isoMount, IEnumerable<string> playableStreamFileNames, out InputType type)
  27. {
  28. var inputPath = isoMount == null ? new[] { videoPath } : new[] { isoMount.MountedPath };
  29. type = InputType.VideoFile;
  30. switch (videoType)
  31. {
  32. case VideoType.BluRay:
  33. type = InputType.Bluray;
  34. break;
  35. case VideoType.Dvd:
  36. type = InputType.Dvd;
  37. inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray();
  38. break;
  39. case VideoType.Iso:
  40. if (isoType.HasValue)
  41. {
  42. switch (isoType.Value)
  43. {
  44. case IsoType.BluRay:
  45. type = InputType.Bluray;
  46. break;
  47. case IsoType.Dvd:
  48. type = InputType.Dvd;
  49. inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray();
  50. break;
  51. }
  52. }
  53. break;
  54. case VideoType.VideoFile:
  55. {
  56. if (isRemote)
  57. {
  58. type = InputType.Url;
  59. }
  60. break;
  61. }
  62. }
  63. return inputPath;
  64. }
  65. public static List<string> GetPlayableStreamFiles(string rootPath, IEnumerable<string> filenames)
  66. {
  67. var allFiles = Directory
  68. .EnumerateFiles(rootPath, "*", SearchOption.AllDirectories)
  69. .ToList();
  70. return filenames.Select(name => allFiles.FirstOrDefault(f => string.Equals(Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
  71. .Where(f => !string.IsNullOrEmpty(f))
  72. .ToList();
  73. }
  74. /// <summary>
  75. /// Gets the type of the input.
  76. /// </summary>
  77. /// <param name="path">The path.</param>
  78. /// <param name="videoType">Type of the video.</param>
  79. /// <param name="isoType">Type of the iso.</param>
  80. /// <returns>InputType.</returns>
  81. public static InputType GetInputType(string path, VideoType? videoType, IsoType? isoType)
  82. {
  83. var type = InputType.AudioFile;
  84. if (videoType.HasValue)
  85. {
  86. switch (videoType.Value)
  87. {
  88. case VideoType.BluRay:
  89. type = InputType.Bluray;
  90. break;
  91. case VideoType.Dvd:
  92. type = InputType.Dvd;
  93. break;
  94. case VideoType.Iso:
  95. if (isoType.HasValue)
  96. {
  97. switch (isoType.Value)
  98. {
  99. case IsoType.BluRay:
  100. type = InputType.Bluray;
  101. break;
  102. case IsoType.Dvd:
  103. type = InputType.Dvd;
  104. break;
  105. }
  106. }
  107. break;
  108. }
  109. }
  110. return type;
  111. }
  112. }
  113. }