BaseVideoResolver.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Model.Entities;
  4. using MediaBrowser.Naming.Video;
  5. using System;
  6. namespace MediaBrowser.Server.Implementations.Library.Resolvers
  7. {
  8. /// <summary>
  9. /// Resolves a Path into a Video or Video subclass
  10. /// </summary>
  11. /// <typeparam name="T"></typeparam>
  12. public abstract class BaseVideoResolver<T> : Controller.Resolvers.ItemResolver<T>
  13. where T : Video, new()
  14. {
  15. protected readonly ILibraryManager LibraryManager;
  16. protected BaseVideoResolver(ILibraryManager libraryManager)
  17. {
  18. LibraryManager = libraryManager;
  19. }
  20. /// <summary>
  21. /// Resolves the specified args.
  22. /// </summary>
  23. /// <param name="args">The args.</param>
  24. /// <returns>`0.</returns>
  25. protected override T Resolve(ItemResolveArgs args)
  26. {
  27. return ResolveVideo<T>(args);
  28. }
  29. /// <summary>
  30. /// Resolves the video.
  31. /// </summary>
  32. /// <typeparam name="TVideoType">The type of the T video type.</typeparam>
  33. /// <param name="args">The args.</param>
  34. /// <returns>``0.</returns>
  35. protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args)
  36. where TVideoType : Video, new()
  37. {
  38. // If the path is a file check for a matching extensions
  39. if (!args.IsDirectory)
  40. {
  41. var parser = new VideoFileParser(new ExpandedVideoOptions(), new Naming.Logging.NullLogger());
  42. var videoInfo = parser.ParseFile(args.Path);
  43. if (videoInfo == null)
  44. {
  45. return null;
  46. }
  47. var isShortcut = string.Equals(videoInfo.Container, "strm", StringComparison.OrdinalIgnoreCase);
  48. if (LibraryManager.IsVideoFile(args.Path) || videoInfo.IsStub || isShortcut)
  49. {
  50. var type = string.Equals(videoInfo.Container, "iso", StringComparison.OrdinalIgnoreCase) || string.Equals(videoInfo.Container, "img", StringComparison.OrdinalIgnoreCase) ?
  51. VideoType.Iso :
  52. VideoType.VideoFile;
  53. var path = args.Path;
  54. var video = new TVideoType
  55. {
  56. VideoType = type,
  57. Path = path,
  58. IsInMixedFolder = true,
  59. IsPlaceHolder = videoInfo.IsStub,
  60. IsShortcut = isShortcut,
  61. Name = videoInfo.Name
  62. };
  63. if (videoInfo.IsStub)
  64. {
  65. if (string.Equals(videoInfo.StubType, "dvd", StringComparison.OrdinalIgnoreCase))
  66. {
  67. video.VideoType = VideoType.Dvd;
  68. }
  69. else if (string.Equals(videoInfo.StubType, "hddvd", StringComparison.OrdinalIgnoreCase))
  70. {
  71. video.VideoType = VideoType.HdDvd;
  72. }
  73. else if (string.Equals(videoInfo.StubType, "bluray", StringComparison.OrdinalIgnoreCase))
  74. {
  75. video.VideoType = VideoType.BluRay;
  76. }
  77. }
  78. return video;
  79. }
  80. }
  81. return null;
  82. }
  83. }
  84. }