ExtraTests.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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);
  18. Test("300-trailer.mp4", ExtraType.Trailer);
  19. Test("theme.mp3", ExtraType.ThemeSong);
  20. }
  21. [Fact]
  22. public void TestExpandedExtras()
  23. {
  24. Test("trailer.mp4", ExtraType.Trailer);
  25. Test("trailer.mp3", null);
  26. Test("300-trailer.mp4", ExtraType.Trailer);
  27. Test("stuff trailerthings.mkv", null);
  28. Test("theme.mp3", ExtraType.ThemeSong);
  29. Test("theme.mkv", null);
  30. Test("300-scene.mp4", ExtraType.Scene);
  31. Test("300-scene2.mp4", ExtraType.Scene);
  32. Test("300-clip.mp4", ExtraType.Clip);
  33. Test("300-deleted.mp4", ExtraType.DeletedScene);
  34. Test("300-deletedscene.mp4", ExtraType.DeletedScene);
  35. Test("300-interview.mp4", ExtraType.Interview);
  36. Test("300-behindthescenes.mp4", ExtraType.BehindTheScenes);
  37. }
  38. [Theory]
  39. [InlineData(ExtraType.BehindTheScenes, "behind the scenes")]
  40. [InlineData(ExtraType.DeletedScene, "deleted scenes")]
  41. [InlineData(ExtraType.Interview, "interviews")]
  42. [InlineData(ExtraType.Scene, "scenes")]
  43. [InlineData(ExtraType.Sample, "samples")]
  44. [InlineData(ExtraType.Clip, "shorts")]
  45. [InlineData(ExtraType.Clip, "featurettes")]
  46. [InlineData(ExtraType.ThemeVideo, "backdrops")]
  47. [InlineData(ExtraType.Unknown, "extras")]
  48. public void TestDirectories(ExtraType type, string dirName)
  49. {
  50. Test(dirName + "/300.mp4", type);
  51. Test("300/" + dirName + "/something.mkv", type);
  52. Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", type);
  53. }
  54. [Theory]
  55. [InlineData("gibberish")]
  56. [InlineData("not a scene")]
  57. [InlineData("The Big Short")]
  58. public void TestNonExtraDirectories(string dirName)
  59. {
  60. Test(dirName + "/300.mp4", null);
  61. Test("300/" + dirName + "/something.mkv", null);
  62. Test("/data/something/Movies/300/" + dirName + "/whoknows.mp4", null);
  63. Test("/data/something/Movies/" + dirName + "/" + dirName + ".mp4", null);
  64. }
  65. [Fact]
  66. public void TestSample()
  67. {
  68. Test("300-sample.mp4", ExtraType.Sample);
  69. }
  70. private void Test(string input, ExtraType? expectedType)
  71. {
  72. var extraType = ExtraRuleResolver.GetExtraInfo(input, _videoOptions).ExtraType;
  73. Assert.Equal(expectedType, extraType);
  74. }
  75. [Fact]
  76. public void TestExtraInfo_InvalidRuleType()
  77. {
  78. var rule = new ExtraRule(ExtraType.Unknown, ExtraRuleType.Regex, @"([eE]x(tra)?\.\w+)", MediaType.Video);
  79. var options = new NamingOptions { VideoExtraRules = new[] { rule } };
  80. var res = ExtraRuleResolver.GetExtraInfo("extra.mp4", options);
  81. Assert.Equal(rule, res.Rule);
  82. }
  83. }
  84. }