VideoResolver.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using MediaBrowser.Controller.Entities;
  2. using MediaBrowser.Controller.Library;
  3. using MediaBrowser.Model.Entities;
  4. using System;
  5. using System.ComponentModel.Composition;
  6. using System.IO;
  7. namespace MediaBrowser.Controller.Resolvers
  8. {
  9. /// <summary>
  10. /// Resolves a Path into a Video
  11. /// </summary>
  12. [Export(typeof(IBaseItemResolver))]
  13. public class VideoResolver : BaseVideoResolver<Video>
  14. {
  15. /// <summary>
  16. /// Gets the priority.
  17. /// </summary>
  18. /// <value>The priority.</value>
  19. public override ResolverPriority Priority
  20. {
  21. get { return ResolverPriority.Last; }
  22. }
  23. }
  24. /// <summary>
  25. /// Resolves a Path into a Video or Video subclass
  26. /// </summary>
  27. /// <typeparam name="T"></typeparam>
  28. public abstract class BaseVideoResolver<T> : BaseItemResolver<T>
  29. where T : Video, new()
  30. {
  31. /// <summary>
  32. /// Resolves the specified args.
  33. /// </summary>
  34. /// <param name="args">The args.</param>
  35. /// <returns>`0.</returns>
  36. protected override T Resolve(ItemResolveArgs args)
  37. {
  38. // If the path is a file check for a matching extensions
  39. if (!args.IsDirectory)
  40. {
  41. if (EntityResolutionHelper.IsVideoFile(args.Path))
  42. {
  43. var extension = Path.GetExtension(args.Path);
  44. var type = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
  45. VideoType.Iso : VideoType.VideoFile;
  46. return new T
  47. {
  48. VideoType = type,
  49. Path = args.Path
  50. };
  51. }
  52. }
  53. return null;
  54. }
  55. /// <summary>
  56. /// Sets the initial item values.
  57. /// </summary>
  58. /// <param name="item">The item.</param>
  59. /// <param name="args">The args.</param>
  60. protected override void SetInitialItemValues(T item, ItemResolveArgs args)
  61. {
  62. base.SetInitialItemValues(item, args);
  63. item.VideoFormat = item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Digital3D : item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Sbs3D : VideoFormat.Standard;
  64. }
  65. }
  66. }