ExtraTests.cs 3.6 KB

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