BaseVideoResolver.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Naming.Audio;
  5. using MediaBrowser.Naming.Common;
  6. using MediaBrowser.Naming.Video;
  7. using System;
  8. namespace MediaBrowser.Server.Implementations.Library.Resolvers
  9. {
  10. /// <summary>
  11. /// Resolves a Path into a Video or Video subclass
  12. /// </summary>
  13. /// <typeparam name="T"></typeparam>
  14. public abstract class BaseVideoResolver<T> : Controller.Resolvers.ItemResolver<T>
  15. where T : Video, new()
  16. {
  17. protected readonly ILibraryManager LibraryManager;
  18. protected BaseVideoResolver(ILibraryManager libraryManager)
  19. {
  20. LibraryManager = libraryManager;
  21. }
  22. /// <summary>
  23. /// Resolves the specified args.
  24. /// </summary>
  25. /// <param name="args">The args.</param>
  26. /// <returns>`0.</returns>
  27. protected override T Resolve(ItemResolveArgs args)
  28. {
  29. return ResolveVideo<T>(args);
  30. }
  31. /// <summary>
  32. /// Resolves the video.
  33. /// </summary>
  34. /// <typeparam name="TVideoType">The type of the T video type.</typeparam>
  35. /// <param name="args">The args.</param>
  36. /// <returns>``0.</returns>
  37. protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args)
  38. where TVideoType : Video, new()
  39. {
  40. // If the path is a file check for a matching extensions
  41. if (!args.IsDirectory)
  42. {
  43. var parser = new Naming.Video.VideoResolver(new ExtendedNamingOptions(), new Naming.Logging.NullLogger());
  44. var videoInfo = parser.ResolveFile(args.Path);
  45. if (videoInfo == null)
  46. {
  47. return null;
  48. }
  49. var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase);
  50. if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut)
  51. {
  52. var type = string.Equals(videoInfo.Container, "iso", StringComparison.OrdinalIgnoreCase) || string.Equals(videoInfo.Container, "img", StringComparison.OrdinalIgnoreCase) ?
  53. VideoType.Iso :
  54. VideoType.VideoFile;
  55. var path = args.Path;
  56. var video = new TVideoType
  57. {
  58. VideoType = type,
  59. Path = path,
  60. IsInMixedFolder = true,
  61. IsPlaceHolder = videoInfo.IsStub,
  62. IsShortcut = isShortcut,
  63. Name = videoInfo.Name,
  64. ProductionYear = videoInfo.Year
  65. };
  66. if (videoInfo.IsStub)
  67. {
  68. if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase))
  69. {
  70. video.VideoType = VideoType.Dvd;
  71. }
  72. else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase))
  73. {
  74. video.VideoType = VideoType.HdDvd;
  75. }
  76. else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase))
  77. {
  78. video.VideoType = VideoType.BluRay;
  79. }
  80. }
  81. if (videoInfo.Is3D)
  82. {
  83. if (string.Equals(videoInfo.Format3D, "fsbs", StringComparison.OrdinalIgnoreCase))
  84. {
  85. video.Video3DFormat = Video3DFormat.FullSideBySide;
  86. }
  87. else if (string.Equals(videoInfo.Format3D, "ftab", StringComparison.OrdinalIgnoreCase))
  88. {
  89. video.Video3DFormat = Video3DFormat.FullTopAndBottom;
  90. }
  91. else if (string.Equals(videoInfo.Format3D, "hsbs", StringComparison.OrdinalIgnoreCase))
  92. {
  93. video.Video3DFormat = Video3DFormat.HalfSideBySide;
  94. }
  95. else if (string.Equals(videoInfo.Format3D, "htab", StringComparison.OrdinalIgnoreCase))
  96. {
  97. video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
  98. }
  99. else if (string.Equals(videoInfo.Format3D, "sbs", StringComparison.OrdinalIgnoreCase))
  100. {
  101. video.Video3DFormat = Video3DFormat.HalfSideBySide;
  102. }
  103. else if (string.Equals(videoInfo.Format3D, "sbs3d", StringComparison.OrdinalIgnoreCase))
  104. {
  105. video.Video3DFormat = Video3DFormat.HalfSideBySide;
  106. }
  107. else if (string.Equals(videoInfo.Format3D, "tab", StringComparison.OrdinalIgnoreCase))
  108. {
  109. video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
  110. }
  111. }
  112. return video;
  113. }
  114. }
  115. return null;
  116. }
  117. }
  118. }