BaseVideoResolver.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. item.VideoFormat = item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Digital3D : item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Sbs3D : VideoFormat.Standard;
  59. }
  60. }
  61. }