Simplify AudioBookResolver since there is no option of passing directories into it (AudioResolver.cs:179) and handling directories were not implemented anyway

pull/4456/head
Stepan 4 years ago
parent 6437cf6950
commit e7a37bedfc

@ -14,14 +14,12 @@ namespace Emby.Naming.AudioBook
/// <param name="container">File type.</param>
/// <param name="partNumber">Number of part this file represents.</param>
/// <param name="chapterNumber">Number of chapter this file represents.</param>
/// <param name="isDirectory">Indication if we are looking at file or directory.</param>
public AudioBookFileInfo(string path, string container, int? partNumber = default, int? chapterNumber = default, bool isDirectory = default)
public AudioBookFileInfo(string path, string container, int? partNumber = default, int? chapterNumber = default)
{
Path = path;
Container = container;
PartNumber = partNumber;
ChapterNumber = chapterNumber;
IsDirectory = isDirectory;
}
/// <summary>
@ -48,12 +46,6 @@ namespace Emby.Naming.AudioBook
/// <value>The chapter number.</value>
public int? ChapterNumber { get; set; }
/// <summary>
/// Gets or sets a value indicating whether this instance is a directory.
/// </summary>
/// <value>The type.</value>
public bool IsDirectory { get; set; }
/// <inheritdoc />
public int CompareTo(AudioBookFileInfo? other)
{

@ -22,21 +22,21 @@ namespace Emby.Naming.AudioBook
var audioBookResolver = new AudioBookResolver(_options);
var audiobookFileInfos = files
.Select(i => audioBookResolver.Resolve(i.FullName, i.IsDirectory))
.Select(i => audioBookResolver.Resolve(i.FullName))
.OfType<AudioBookFileInfo>()
.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 });
.Select(i => new FileSystemMetadata { FullName = i.Path, IsDirectory = false });
var stackResult = new StackResolver(_options)
.ResolveAudioBooks(metadata);
.ResolveAudioBooks(audiobookFileInfos);
foreach (var stack in stackResult)
{
var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i, stack.IsDirectoryStack)).OfType<AudioBookFileInfo>().ToList();
var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i)).OfType<AudioBookFileInfo>().ToList();
stackFiles.Sort();
// TODO nullable discover if name can be empty
var info = new AudioBookInfo(stack.Name ?? string.Empty) { Files = stackFiles };

@ -17,19 +17,13 @@ namespace Emby.Naming.AudioBook
_options = options;
}
public AudioBookFileInfo? Resolve(string path, bool isDirectory = false)
public AudioBookFileInfo? Resolve(string path)
{
if (path.Length == 0)
{
throw new ArgumentException("String can't be empty.", nameof(path));
}
// TODO
if (isDirectory)
{
return null;
}
var extension = Path.GetExtension(path);
// Check supported extensions
@ -46,8 +40,7 @@ namespace Emby.Naming.AudioBook
path,
container,
chapterNumber: parsingResult.ChapterNumber,
partNumber: parsingResult.PartNumber,
isDirectory: isDirectory);
partNumber: parsingResult.PartNumber);
}
}
}

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using Emby.Naming.AudioBook;
using Emby.Naming.Common;
using MediaBrowser.Model.IO;
@ -29,24 +30,16 @@ namespace Emby.Naming.Video
return Resolve(files.Select(i => new FileSystemMetadata { FullName = i, IsDirectory = false }));
}
public IEnumerable<FileStack> ResolveAudioBooks(IEnumerable<FileSystemMetadata> files)
public IEnumerable<FileStack> ResolveAudioBooks(IEnumerable<AudioBookFileInfo> files)
{
var groupedDirectoryFiles = files.GroupBy(file =>
file.IsDirectory
? file.FullName
: Path.GetDirectoryName(file.FullName));
var groupedDirectoryFiles = files.GroupBy(file => Path.GetDirectoryName(file.Path));
foreach (var directory in groupedDirectoryFiles)
{
var stack = new FileStack { Name = Path.GetFileName(directory.Key), IsDirectoryStack = false };
foreach (var file in directory)
{
if (file.IsDirectory)
{
continue;
}
stack.Files.Add(file.FullName);
stack.Files.Add(file.Path);
}
yield return stack;

Loading…
Cancel
Save