BaseVideoResolver.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. var isPlaceHolder = EntityResolutionHelper.IsVideoPlaceHolder(args.Path);
  37. if (EntityResolutionHelper.IsVideoFile(args.Path) || isPlaceHolder)
  38. {
  39. var extension = Path.GetExtension(args.Path);
  40. var type = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
  41. VideoType.Iso : VideoType.VideoFile;
  42. return new TVideoType
  43. {
  44. VideoType = type,
  45. Path = args.Path,
  46. IsInMixedFolder = true,
  47. IsPlaceHolder = isPlaceHolder
  48. };
  49. }
  50. }
  51. return null;
  52. }
  53. /// <summary>
  54. /// Sets the initial item values.
  55. /// </summary>
  56. /// <param name="item">The item.</param>
  57. /// <param name="args">The args.</param>
  58. protected override void SetInitialItemValues(T item, ItemResolveArgs args)
  59. {
  60. base.SetInitialItemValues(item, args);
  61. if (item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 || item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1)
  62. {
  63. item.Video3DFormat = Video3DFormat.HalfSideBySide;
  64. }
  65. else if (item.Path.IndexOf("[hsbs]", StringComparison.OrdinalIgnoreCase) != -1)
  66. {
  67. item.Video3DFormat = Video3DFormat.HalfSideBySide;
  68. }
  69. else if (item.Path.IndexOf("[fsbs]", StringComparison.OrdinalIgnoreCase) != -1)
  70. {
  71. item.Video3DFormat = Video3DFormat.FullSideBySide;
  72. }
  73. else if (item.Path.IndexOf("[ftab]", StringComparison.OrdinalIgnoreCase) != -1)
  74. {
  75. item.Video3DFormat = Video3DFormat.FullTopAndBottom;
  76. }
  77. else if (item.Path.IndexOf("[htab]", StringComparison.OrdinalIgnoreCase) != -1)
  78. {
  79. item.Video3DFormat = Video3DFormat.HalfTopAndBottom;
  80. }
  81. }
  82. }
  83. }