ExtraTests.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. using Emby.Naming.Common;
  2. using Emby.Naming.Video;
  3. using MediaBrowser.Model.Entities;
  4. using Xunit;
  5. using MediaType = Emby.Naming.Common.MediaType;
  6. namespace Jellyfin.Naming.Tests.Video
  7. {
  8. public class ExtraTests
  9. {
  10. private readonly NamingOptions _videoOptions = new NamingOptions();
  11. // Requirements
  12. // movie-deleted = ExtraType deletedscene
  13. // All of the above rules should be configurable through the options objects (ideally, even the ExtraTypes)
  14. [Fact]
  15. public void TestKodiExtras()
  16. {
  17. Test("trailer.mp4", ExtraType.Trailer, _videoOptions);
  18. Test("300-trailer.mp4", ExtraType.Trailer, _videoOptions);
  19. Test("theme.mp3", ExtraType.ThemeSong, _videoOptions);
  20. }
  21. [Fact]
  22. public void TestExpandedExtras()
  23. {
  24. Test("trailer.mp4", ExtraType.Trailer, _videoOptions);
  25. Test("trailer.mp3", null, _videoOptions);
  26. Test("300-trailer.mp4", ExtraType.Trailer, _videoOptions);
  27. Test("theme.mp3", ExtraType.ThemeSong, _videoOptions);
  28. Test("theme.mkv", null, _videoOptions);
  29. Test("300-scene.mp4", ExtraType.Scene, _videoOptions);
  30. Test("300-scene2.mp4", ExtraType.Scene, _videoOptions);
  31. Test("300-clip.mp4", ExtraType.Clip, _videoOptions);
  32. Test("300-deleted.mp4", ExtraType.DeletedScene, _videoOptions);
  33. Test("300-deletedscene.mp4", ExtraType.DeletedScene, _videoOptions);
  34. Test("300-interview.mp4", ExtraType.Interview, _videoOptions);
  35. Test("300-behindthescenes.mp4", ExtraType.BehindTheScenes, _videoOptions);
  36. }
  37. [Theory]
  38. [InlineData(ExtraType.BehindTheScenes, "behind the scenes")]
  39. [InlineData(ExtraType.DeletedScene, "deleted scenes")]
  40. [InlineData(ExtraType.Interview, "interviews")]
  41. [InlineData(ExtraType.Scene, "scenes")]
  42. [InlineData(ExtraType.Sample, "samples")]
  43. [InlineData(ExtraType.Clip, "shorts")]
  44. [InlineData(ExtraType.Clip, "featurettes")]
  45. [InlineData(ExtraType.Unknown, "extras")]
  46. public void TestDirectories(ExtraType type, string dirName)
  47. {
  48. Test(dirName + "/300.mp4", type, _videoOptions);
  49. Test("300/" + dirName + "/something.mkv", type, _videoOptions);
  50. Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", type, _videoOptions);
  51. }
  52. [Theory]
  53. [InlineData("gibberish")]
  54. [InlineData("not a scene")]
  55. [InlineData("The Big Short")]
  56. public void TestNonExtraDirectories(string dirName)
  57. {
  58. Test(dirName + "/300.mp4", null, _videoOptions);
  59. Test("300/" + dirName + "/something.mkv", null, _videoOptions);
  60. Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", null, _videoOptions);
  61. Test("/data/something/Movies/" + dirName + "/" + dirName + ".mp4", null, _videoOptions);
  62. }
  63. [Fact]
  64. public void TestSample()
  65. {
  66. Test("300-sample.mp4", ExtraType.Sample, _videoOptions);
  67. }
  68. private void Test(string input, ExtraType? expectedType, NamingOptions videoOptions)
  69. {
  70. var parser = GetExtraTypeParser(videoOptions);
  71. var extraType = parser.GetExtraInfo(input).ExtraType;
  72. if (expectedType == null)
  73. {
  74. Assert.Null(extraType);
  75. }
  76. else
  77. {
  78. Assert.Equal(expectedType, extraType);
  79. }
  80. }
  81. [Fact]
  82. public void TestExtraInfo_InvalidRuleType()
  83. {
  84. var rule = new ExtraRule(ExtraType.Unknown, ExtraRuleType.Regex, @"([eE]x(tra)?\.\w+)", MediaType.Video);
  85. var options = new NamingOptions { VideoExtraRules = new[] { rule } };
  86. var res = GetExtraTypeParser(options).GetExtraInfo("extra.mp4");
  87. Assert.Equal(rule, res.Rule);
  88. }
  89. private ExtraResolver GetExtraTypeParser(NamingOptions videoOptions)
  90. {
  91. return new ExtraResolver(videoOptions);
  92. }
  93. }
  94. }