SeriesResolver.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using MediaBrowser.Common.Extensions;
  2. using MediaBrowser.Controller.Entities.TV;
  3. using MediaBrowser.Controller.Library;
  4. using MediaBrowser.Controller.Resolvers;
  5. using MediaBrowser.Model.Entities;
  6. using System;
  7. using System.IO;
  8. namespace MediaBrowser.Server.Implementations.Library.Resolvers.TV
  9. {
  10. /// <summary>
  11. /// Class SeriesResolver
  12. /// </summary>
  13. public class SeriesResolver : FolderResolver<Series>
  14. {
  15. /// <summary>
  16. /// Gets the priority.
  17. /// </summary>
  18. /// <value>The priority.</value>
  19. public override ResolverPriority Priority
  20. {
  21. get
  22. {
  23. return ResolverPriority.Second;
  24. }
  25. }
  26. /// <summary>
  27. /// Resolves the specified args.
  28. /// </summary>
  29. /// <param name="args">The args.</param>
  30. /// <returns>Series.</returns>
  31. protected override Series Resolve(ItemResolveArgs args)
  32. {
  33. if (args.IsDirectory)
  34. {
  35. // Avoid expensive tests against VF's and all their children by not allowing this
  36. if (args.Parent == null || args.Parent.IsRoot)
  37. {
  38. return null;
  39. }
  40. // Optimization to avoid running these tests against Seasons
  41. if (args.Parent is Series)
  42. {
  43. return null;
  44. }
  45. // It's a Series if any of the following conditions are met:
  46. // series.xml exists
  47. // [tvdbid= is present in the path
  48. // TVUtils.IsSeriesFolder returns true
  49. var filename = Path.GetFileName(args.Path);
  50. if (string.IsNullOrEmpty(filename))
  51. {
  52. return null;
  53. }
  54. if (args.ContainsMetaFileByName("series.xml") || filename.IndexOf("[tvdbid=", StringComparison.OrdinalIgnoreCase) != -1 || TVUtils.IsSeriesFolder(args.Path, args.FileSystemChildren))
  55. {
  56. return new Series();
  57. }
  58. }
  59. return null;
  60. }
  61. /// <summary>
  62. /// Sets the initial item values.
  63. /// </summary>
  64. /// <param name="item">The item.</param>
  65. /// <param name="args">The args.</param>
  66. protected override void SetInitialItemValues(Series item, ItemResolveArgs args)
  67. {
  68. base.SetInitialItemValues(item, args);
  69. Season.AddMetadataFiles(args);
  70. SetProviderIdFromPath(item, args.Path);
  71. }
  72. /// <summary>
  73. /// Sets the provider id from path.
  74. /// </summary>
  75. /// <param name="item">The item.</param>
  76. private void SetProviderIdFromPath(Series item, string path)
  77. {
  78. var justName = Path.GetFileName(path);
  79. var id = justName.GetAttributeValue("tvdbid");
  80. if (!string.IsNullOrEmpty(id))
  81. {
  82. item.SetProviderId(MetadataProviders.Tvdb, id);
  83. }
  84. }
  85. }
  86. }