BaseVideoResolver.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. // If the path is a file check for a matching extensions
  23. if (!args.IsDirectory)
  24. {
  25. if (EntityResolutionHelper.IsVideoFile(args.Path))
  26. {
  27. var extension = Path.GetExtension(args.Path);
  28. var type = string.Equals(extension, ".iso", StringComparison.OrdinalIgnoreCase) || string.Equals(extension, ".img", StringComparison.OrdinalIgnoreCase) ?
  29. VideoType.Iso : VideoType.VideoFile;
  30. return new T
  31. {
  32. VideoType = type,
  33. Path = args.Path
  34. };
  35. }
  36. }
  37. return null;
  38. }
  39. /// <summary>
  40. /// Sets the initial item values.
  41. /// </summary>
  42. /// <param name="item">The item.</param>
  43. /// <param name="args">The args.</param>
  44. protected override void SetInitialItemValues(T item, ItemResolveArgs args)
  45. {
  46. base.SetInitialItemValues(item, args);
  47. item.VideoFormat = item.Path.IndexOf("[3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Digital3D : item.Path.IndexOf("[sbs3d]", StringComparison.OrdinalIgnoreCase) != -1 ? VideoFormat.Sbs3D : VideoFormat.Standard;
  48. }
  49. }
  50. }