VideoResolver.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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
  10. /// </summary>
  11. public class VideoResolver : BaseVideoResolver<Video>
  12. {
  13. /// <summary>
  14. /// Gets the priority.
  15. /// </summary>
  16. /// <value>The priority.</value>
  17. public override ResolverPriority Priority
  18. {
  19. get { return ResolverPriority.Last; }
  20. }
  21. }
  22. /// <summary>
  23. /// Resolves a Path into a Video or Video subclass
  24. /// </summary>
  25. /// <typeparam name="T"></typeparam>
  26. public abstract class BaseVideoResolver<T> : BaseItemResolver<T>
  27. where T : Video, new()
  28. {
  29. /// <summary>
  30. /// Resolves the specified args.
  31. /// </summary>
  32. /// <param name="args">The args.</param>
  33. /// <returns>`0.</returns>
  34. protected override T Resolve(ItemResolveArgs args)
  35. {
  36. // If the path is a file check for a matching extensions
  37. if (!args.IsDirectory)
  38. {
  39. if (EntityResolutionHelper.IsVideoFile(args.Path))
  40. {
  41. var extension = Path.GetExtension(args.Path);
  42. var type = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
  43. VideoType.Iso : VideoType.VideoFile;
  44. return new T
  45. {
  46. VideoType = type,
  47. Path = args.Path
  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. item.VideoFormat = item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Digital3D : item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Sbs3D : VideoFormat.Standard;
  62. }
  63. }
  64. }