ExtraTests.cs 4.2 KB

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