2021-12-07 14:18:17 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using AutoFixture;
|
|
|
|
|
using AutoFixture.AutoMoq;
|
|
|
|
|
using Emby.Naming.Common;
|
|
|
|
|
using Emby.Server.Implementations.Library.Resolvers;
|
2021-12-20 11:15:20 +00:00
|
|
|
|
using Emby.Server.Implementations.Library.Resolvers.Audio;
|
2021-12-07 14:18:17 +00:00
|
|
|
|
using MediaBrowser.Controller.Configuration;
|
|
|
|
|
using MediaBrowser.Controller.Entities;
|
|
|
|
|
using MediaBrowser.Controller.Entities.Movies;
|
|
|
|
|
using MediaBrowser.Controller.Entities.TV;
|
|
|
|
|
using MediaBrowser.Controller.Library;
|
2021-12-20 11:15:20 +00:00
|
|
|
|
using MediaBrowser.Controller.Providers;
|
2021-12-07 14:18:17 +00:00
|
|
|
|
using MediaBrowser.Controller.Resolvers;
|
|
|
|
|
using MediaBrowser.Controller.Sorting;
|
|
|
|
|
using MediaBrowser.Model.Entities;
|
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
|
using Moq;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Jellyfin.Server.Implementations.Tests.Library.LibraryManager;
|
|
|
|
|
|
|
|
|
|
public class FindExtrasTests
|
|
|
|
|
{
|
|
|
|
|
private readonly Emby.Server.Implementations.Library.LibraryManager _libraryManager;
|
2021-12-20 11:15:20 +00:00
|
|
|
|
private readonly Mock<IFileSystem> _fileSystemMock;
|
2021-12-07 14:18:17 +00:00
|
|
|
|
|
|
|
|
|
public FindExtrasTests()
|
|
|
|
|
{
|
|
|
|
|
var fixture = new Fixture().Customize(new AutoMoqCustomization());
|
|
|
|
|
fixture.Register(() => new NamingOptions());
|
|
|
|
|
var configMock = fixture.Freeze<Mock<IServerConfigurationManager>>();
|
|
|
|
|
configMock.Setup(c => c.ApplicationPaths.ProgramDataPath).Returns("/data");
|
2021-12-20 11:15:20 +00:00
|
|
|
|
_fileSystemMock = fixture.Freeze<Mock<IFileSystem>>();
|
|
|
|
|
_fileSystemMock.Setup(f => f.GetFileInfo(It.IsAny<string>())).Returns<string>(path => new FileSystemMetadata { FullName = path });
|
2021-12-07 14:18:17 +00:00
|
|
|
|
_libraryManager = fixture.Build<Emby.Server.Implementations.Library.LibraryManager>().Do(s => s.AddParts(
|
|
|
|
|
fixture.Create<IEnumerable<IResolverIgnoreRule>>(),
|
2021-12-20 11:15:20 +00:00
|
|
|
|
new List<IItemResolver> { new GenericVideoResolver<Video>(fixture.Create<NamingOptions>()), new AudioResolver(fixture.Create<NamingOptions>()) },
|
2021-12-07 14:18:17 +00:00
|
|
|
|
fixture.Create<IEnumerable<IIntroProvider>>(),
|
|
|
|
|
fixture.Create<IEnumerable<IBaseItemComparer>>(),
|
|
|
|
|
fixture.Create<IEnumerable<ILibraryPostScanTask>>()))
|
|
|
|
|
.Create();
|
|
|
|
|
|
|
|
|
|
// This is pretty terrible but unavoidable
|
|
|
|
|
BaseItem.FileSystem ??= fixture.Create<IFileSystem>();
|
|
|
|
|
BaseItem.MediaSourceManager ??= fixture.Create<IMediaSourceManager>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void FindExtras_SeparateMovieFolder_FindsCorrectExtras()
|
|
|
|
|
{
|
|
|
|
|
var owner = new Movie { Name = "Up", Path = "/movies/Up/Up.mkv" };
|
|
|
|
|
var paths = new List<string>
|
|
|
|
|
{
|
|
|
|
|
"/movies/Up/Up.mkv",
|
|
|
|
|
"/movies/Up/Up - trailer.mkv",
|
|
|
|
|
"/movies/Up/Up - sample.mkv",
|
|
|
|
|
"/movies/Up/Up something else.mkv"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var files = paths.Select(p => new FileSystemMetadata
|
|
|
|
|
{
|
|
|
|
|
FullName = p,
|
|
|
|
|
IsDirectory = false
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
2021-12-20 11:15:20 +00:00
|
|
|
|
var extras = _libraryManager.FindExtras(owner, files, new DirectoryService(_fileSystemMock.Object)).OrderBy(e => e.ExtraType).ToList();
|
2021-12-07 14:18:17 +00:00
|
|
|
|
|
|
|
|
|
Assert.Equal(2, extras.Count);
|
|
|
|
|
Assert.Equal(ExtraType.Trailer, extras[0].ExtraType);
|
|
|
|
|
Assert.Equal(ExtraType.Sample, extras[1].ExtraType);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void FindExtras_SeparateMovieFolderWithMixedExtras_FindsCorrectExtras()
|
|
|
|
|
{
|
|
|
|
|
var owner = new Movie { Name = "Up", Path = "/movies/Up/Up.mkv" };
|
|
|
|
|
var paths = new List<string>
|
|
|
|
|
{
|
|
|
|
|
"/movies/Up/Up.mkv",
|
|
|
|
|
"/movies/Up/Up - trailer.mkv",
|
2021-12-20 11:15:20 +00:00
|
|
|
|
"/movies/Up/trailers",
|
|
|
|
|
"/movies/Up/theme-music",
|
|
|
|
|
"/movies/Up/theme.mp3",
|
|
|
|
|
"/movies/Up/not a theme.mp3",
|
|
|
|
|
"/movies/Up/behind the scenes",
|
2021-12-07 14:18:17 +00:00
|
|
|
|
"/movies/Up/behind the scenes.mkv",
|
|
|
|
|
"/movies/Up/Up - sample.mkv",
|
|
|
|
|
"/movies/Up/Up something else.mkv"
|
|
|
|
|
};
|
|
|
|
|
|
2021-12-20 11:15:20 +00:00
|
|
|
|
_fileSystemMock.Setup(f => f.GetFiles(
|
|
|
|
|
"/movies/Up/trailers",
|
|
|
|
|
It.IsAny<string[]>(),
|
|
|
|
|
false,
|
|
|
|
|
false))
|
|
|
|
|
.Returns(new List<FileSystemMetadata>
|
|
|
|
|
{
|
|
|
|
|
new ()
|
|
|
|
|
{
|
|
|
|
|
FullName = "/movies/Up/trailers/some trailer.mkv",
|
|
|
|
|
Name = "some trailer.mkv",
|
|
|
|
|
IsDirectory = false
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
_fileSystemMock.Setup(f => f.GetFiles(
|
|
|
|
|
"/movies/Up/behind the scenes",
|
|
|
|
|
It.IsAny<string[]>(),
|
|
|
|
|
false,
|
|
|
|
|
false))
|
|
|
|
|
.Returns(new List<FileSystemMetadata>
|
|
|
|
|
{
|
|
|
|
|
new ()
|
|
|
|
|
{
|
|
|
|
|
FullName = "/movies/Up/behind the scenes/the making of Up.mkv",
|
|
|
|
|
Name = "the making of Up.mkv",
|
|
|
|
|
IsDirectory = false
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
_fileSystemMock.Setup(f => f.GetFiles(
|
|
|
|
|
"/movies/Up/theme-music",
|
|
|
|
|
It.IsAny<string[]>(),
|
|
|
|
|
false,
|
|
|
|
|
false))
|
|
|
|
|
.Returns(new List<FileSystemMetadata>
|
|
|
|
|
{
|
|
|
|
|
new ()
|
|
|
|
|
{
|
|
|
|
|
FullName = "/movies/Up/theme-music/theme2.mp3",
|
|
|
|
|
Name = "theme2.mp3",
|
|
|
|
|
IsDirectory = false
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
2021-12-07 14:18:17 +00:00
|
|
|
|
var files = paths.Select(p => new FileSystemMetadata
|
|
|
|
|
{
|
|
|
|
|
FullName = p,
|
2021-12-20 11:15:20 +00:00
|
|
|
|
Name = Path.GetFileName(p),
|
|
|
|
|
IsDirectory = string.IsNullOrEmpty(Path.GetExtension(p))
|
2021-12-07 14:18:17 +00:00
|
|
|
|
}).ToList();
|
|
|
|
|
|
2021-12-20 11:15:20 +00:00
|
|
|
|
var extras = _libraryManager.FindExtras(owner, files, new DirectoryService(_fileSystemMock.Object)).OrderBy(e => e.ExtraType).ToList();
|
2021-12-07 14:18:17 +00:00
|
|
|
|
|
2021-12-20 11:15:20 +00:00
|
|
|
|
Assert.Equal(6, extras.Count);
|
2021-12-07 14:18:17 +00:00
|
|
|
|
Assert.Equal(ExtraType.Trailer, extras[0].ExtraType);
|
|
|
|
|
Assert.Equal(ExtraType.Trailer, extras[1].ExtraType);
|
|
|
|
|
Assert.Equal(ExtraType.BehindTheScenes, extras[2].ExtraType);
|
|
|
|
|
Assert.Equal(ExtraType.Sample, extras[3].ExtraType);
|
2021-12-20 11:15:20 +00:00
|
|
|
|
Assert.Equal(ExtraType.ThemeSong, extras[4].ExtraType);
|
|
|
|
|
Assert.Equal(ExtraType.ThemeSong, extras[5].ExtraType);
|
2021-12-07 14:18:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void FindExtras_SeparateMovieFolderWithMixedExtras_FindsOnlyExtrasInMovieFolder()
|
|
|
|
|
{
|
|
|
|
|
var owner = new Movie { Name = "Up", Path = "/movies/Up/Up.mkv" };
|
|
|
|
|
var paths = new List<string>
|
|
|
|
|
{
|
|
|
|
|
"/movies/Up/Up.mkv",
|
|
|
|
|
"/movies/Up/trailer.mkv",
|
|
|
|
|
"/movies/Another Movie/trailer.mkv"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var files = paths.Select(p => new FileSystemMetadata
|
|
|
|
|
{
|
|
|
|
|
FullName = p,
|
|
|
|
|
IsDirectory = false
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
2021-12-20 11:15:20 +00:00
|
|
|
|
var extras = _libraryManager.FindExtras(owner, files, new DirectoryService(_fileSystemMock.Object)).OrderBy(e => e.ExtraType).ToList();
|
2021-12-07 14:18:17 +00:00
|
|
|
|
|
|
|
|
|
Assert.Single(extras);
|
|
|
|
|
Assert.Equal(ExtraType.Trailer, extras[0].ExtraType);
|
|
|
|
|
Assert.Equal("trailer", extras[0].FileNameWithoutExtension);
|
|
|
|
|
Assert.Equal("/movies/Up/trailer.mkv", extras[0].Path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void FindExtras_SeparateMovieFolderWithParts_FindsCorrectExtras()
|
|
|
|
|
{
|
|
|
|
|
var owner = new Movie { Name = "Up", Path = "/movies/Up/Up - part1.mkv" };
|
|
|
|
|
var paths = new List<string>
|
|
|
|
|
{
|
|
|
|
|
"/movies/Up/Up - part1.mkv",
|
|
|
|
|
"/movies/Up/Up - part2.mkv",
|
|
|
|
|
"/movies/Up/trailer.mkv",
|
|
|
|
|
"/movies/Another Movie/trailer.mkv"
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var files = paths.Select(p => new FileSystemMetadata
|
|
|
|
|
{
|
|
|
|
|
FullName = p,
|
|
|
|
|
IsDirectory = false
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
2021-12-20 11:15:20 +00:00
|
|
|
|
var extras = _libraryManager.FindExtras(owner, files, new DirectoryService(_fileSystemMock.Object)).OrderBy(e => e.ExtraType).ToList();
|
2021-12-07 14:18:17 +00:00
|
|
|
|
|
|
|
|
|
Assert.Single(extras);
|
|
|
|
|
Assert.Equal(ExtraType.Trailer, extras[0].ExtraType);
|
|
|
|
|
Assert.Equal("trailer", extras[0].FileNameWithoutExtension);
|
|
|
|
|
Assert.Equal("/movies/Up/trailer.mkv", extras[0].Path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void FindExtras_SeriesWithTrailers_FindsCorrectExtras()
|
|
|
|
|
{
|
|
|
|
|
var owner = new Series { Name = "Dexter", Path = "/series/Dexter" };
|
|
|
|
|
var paths = new List<string>
|
|
|
|
|
{
|
|
|
|
|
"/series/Dexter/Season 1/S01E01.mkv",
|
|
|
|
|
"/series/Dexter/trailer.mkv",
|
|
|
|
|
"/series/Dexter/trailers/trailer2.mkv",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var files = paths.Select(p => new FileSystemMetadata
|
|
|
|
|
{
|
|
|
|
|
FullName = p,
|
|
|
|
|
IsDirectory = string.IsNullOrEmpty(Path.GetExtension(p))
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
2021-12-20 11:15:20 +00:00
|
|
|
|
var extras = _libraryManager.FindExtras(owner, files, new DirectoryService(_fileSystemMock.Object)).OrderBy(e => e.ExtraType).ToList();
|
2021-12-07 14:18:17 +00:00
|
|
|
|
|
|
|
|
|
Assert.Equal(2, extras.Count);
|
|
|
|
|
Assert.Equal(ExtraType.Trailer, extras[0].ExtraType);
|
|
|
|
|
Assert.Equal("trailer", extras[0].FileNameWithoutExtension);
|
|
|
|
|
Assert.Equal("/series/Dexter/trailer.mkv", extras[0].Path);
|
|
|
|
|
Assert.Equal("/series/Dexter/trailers/trailer2.mkv", extras[1].Path);
|
|
|
|
|
}
|
|
|
|
|
}
|