BaseVideoResolver.cs 3.2 KB

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