BaseVideoResolver.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. var extension = Path.GetExtension(args.Path);
  39. var isShortcut = string.Equals(extension, ".strm", StringComparison.OrdinalIgnoreCase);
  40. if (EntityResolutionHelper.IsVideoFile(args.Path) || isPlaceHolder || isShortcut)
  41. {
  42. var type = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
  43. VideoType.Iso : VideoType.VideoFile;
  44. var path = args.Path;
  45. var video = new TVideoType
  46. {
  47. VideoType = type,
  48. Path = args.Path,
  49. IsInMixedFolder = true,
  50. IsPlaceHolder = isPlaceHolder,
  51. IsShortcut = isShortcut
  52. };
  53. if (isPlaceHolder)
  54. {
  55. if (args.Path.EndsWith("dvd.disc", StringComparison.OrdinalIgnoreCase))
  56. {
  57. video.VideoType = VideoType.Dvd;
  58. }
  59. else if (args.Path.EndsWith("hddvd.disc", StringComparison.OrdinalIgnoreCase))
  60. {
  61. video.VideoType = VideoType.HdDvd;
  62. }
  63. else if (args.Path.EndsWith("bluray.disc", StringComparison.OrdinalIgnoreCase) ||
  64. args.Path.EndsWith("brrip.disc", StringComparison.OrdinalIgnoreCase) ||
  65. args.Path.EndsWith("bd25.disc", StringComparison.OrdinalIgnoreCase) ||
  66. args.Path.EndsWith("bd50.disc", StringComparison.OrdinalIgnoreCase))
  67. {
  68. video.VideoType = VideoType.BluRay;
  69. }
  70. }
  71. return video;
  72. }
  73. }
  74. return null;
  75. }
  76. /// <summary>
  77. /// Sets the initial item values.
  78. /// </summary>
  79. /// <param name="item">The item.</param>
  80. /// <param name="args">The args.</param>
  81. protected override void SetInitialItemValues(T item, ItemResolveArgs args)
  82. {
  83. base.SetInitialItemValues(item, args);
  84. if (item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 || item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1)
  85. {
  86. item.Video3DFormat = Video3DFormat.HalfSideBySide;
  87. }
  88. else if (item.Path.IndexOf("[hsbs]", StringComparison.OrdinalIgnoreCase) != -1)
  89. {
  90. item.Video3DFormat = Video3DFormat.HalfSideBySide;
  91. }
  92. else if (item.Path.IndexOf("[fsbs]", StringComparison.OrdinalIgnoreCase) != -1)
  93. {
  94. item.Video3DFormat = Video3DFormat.FullSideBySide;
  95. }
  96. else if (item.Path.IndexOf("[ftab]", StringComparison.OrdinalIgnoreCase) != -1)
  97. {
  98. item.Video3DFormat = Video3DFormat.FullTopAndBottom;
  99. }
  100. else if (item.Path.IndexOf("[htab]", StringComparison.OrdinalIgnoreCase) != -1)
  101. {
  102. item.Video3DFormat = Video3DFormat.HalfTopAndBottom;
  103. }
  104. else
  105. {
  106. // Support Xbmc conventions:
  107. // http://wiki.xbmc.org/index.php?title=3D
  108. var name = Path.GetFileName(item.Path);
  109. name = name.Replace('.', ' ').Replace('_', ' ').Replace('-', ' ');
  110. if (name.IndexOf(" 3d hsbs ", StringComparison.OrdinalIgnoreCase) != -1 ||
  111. name.IndexOf(" 3d sbs ", StringComparison.OrdinalIgnoreCase) != -1)
  112. {
  113. item.Video3DFormat = Video3DFormat.HalfSideBySide;
  114. }
  115. else if (name.IndexOf(" 3d htab ", StringComparison.OrdinalIgnoreCase) != -1 ||
  116. name.IndexOf(" 3d tab ", StringComparison.OrdinalIgnoreCase) != -1)
  117. {
  118. item.Video3DFormat = Video3DFormat.HalfTopAndBottom;
  119. }
  120. }
  121. }
  122. }
  123. }