jellyfin/Emby.Naming/AudioBook/AudioBookListResolver.cs

67 lines
2.0 KiB
C#
Raw Normal View History

using System.Collections.Generic;
2018-09-12 17:26:21 +00:00
using System.Linq;
using Emby.Naming.Common;
using Emby.Naming.Video;
using MediaBrowser.Model.IO;
namespace Emby.Naming.AudioBook
{
public class AudioBookListResolver
{
private readonly NamingOptions _options;
public AudioBookListResolver(NamingOptions options)
{
_options = options;
}
2019-05-10 18:37:42 +00:00
public IEnumerable<AudioBookInfo> Resolve(IEnumerable<FileSystemMetadata> files)
2018-09-12 17:26:21 +00:00
{
var audioBookResolver = new AudioBookResolver(_options);
var audiobookFileInfos = files
.Select(i => audioBookResolver.Resolve(i.FullName, i.IsDirectory))
.Where(i => i != null)
.ToList();
// Filter out all extras, otherwise they could cause stacks to not be resolved
// See the unit test TestStackedWithTrailer
var metadata = audiobookFileInfos
.Select(i => new FileSystemMetadata
{
FullName = i.Path,
IsDirectory = i.IsDirectory
});
var stackResult = new StackResolver(_options)
.ResolveAudioBooks(metadata);
var list = new List<AudioBookInfo>();
foreach (var stack in stackResult.Stacks)
{
var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i, stack.IsDirectoryStack)).ToList();
stackFiles.Sort();
var info = new AudioBookInfo
{
Files = stackFiles,
Name = stack.Name
};
list.Add(info);
}
// Whatever files are left, just add them
/*list.AddRange(remainingFiles.Select(i => new AudioBookInfo
{
Files = new List<AudioBookFileInfo> { i },
Name = i.,
Year = i.Year
}));*/
var orderedList = list.OrderBy(i => i.Name);
return orderedList;
}
}
}