BaseVideoResolver.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Model.Entities;
  4. using System;
  5. using System.IO;
  6. namespace MediaBrowser.Controller.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> : ItemResolver<T>
  13. where T : Video, new()
  14. {
  15. /// <summary>
  16. /// Resolves the specified args.
  17. /// </summary>
  18. /// <param name="args">The args.</param>
  19. /// <returns>`0.</returns>
  20. protected override T Resolve(ItemResolveArgs args)
  21. {
  22. return ResolveVideo<T>(args);
  23. }
  24. /// <summary>
  25. /// Resolves the video.
  26. /// </summary>
  27. /// <typeparam name="TVideoType">The type of the T video type.</typeparam>
  28. /// <param name="args">The args.</param>
  29. /// <returns>``0.</returns>
  30. protected TVideoType ResolveVideo<TVideoType>(ItemResolveArgs args)
  31. where TVideoType : Video, new()
  32. {
  33. // If the path is a file check for a matching extensions
  34. if (!args.IsDirectory)
  35. {
  36. // http://wiki.xbmc.org/index.php?title=Media_stubs
  37. var isPlaceHolder = EntityResolutionHelper.IsVideoPlaceHolder(args.Path);
  38. if (EntityResolutionHelper.IsVideoFile(args.Path) || isPlaceHolder)
  39. {
  40. var extension = Path.GetExtension(args.Path);
  41. var type = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
  42. VideoType.Iso : VideoType.VideoFile;
  43. var video = new TVideoType
  44. {
  45. VideoType = type,
  46. Path = args.Path,
  47. IsInMixedFolder = true,
  48. IsPlaceHolder = isPlaceHolder
  49. };
  50. if (isPlaceHolder)
  51. {
  52. if (args.Path.EndsWith("dvd.disc", StringComparison.OrdinalIgnoreCase))
  53. {
  54. video.VideoType = VideoType.Dvd;
  55. }
  56. else if (args.Path.EndsWith("hddvd.disc", StringComparison.OrdinalIgnoreCase))
  57. {
  58. video.VideoType = VideoType.HdDvd;
  59. }
  60. else if (args.Path.EndsWith("bluray.disc", StringComparison.OrdinalIgnoreCase) ||
  61. args.Path.EndsWith("brrip.disc", StringComparison.OrdinalIgnoreCase) ||
  62. args.Path.EndsWith("bd25.disc", StringComparison.OrdinalIgnoreCase) ||
  63. args.Path.EndsWith("bd50.disc", StringComparison.OrdinalIgnoreCase))
  64. {
  65. video.VideoType = VideoType.BluRay;
  66. }
  67. }
  68. return video;
  69. }
  70. }
  71. return null;
  72. }
  73. /// <summary>
  74. /// Sets the initial item values.
  75. /// </summary>
  76. /// <param name="item">The item.</param>
  77. /// <param name="args">The args.</param>
  78. protected override void SetInitialItemValues(T item, ItemResolveArgs args)
  79. {
  80. base.SetInitialItemValues(item, args);
  81. if (item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 || item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1)
  82. {
  83. item.Video3DFormat = Video3DFormat.HalfSideBySide;
  84. }
  85. else if (item.Path.IndexOf("[hsbs]", StringComparison.OrdinalIgnoreCase) != -1)
  86. {
  87. item.Video3DFormat = Video3DFormat.HalfSideBySide;
  88. }
  89. else if (item.Path.IndexOf("[fsbs]", StringComparison.OrdinalIgnoreCase) != -1)
  90. {
  91. item.Video3DFormat = Video3DFormat.FullSideBySide;
  92. }
  93. else if (item.Path.IndexOf("[ftab]", StringComparison.OrdinalIgnoreCase) != -1)
  94. {
  95. item.Video3DFormat = Video3DFormat.FullTopAndBottom;
  96. }
  97. else if (item.Path.IndexOf("[htab]", StringComparison.OrdinalIgnoreCase) != -1)
  98. {
  99. item.Video3DFormat = Video3DFormat.HalfTopAndBottom;
  100. }
  101. }
  102. }
  103. }