2022-02-06 23:26:25 +01:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using Emby.Naming.Common;
|
2022-02-21 21:59:41 +01:00
|
|
|
using MediaBrowser.Controller;
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
2022-02-06 23:26:25 +01:00
|
|
|
using MediaBrowser.Controller.Entities;
|
2022-02-21 21:59:41 +01:00
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
2022-02-06 23:26:25 +01:00
|
|
|
using MediaBrowser.Controller.Library;
|
2022-02-21 21:59:41 +01:00
|
|
|
using MediaBrowser.Controller.LiveTv;
|
2022-02-06 23:26:25 +01:00
|
|
|
using MediaBrowser.Controller.MediaEncoding;
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
using MediaBrowser.Model.Globalization;
|
|
|
|
using MediaBrowser.Providers.MediaInfo;
|
|
|
|
using Moq;
|
|
|
|
using Xunit;
|
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
namespace Jellyfin.Providers.Tests.MediaInfo;
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
public class AudioResolverTests
|
|
|
|
{
|
|
|
|
private readonly AudioResolver _audioResolver;
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
public AudioResolverTests()
|
|
|
|
{
|
|
|
|
// prep BaseItem and Video for calls made that expect managers
|
|
|
|
Video.LiveTvManager = Mock.Of<ILiveTvManager>();
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
var applicationPaths = new Mock<IServerApplicationPaths>().Object;
|
|
|
|
var serverConfig = new Mock<IServerConfigurationManager>();
|
|
|
|
serverConfig.Setup(c => c.ApplicationPaths)
|
|
|
|
.Returns(applicationPaths);
|
|
|
|
BaseItem.ConfigurationManager = serverConfig.Object;
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
// build resolver to test with
|
|
|
|
var localizationManager = Mock.Of<ILocalizationManager>();
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
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
|
2022-02-06 23:26:25 +01:00
|
|
|
{
|
2022-02-21 21:59:41 +01:00
|
|
|
MediaStreams = new List<MediaStream>
|
|
|
|
{
|
|
|
|
new()
|
|
|
|
}
|
|
|
|
}));
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
_audioResolver = new AudioResolver(localizationManager, mediaEncoder.Object, new NamingOptions());
|
|
|
|
}
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
[Theory]
|
|
|
|
[InlineData("My.Video.srt", false, false)]
|
|
|
|
[InlineData("My.Video.mp3", false, true)]
|
|
|
|
[InlineData("My.Video.srt", true, false)]
|
|
|
|
[InlineData("My.Video.mp3", true, true)]
|
|
|
|
public async void GetExternalStreams_MixedFilenames_PicksAudio(string file, bool metadataDirectory, bool matches)
|
|
|
|
{
|
|
|
|
BaseItem.MediaSourceManager = Mock.Of<IMediaSourceManager>();
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
var video = new Movie
|
2022-02-06 23:26:25 +01:00
|
|
|
{
|
2022-02-21 21:59:41 +01:00
|
|
|
Path = MediaInfoResolverTests.VideoDirectoryPath + "/My.Video.mkv"
|
|
|
|
};
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
var directoryService = MediaInfoResolverTests.GetDirectoryServiceForExternalFile(file, metadataDirectory);
|
|
|
|
var streams = await _audioResolver.GetExternalStreamsAsync(video, 0, directoryService, false, CancellationToken.None);
|
2022-02-06 23:26:25 +01:00
|
|
|
|
2022-02-21 21:59:41 +01:00
|
|
|
if (matches)
|
|
|
|
{
|
2022-02-06 23:26:25 +01:00
|
|
|
Assert.Single(streams);
|
|
|
|
var actual = streams[0];
|
2022-02-21 21:59:41 +01:00
|
|
|
Assert.Equal(MediaStreamType.Audio, actual.Type);
|
2022-02-06 23:26:25 +01:00
|
|
|
}
|
2022-02-21 21:59:41 +01:00
|
|
|
else
|
2022-02-06 23:26:25 +01:00
|
|
|
{
|
2022-02-21 21:59:41 +01:00
|
|
|
Assert.Empty(streams);
|
2022-02-06 23:26:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|