BaseVideoResolver.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Naming.Common;
  5. using System;
  6. using System.IO;
  7. namespace MediaBrowser.Server.Implementations.Library.Resolvers
  8. {
  9. /// <summary>
  10. /// Resolves a Path into a Video or Video subclass
  11. /// </summary>
  12. /// <typeparam name="T"></typeparam>
  13. public abstract class BaseVideoResolver<T> : Controller.Resolvers.ItemResolver<T>
  14. where T : Video, new()
  15. {
  16. protected readonly ILibraryManager LibraryManager;
  17. protected BaseVideoResolver(ILibraryManager libraryManager)
  18. {
  19. LibraryManager = libraryManager;
  20. }
  21. /// <summary>
  22. /// Resolves the specified args.
  23. /// </summary>
  24. /// <param name="args">The args.</param>
  25. /// <returns>`0.</returns>
  26. protected override T Resolve(ItemResolveArgs args)
  27. {
  28. return ResolveVideo<T>(args, true);
  29. }
  30. /// <summary>
  31. /// Resolves the video.
  32. /// </summary>
  33. /// <typeparam name="TVideoType">The type of the T video type.</typeparam>
  34. /// <param name="args">The args.</param>
  35. /// <param name="parseName">if set to <c>true</c> [parse name].</param>
  36. /// <returns>``0.</returns>
  37. protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args, bool parseName)
  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. ProductionYear = videoInfo.Year
  64. };
  65. if (parseName)
  66. {
  67. video.Name = videoInfo.Name;
  68. }
  69. else
  70. {
  71. video.Name = Path.GetFileNameWithoutExtension(path);
  72. }
  73. if (videoInfo.IsStub)
  74. {
  75. if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase))
  76. {
  77. video.VideoType = VideoType.Dvd;
  78. }
  79. else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase))
  80. {
  81. video.VideoType = VideoType.HdDvd;
  82. }
  83. else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase))
  84. {
  85. video.VideoType = VideoType.BluRay;
  86. }
  87. }
  88. if (videoInfo.Is3D)
  89. {
  90. if (string.Equals(videoInfo.Format3D, "fsbs", StringComparison.OrdinalIgnoreCase))
  91. {
  92. video.Video3DFormat = Video3DFormat.FullSideBySide;
  93. }
  94. else if (string.Equals(videoInfo.Format3D, "ftab", StringComparison.OrdinalIgnoreCase))
  95. {
  96. video.Video3DFormat = Video3DFormat.FullTopAndBottom;
  97. }
  98. else if (string.Equals(videoInfo.Format3D, "hsbs", StringComparison.OrdinalIgnoreCase))
  99. {
  100. video.Video3DFormat = Video3DFormat.HalfSideBySide;
  101. }
  102. else if (string.Equals(videoInfo.Format3D, "htab", StringComparison.OrdinalIgnoreCase))
  103. {
  104. video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
  105. }
  106. else if (string.Equals(videoInfo.Format3D, "sbs", StringComparison.OrdinalIgnoreCase))
  107. {
  108. video.Video3DFormat = Video3DFormat.HalfSideBySide;
  109. }
  110. else if (string.Equals(videoInfo.Format3D, "sbs3d", StringComparison.OrdinalIgnoreCase))
  111. {
  112. video.Video3DFormat = Video3DFormat.HalfSideBySide;
  113. }
  114. else if (string.Equals(videoInfo.Format3D, "tab", StringComparison.OrdinalIgnoreCase))
  115. {
  116. video.Video3DFormat = Video3DFormat.HalfTopAndBottom;
  117. }
  118. }
  119. return video;
  120. }
  121. }
  122. return null;
  123. }
  124. }
  125. }