BaseVideoResolver.cs 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Naming.Audio;
  5. using MediaBrowser.Naming.Video;
  6. using System;
  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);
  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. /// <returns>``0.</returns>
  36. protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args)
  37. where TVideoType : Video, new()
  38. {
  39. // If the path is a file check for a matching extensions
  40. if (!args.IsDirectory)
  41. {
  42. var parser = new Naming.Video.VideoResolver(new ExpandedVideoOptions(), new AudioOptions(), new Naming.Logging.NullLogger());
  43. var videoInfo = parser.ResolveFile(args.Path);
  44. if (videoInfo == null)
  45. {
  46. return null;
  47. }
  48. var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase);
  49. if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut)
  50. {
  51. var type = string.Equals(videoInfo.Container, "iso", StringComparison.OrdinalIgnoreCase) || string.Equals(videoInfo.Container, "img", StringComparison.OrdinalIgnoreCase) ?
  52. VideoType.Iso :
  53. VideoType.VideoFile;
  54. var path = args.Path;
  55. var video = new TVideoType
  56. {
  57. VideoType = type,
  58. Path = path,
  59. IsInMixedFolder = true,
  60. IsPlaceHolder = videoInfo.IsStub,
  61. IsShortcut = isShortcut,
  62. Name = videoInfo.Name,
  63. ProductionYear = videoInfo.Year
  64. };
  65. if (videoInfo.IsStub)
  66. {
  67. if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase))
  68. {
  69. video.VideoType = VideoType.Dvd;
  70. }
  71. else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase))
  72. {
  73. video.VideoType = VideoType.HdDvd;
  74. }
  75. else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase))
  76. {
  77. video.VideoType = VideoType.BluRay;
  78. }
  79. }
  80. return video;
  81. }
  82. }
  83. return null;
  84. }
  85. }
  86. }