jellyfin/Emby.Naming/AudioBook/AudioBookListResolver.cs

53 lines
1.5 KiB
C#
Raw Normal View History

#pragma warning disable CS1591
using System;
using System.Collections.Generic;
using System.IO;
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);
// File with empty fullname will be sorted out here
2018-09-12 17:26:21 +00:00
var audiobookFileInfos = files
.Select(i => audioBookResolver.Resolve(i.FullName))
2020-11-01 09:47:31 +00:00
.OfType<AudioBookFileInfo>()
2018-09-12 17:26:21 +00:00
.ToList();
var stackResult = new StackResolver(_options)
.ResolveAudioBooks(audiobookFileInfos);
2018-09-12 17:26:21 +00:00
2020-01-22 21:18:56 +00:00
foreach (var stack in stackResult)
2018-09-12 17:26:21 +00:00
{
var stackFiles = stack.Files
.Select(i => audioBookResolver.Resolve(i))
.OfType<AudioBookFileInfo>()
.ToList();
2018-09-12 17:26:21 +00:00
stackFiles.Sort();
var result = new AudioBookNameParser(_options).Parse(stack.Name);
var info = new AudioBookInfo(result.Name, result.Year) { Files = stackFiles };
2018-09-12 17:26:21 +00:00
2020-01-22 21:18:56 +00:00
yield return info;
}
2018-09-12 17:26:21 +00:00
}
}
}