2019-12-13 12:11:37 -07:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 12:54:44 -07:00
|
|
|
using System.Collections.Generic;
|
2018-09-12 10:26:21 -07: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 11:37:42 -07:00
|
|
|
public IEnumerable<AudioBookInfo> Resolve(IEnumerable<FileSystemMetadata> files)
|
2018-09-12 10:26:21 -07: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
|
2020-03-25 09:53:03 -07:00
|
|
|
.Select(i => new FileSystemMetadata { FullName = i.Path, IsDirectory = i.IsDirectory });
|
2018-09-12 10:26:21 -07:00
|
|
|
|
|
|
|
var stackResult = new StackResolver(_options)
|
|
|
|
.ResolveAudioBooks(metadata);
|
|
|
|
|
2020-01-22 14:18:56 -07:00
|
|
|
foreach (var stack in stackResult)
|
2018-09-12 10:26:21 -07:00
|
|
|
{
|
|
|
|
var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i, stack.IsDirectoryStack)).ToList();
|
|
|
|
stackFiles.Sort();
|
2020-03-25 09:53:03 -07:00
|
|
|
var info = new AudioBookInfo { Files = stackFiles, Name = stack.Name };
|
2018-09-12 10:26:21 -07:00
|
|
|
|
2020-01-22 14:18:56 -07:00
|
|
|
yield return info;
|
|
|
|
}
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|