LocalTrailerResolver.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. using MediaBrowser.Common.IO;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Controller.Resolvers;
  5. using System;
  6. using System.IO;
  7. namespace MediaBrowser.Server.Implementations.Library.Resolvers
  8. {
  9. /// <summary>
  10. /// Class LocalTrailerResolver
  11. /// </summary>
  12. public class LocalTrailerResolver : BaseVideoResolver<Trailer>
  13. {
  14. private readonly IFileSystem _fileSystem;
  15. public LocalTrailerResolver(IFileSystem fileSystem)
  16. {
  17. _fileSystem = fileSystem;
  18. }
  19. /// <summary>
  20. /// Resolves the specified args.
  21. /// </summary>
  22. /// <param name="args">The args.</param>
  23. /// <returns>Trailer.</returns>
  24. protected override Trailer Resolve(ItemResolveArgs args)
  25. {
  26. // Trailers are not Children, therefore this can never happen
  27. if (args.Parent != null)
  28. {
  29. return null;
  30. }
  31. // If the file is within a trailers folder, see if the VideoResolver returns something
  32. if (!args.IsDirectory)
  33. {
  34. if (string.Equals(Path.GetFileName(Path.GetDirectoryName(args.Path)), BaseItem.TrailerFolderName, StringComparison.OrdinalIgnoreCase))
  35. {
  36. return base.Resolve(args);
  37. }
  38. // Support xbmc local trailer convention, but only when looking for local trailers (hence the parent == null check)
  39. if (args.Parent == null && _fileSystem.GetFileNameWithoutExtension(args.Path).EndsWith(BaseItem.XbmcTrailerFileSuffix, StringComparison.OrdinalIgnoreCase))
  40. {
  41. return base.Resolve(args);
  42. }
  43. }
  44. return null;
  45. }
  46. }
  47. }