|
@@ -1,6 +1,13 @@
|
|
-#pragma warning disable CA1002 // Do not expose generic lists
|
|
|
|
-
|
|
|
|
|
|
+using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
|
|
+using System.Text.RegularExpressions;
|
|
|
|
+using System.Threading;
|
|
|
|
+using System.Threading.Tasks;
|
|
|
|
+using Emby.Naming.Common;
|
|
|
|
+using MediaBrowser.Controller.Entities;
|
|
|
|
+using MediaBrowser.Controller.Library;
|
|
|
|
+using MediaBrowser.Controller.MediaEncoding;
|
|
|
|
+using MediaBrowser.Controller.Providers;
|
|
using MediaBrowser.Model.Entities;
|
|
using MediaBrowser.Model.Entities;
|
|
using MediaBrowser.Model.Globalization;
|
|
using MediaBrowser.Model.Globalization;
|
|
using MediaBrowser.Providers.MediaInfo;
|
|
using MediaBrowser.Providers.MediaInfo;
|
|
@@ -11,58 +18,103 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
|
{
|
|
{
|
|
public class SubtitleResolverTests
|
|
public class SubtitleResolverTests
|
|
{
|
|
{
|
|
- public static TheoryData<List<MediaStream>, string, int, string[], MediaStream[]> AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles_TestData()
|
|
|
|
|
|
+ private const string VideoDirectoryPath = "Test Data/Video";
|
|
|
|
+ private const string MetadataDirectoryPath = "Test Data/Metadata";
|
|
|
|
+ private readonly SubtitleResolver _subtitleResolver;
|
|
|
|
+
|
|
|
|
+ public SubtitleResolverTests()
|
|
{
|
|
{
|
|
- var data = new TheoryData<List<MediaStream>, string, int, string[], MediaStream[]>();
|
|
|
|
-
|
|
|
|
- var index = 0;
|
|
|
|
- data.Add(
|
|
|
|
- new List<MediaStream>(),
|
|
|
|
- "/video/My.Video.mkv",
|
|
|
|
- index,
|
|
|
|
- new[]
|
|
|
|
- {
|
|
|
|
- "/video/My.Video.mp3",
|
|
|
|
- "/video/My.Video.png",
|
|
|
|
- "/video/My.Video.srt",
|
|
|
|
- "/video/My.Video.txt",
|
|
|
|
- "/video/My.Video.vtt",
|
|
|
|
- "/video/My.Video.ass",
|
|
|
|
- "/video/My.Video.sub",
|
|
|
|
- "/video/My.Video.ssa",
|
|
|
|
- "/video/My.Video.smi",
|
|
|
|
- "/video/My.Video.sami",
|
|
|
|
- "/video/My.Video.en.srt",
|
|
|
|
- "/video/My.Video.default.en.srt",
|
|
|
|
- "/video/My.Video.default.forced.en.srt",
|
|
|
|
- "/video/My.Video.en.default.forced.srt",
|
|
|
|
- "/video/My.Video.With.Additional.Garbage.en.srt",
|
|
|
|
- "/video/My.Video With Additional Garbage.srt"
|
|
|
|
- },
|
|
|
|
- new[]
|
|
|
|
|
|
+ var englishCultureDto = new CultureDto("English", "English", "en", new[] { "eng" });
|
|
|
|
+ var frenchCultureDto = new CultureDto("French", "French", "fr", new[] { "fre", "fra" });
|
|
|
|
+
|
|
|
|
+ var localizationManager = new Mock<ILocalizationManager>(MockBehavior.Loose);
|
|
|
|
+ localizationManager.Setup(lm => lm.FindLanguageInfo(It.IsRegex(@"en.*", RegexOptions.IgnoreCase)))
|
|
|
|
+ .Returns(englishCultureDto);
|
|
|
|
+ localizationManager.Setup(lm => lm.FindLanguageInfo(It.IsRegex(@"fr.*", RegexOptions.IgnoreCase)))
|
|
|
|
+ .Returns(frenchCultureDto);
|
|
|
|
+
|
|
|
|
+ var mediaEncoder = new Mock<IMediaEncoder>(MockBehavior.Strict);
|
|
|
|
+ mediaEncoder.Setup(me => me.GetMediaInfo(It.IsAny<MediaInfoRequest>(), It.IsAny<CancellationToken>()))
|
|
|
|
+ .Returns<MediaInfoRequest, CancellationToken>((_, _) => Task.FromResult(new MediaBrowser.Model.MediaInfo.MediaInfo
|
|
{
|
|
{
|
|
- CreateMediaStream("/video/My.Video.srt", "srt", null, index++),
|
|
|
|
- CreateMediaStream("/video/My.Video.vtt", "vtt", null, index++),
|
|
|
|
- CreateMediaStream("/video/My.Video.ass", "ass", null, index++),
|
|
|
|
- CreateMediaStream("/video/My.Video.sub", "sub", null, index++),
|
|
|
|
- CreateMediaStream("/video/My.Video.ssa", "ssa", null, index++),
|
|
|
|
- CreateMediaStream("/video/My.Video.smi", "smi", null, index++),
|
|
|
|
- CreateMediaStream("/video/My.Video.sami", "sami", null, index++),
|
|
|
|
- CreateMediaStream("/video/My.Video.en.srt", "srt", "en", index++),
|
|
|
|
- CreateMediaStream("/video/My.Video.default.en.srt", "srt", "en", index++, isDefault: true),
|
|
|
|
- CreateMediaStream("/video/My.Video.default.forced.en.srt", "srt", "en", index++, isForced: true, isDefault: true),
|
|
|
|
- CreateMediaStream("/video/My.Video.en.default.forced.srt", "srt", "en", index++, isForced: true, isDefault: true),
|
|
|
|
- CreateMediaStream("/video/My.Video.With.Additional.Garbage.en.srt", "srt", "en", index),
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- return data;
|
|
|
|
|
|
+ MediaStreams = new List<MediaStream>
|
|
|
|
+ {
|
|
|
|
+ new()
|
|
|
|
+ }
|
|
|
|
+ }));
|
|
|
|
+
|
|
|
|
+ _subtitleResolver = new SubtitleResolver(localizationManager.Object, mediaEncoder.Object, new NamingOptions());
|
|
}
|
|
}
|
|
|
|
|
|
- [Theory]
|
|
|
|
- [MemberData(nameof(AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles_TestData))]
|
|
|
|
- public void AddExternalSubtitleStreams_GivenMixedFilenames_ReturnsValidSubtitles(List<MediaStream> streams, string videoPath, int startIndex, string[] files, MediaStream[] expectedResult)
|
|
|
|
|
|
+ [Fact]
|
|
|
|
+ public async void AddExternalStreamsAsync_GivenMixedFilenames_ReturnsValidSubtitles()
|
|
{
|
|
{
|
|
- new SubtitleResolver(Mock.Of<ILocalizationManager>()).AddExternalSubtitleStreams(streams, videoPath, startIndex, files);
|
|
|
|
|
|
+ var startIndex = 0;
|
|
|
|
+ var index = startIndex;
|
|
|
|
+ var files = new[]
|
|
|
|
+ {
|
|
|
|
+ VideoDirectoryPath + "/MyVideo.en.srt",
|
|
|
|
+ VideoDirectoryPath + "/MyVideo.en.forced.default.sub",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.mp3",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.png",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.srt",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.txt",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.vtt",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.ass",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.sub",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.ssa",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.smi",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.sami",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.mks",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.en.srt",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.default.en.srt",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.default.forced.en.srt",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.en.default.forced.srt",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.en.With Additional Garbage.sub",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.With Additional Garbage.English.sub",
|
|
|
|
+ VideoDirectoryPath + "/My.Video.With.Additional.Garbage.en.srt",
|
|
|
|
+ VideoDirectoryPath + "/Some.Other.Video.srt"
|
|
|
|
+ };
|
|
|
|
+ var metadataFiles = new[]
|
|
|
|
+ {
|
|
|
|
+ MetadataDirectoryPath + "/My.Video.en.srt"
|
|
|
|
+ };
|
|
|
|
+ var expectedResult = new[]
|
|
|
|
+ {
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/MyVideo.en.srt", "srt", "eng", null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/MyVideo.en.forced.default.sub", "sub", "eng", null, index++, isDefault: true, isForced: true),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.srt", "srt", null, null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.vtt", "vtt", null, null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.ass", "ass", null, null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.sub", "sub", null, null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.ssa", "ssa", null, null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.smi", "smi", null, null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.sami", "sami", null, null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.mks", "mks", null, null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.en.srt", "srt", "eng", null, index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.default.en.srt", "srt", "eng", null, index++, isDefault: true),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.default.forced.en.srt", "srt", "eng", null, index++, isForced: true, isDefault: true),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.en.default.forced.srt", "srt", "eng", null, index++, isForced: true, isDefault: true),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.en.With Additional Garbage.sub", "sub", "eng", "With Additional Garbage", index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.With Additional Garbage.English.sub", "sub", "eng", "With Additional Garbage", index++),
|
|
|
|
+ CreateMediaStream(VideoDirectoryPath + "/My.Video.With.Additional.Garbage.en.srt", "srt", "eng", "With.Additional.Garbage", index++),
|
|
|
|
+ CreateMediaStream(MetadataDirectoryPath + "/My.Video.en.srt", "srt", "eng", null, index)
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ BaseItem.MediaSourceManager = Mock.Of<IMediaSourceManager>();
|
|
|
|
+
|
|
|
|
+ var video = new Mock<Video>();
|
|
|
|
+ video.CallBase = true;
|
|
|
|
+ video.Setup(moq => moq.Path).Returns(VideoDirectoryPath + "/My.Video.mkv");
|
|
|
|
+ video.Setup(moq => moq.GetInternalMetadataPath()).Returns(MetadataDirectoryPath);
|
|
|
|
+
|
|
|
|
+ var directoryService = new Mock<IDirectoryService>(MockBehavior.Strict);
|
|
|
|
+ directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(@"Test Data[/\\]Video"), It.IsAny<bool>(), It.IsAny<bool>()))
|
|
|
|
+ .Returns(files);
|
|
|
|
+ directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(@"Test Data[/\\]Metadata"), It.IsAny<bool>(), It.IsAny<bool>()))
|
|
|
|
+ .Returns(metadataFiles);
|
|
|
|
+
|
|
|
|
+ var streams = await _subtitleResolver.GetExternalStreamsAsync(video.Object, startIndex, directoryService.Object, false, CancellationToken.None);
|
|
|
|
|
|
Assert.Equal(expectedResult.Length, streams.Count);
|
|
Assert.Equal(expectedResult.Length, streams.Count);
|
|
for (var i = 0; i < expectedResult.Length; i++)
|
|
for (var i = 0; i < expectedResult.Length; i++)
|
|
@@ -77,31 +129,48 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
|
Assert.Equal(expected.IsDefault, actual.IsDefault);
|
|
Assert.Equal(expected.IsDefault, actual.IsDefault);
|
|
Assert.Equal(expected.IsForced, actual.IsForced);
|
|
Assert.Equal(expected.IsForced, actual.IsForced);
|
|
Assert.Equal(expected.Language, actual.Language);
|
|
Assert.Equal(expected.Language, actual.Language);
|
|
|
|
+ Assert.Equal(expected.Title, actual.Title);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
[Theory]
|
|
[Theory]
|
|
- [InlineData("/video/My Video.mkv", "/video/My Video.srt", "srt", null, false, false)]
|
|
|
|
- [InlineData("/video/My.Video.mkv", "/video/My.Video.srt", "srt", null, false, false)]
|
|
|
|
- [InlineData("/video/My.Video.mkv", "/video/My.Video.foreign.srt", "srt", null, true, false)]
|
|
|
|
- [InlineData("/video/My Video.mkv", "/video/My Video.forced.srt", "srt", null, true, false)]
|
|
|
|
- [InlineData("/video/My.Video.mkv", "/video/My.Video.default.srt", "srt", null, false, true)]
|
|
|
|
- [InlineData("/video/My.Video.mkv", "/video/My.Video.forced.default.srt", "srt", null, true, true)]
|
|
|
|
- [InlineData("/video/My.Video.mkv", "/video/My.Video.en.srt", "srt", "en", false, false)]
|
|
|
|
- [InlineData("/video/My.Video.mkv", "/video/My.Video.default.en.srt", "srt", "en", false, true)]
|
|
|
|
- [InlineData("/video/My.Video.mkv", "/video/My.Video.default.forced.en.srt", "srt", "en", true, true)]
|
|
|
|
- [InlineData("/video/My.Video.mkv", "/video/My.Video.en.default.forced.srt", "srt", "en", true, true)]
|
|
|
|
- public void AddExternalSubtitleStreams_GivenSingleFile_ReturnsExpectedSubtitle(string videoPath, string file, string codec, string? language, bool isForced, bool isDefault)
|
|
|
|
|
|
+ [InlineData("MyVideo.en.srt", "srt", "eng", null, false, false)]
|
|
|
|
+ [InlineData("MyVideo.en.forced.default.srt", "srt", "eng", null, true, true)]
|
|
|
|
+ [InlineData("My.Video.srt", "srt", null, null, false, false)]
|
|
|
|
+ [InlineData("My.Video.foreign.srt", "srt", null, null, true, false)]
|
|
|
|
+ [InlineData("My.Video.default.srt", "srt", null, null, false, true)]
|
|
|
|
+ [InlineData("My.Video.forced.default.srt", "srt", null, null, true, true)]
|
|
|
|
+ [InlineData("My.Video.en.srt", "srt", "eng", null, false, false)]
|
|
|
|
+ [InlineData("My.Video.fr.en.srt", "srt", "eng", "fr", false, false)]
|
|
|
|
+ [InlineData("My.Video.en.fr.srt", "srt", "fre", "en", false, false)]
|
|
|
|
+ [InlineData("My.Video.default.en.srt", "srt", "eng", null, false, true)]
|
|
|
|
+ [InlineData("My.Video.default.forced.en.srt", "srt", "eng", null, true, true)]
|
|
|
|
+ [InlineData("My.Video.en.default.forced.srt", "srt", "eng", null, true, true)]
|
|
|
|
+ [InlineData("My.Video.Track Label.srt", "srt", null, "Track Label", false, false)]
|
|
|
|
+ [InlineData("My.Video.Track.Label.srt", "srt", null, "Track.Label", false, false)]
|
|
|
|
+ [InlineData("My.Video.Track Label.en.default.forced.srt", "srt", "eng", "Track Label", true, true)]
|
|
|
|
+ [InlineData("My.Video.en.default.forced.Track Label.srt", "srt", "eng", "Track Label", true, true)]
|
|
|
|
+ public async void AddExternalStreamsAsync_GivenSingleFile_ReturnsExpectedSubtitle(string file, string codec, string? language, string? title, bool isForced, bool isDefault)
|
|
{
|
|
{
|
|
- var streams = new List<MediaStream>();
|
|
|
|
- var expected = CreateMediaStream(file, codec, language, 0, isForced, isDefault);
|
|
|
|
|
|
+ BaseItem.MediaSourceManager = Mock.Of<IMediaSourceManager>();
|
|
|
|
|
|
- new SubtitleResolver(Mock.Of<ILocalizationManager>()).AddExternalSubtitleStreams(streams, videoPath, 0, new[] { file });
|
|
|
|
|
|
+ var video = new Mock<Video>();
|
|
|
|
+ video.CallBase = true;
|
|
|
|
+ video.Setup(moq => moq.Path).Returns(VideoDirectoryPath + "/My.Video.mkv");
|
|
|
|
+ video.Setup(moq => moq.GetInternalMetadataPath()).Returns(MetadataDirectoryPath);
|
|
|
|
|
|
- Assert.Single(streams);
|
|
|
|
|
|
+ var directoryService = new Mock<IDirectoryService>(MockBehavior.Strict);
|
|
|
|
+ directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(@"Test Data[/\\]Video"), It.IsAny<bool>(), It.IsAny<bool>()))
|
|
|
|
+ .Returns(new[] { VideoDirectoryPath + "/" + file });
|
|
|
|
+ directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(@"Test Data[/\\]Metadata"), It.IsAny<bool>(), It.IsAny<bool>()))
|
|
|
|
+ .Returns(Array.Empty<string>());
|
|
|
|
|
|
|
|
+ var streams = await _subtitleResolver.GetExternalStreamsAsync(video.Object, 0, directoryService.Object, false, CancellationToken.None);
|
|
|
|
+
|
|
|
|
+ Assert.Single(streams);
|
|
var actual = streams[0];
|
|
var actual = streams[0];
|
|
|
|
|
|
|
|
+ var expected = CreateMediaStream(VideoDirectoryPath + "/" + file, codec, language, title, 0, isForced, isDefault);
|
|
Assert.Equal(expected.Index, actual.Index);
|
|
Assert.Equal(expected.Index, actual.Index);
|
|
Assert.Equal(expected.Type, actual.Type);
|
|
Assert.Equal(expected.Type, actual.Type);
|
|
Assert.Equal(expected.IsExternal, actual.IsExternal);
|
|
Assert.Equal(expected.IsExternal, actual.IsExternal);
|
|
@@ -109,9 +178,10 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
|
Assert.Equal(expected.IsDefault, actual.IsDefault);
|
|
Assert.Equal(expected.IsDefault, actual.IsDefault);
|
|
Assert.Equal(expected.IsForced, actual.IsForced);
|
|
Assert.Equal(expected.IsForced, actual.IsForced);
|
|
Assert.Equal(expected.Language, actual.Language);
|
|
Assert.Equal(expected.Language, actual.Language);
|
|
|
|
+ Assert.Equal(expected.Title, actual.Title);
|
|
}
|
|
}
|
|
|
|
|
|
- private static MediaStream CreateMediaStream(string path, string codec, string? language, int index, bool isForced = false, bool isDefault = false)
|
|
|
|
|
|
+ private static MediaStream CreateMediaStream(string path, string codec, string? language, string? title, int index, bool isForced = false, bool isDefault = false)
|
|
{
|
|
{
|
|
return new()
|
|
return new()
|
|
{
|
|
{
|
|
@@ -122,7 +192,8 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
|
Path = path,
|
|
Path = path,
|
|
IsDefault = isDefault,
|
|
IsDefault = isDefault,
|
|
IsForced = isForced,
|
|
IsForced = isForced,
|
|
- Language = language
|
|
|
|
|
|
+ Language = language,
|
|
|
|
+ Title = title
|
|
};
|
|
};
|
|
}
|
|
}
|
|
}
|
|
}
|