using System; 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.Globalization; using MediaBrowser.Providers.MediaInfo; using Moq; using Xunit; namespace Jellyfin.Providers.Tests.MediaInfo { public class AudioResolverTests { private const string VideoDirectoryPath = "Test Data/Video"; private const string MetadataDirectoryPath = "Test Data/Metadata"; private readonly AudioResolver _audioResolver; public AudioResolverTests() { var englishCultureDto = new CultureDto("English", "English", "en", new[] { "eng" }); var localizationManager = new Mock(MockBehavior.Loose); localizationManager.Setup(lm => lm.FindLanguageInfo(It.IsRegex(@"en.*", RegexOptions.IgnoreCase))) .Returns(englishCultureDto); var mediaEncoder = new Mock(MockBehavior.Strict); mediaEncoder.Setup(me => me.GetMediaInfo(It.IsAny(), It.IsAny())) .Returns((_, _) => Task.FromResult(new MediaBrowser.Model.MediaInfo.MediaInfo { MediaStreams = new List { new() } })); _audioResolver = new AudioResolver(localizationManager.Object, mediaEncoder.Object, new NamingOptions()); } [Fact] public async void AddExternalStreamsAsync_GivenMixedFilenames_ReturnsValidSubtitles() { var startIndex = 0; var index = startIndex; var files = new[] { VideoDirectoryPath + "/MyVideo.en.aac", VideoDirectoryPath + "/MyVideo.en.forced.default.dts", VideoDirectoryPath + "/My.Video.mp3", VideoDirectoryPath + "/Some.Other.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.en.mp3", VideoDirectoryPath + "/My.Video.en.forced.mp3", VideoDirectoryPath + "/My.Video.en.default.forced.aac", VideoDirectoryPath + "/My.Video.Label.mp3", VideoDirectoryPath + "/My.Video.With Additional Garbage.en.aac", VideoDirectoryPath + "/My.Video.With.Additional.Garbage.en.mp3" }; var metadataFiles = new[] { MetadataDirectoryPath + "/My.Video.en.aac" }; var expectedResult = new[] { CreateMediaStream(VideoDirectoryPath + "/MyVideo.en.aac", "eng", null, index++), CreateMediaStream(VideoDirectoryPath + "/MyVideo.en.forced.default.dts", "eng", null, index++, isDefault: true, isForced: true), CreateMediaStream(VideoDirectoryPath + "/My.Video.mp3", null, null, index++), CreateMediaStream(VideoDirectoryPath + "/My.Video.en.mp3", "eng", null, index++), CreateMediaStream(VideoDirectoryPath + "/My.Video.en.forced.mp3", "eng", null, index++, isDefault: false, isForced: true), CreateMediaStream(VideoDirectoryPath + "/My.Video.en.default.forced.aac", "eng", null, index++, isDefault: true, isForced: true), CreateMediaStream(VideoDirectoryPath + "/My.Video.Label.mp3", null, "Label", index++), CreateMediaStream(VideoDirectoryPath + "/My.Video.With Additional Garbage.en.aac", "eng", "With Additional Garbage", index++), CreateMediaStream(VideoDirectoryPath + "/My.Video.With.Additional.Garbage.en.mp3", "eng", "With.Additional.Garbage", index++), CreateMediaStream(MetadataDirectoryPath + "/My.Video.en.aac", "eng", null, index) }; BaseItem.MediaSourceManager = Mock.Of(); var video = new Mock