MediaEncoderHelpers.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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="videoType">Type of the video.</param>
  78. /// <param name="isoType">Type of the iso.</param>
  79. /// <returns>InputType.</returns>
  80. public static InputType GetInputType(VideoType? videoType, IsoType? isoType)
  81. {
  82. var type = InputType.AudioFile;
  83. if (videoType.HasValue)
  84. {
  85. switch (videoType.Value)
  86. {
  87. case VideoType.BluRay:
  88. type = InputType.Bluray;
  89. break;
  90. case VideoType.Dvd:
  91. type = InputType.Dvd;
  92. break;
  93. case VideoType.Iso:
  94. if (isoType.HasValue)
  95. {
  96. switch (isoType.Value)
  97. {
  98. case IsoType.BluRay:
  99. type = InputType.Bluray;
  100. break;
  101. case IsoType.Dvd:
  102. type = InputType.Dvd;
  103. break;
  104. }
  105. }
  106. break;
  107. }
  108. }
  109. return type;
  110. }
  111. }
  112. }