BaseVideoResolver.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. };
  46. }
  47. }
  48. return null;
  49. }
  50. /// <summary>
  51. /// Sets the initial item values.
  52. /// </summary>
  53. /// <param name="item">The item.</param>
  54. /// <param name="args">The args.</param>
  55. protected override void SetInitialItemValues(T item, ItemResolveArgs args)
  56. {
  57. base.SetInitialItemValues(item, args);
  58. if (item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 || item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1)
  59. {
  60. item.Video3DFormat = Video3DFormat.HalfSideBySide;
  61. }
  62. else if (item.Path.IndexOf("[hsbs]", StringComparison.OrdinalIgnoreCase) != -1)
  63. {
  64. item.Video3DFormat = Video3DFormat.HalfSideBySide;
  65. }
  66. else if (item.Path.IndexOf("[fsbs]", StringComparison.OrdinalIgnoreCase) != -1)
  67. {
  68. item.Video3DFormat = Video3DFormat.FullSideBySide;
  69. }
  70. else if (item.Path.IndexOf("[ftab]", StringComparison.OrdinalIgnoreCase) != -1)
  71. {
  72. item.Video3DFormat = Video3DFormat.FullTopAndBottom;
  73. }
  74. else if (item.Path.IndexOf("[htab]", StringComparison.OrdinalIgnoreCase) != -1)
  75. {
  76. item.Video3DFormat = Video3DFormat.HalfTopAndBottom;
  77. }
  78. }
  79. }
  80. }