Simplify AudioBookResolver since there is no option of passing directories into it (AudioResolver.cs:179) and handling directories were not implemented anyway
This commit is contained in:
parent
6437cf6950
commit
e7a37bedfc
|
@ -14,14 +14,12 @@ namespace Emby.Naming.AudioBook
|
||||||
/// <param name="container">File type.</param>
|
/// <param name="container">File type.</param>
|
||||||
/// <param name="partNumber">Number of part this file represents.</param>
|
/// <param name="partNumber">Number of part this file represents.</param>
|
||||||
/// <param name="chapterNumber">Number of chapter 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)
|
||||||
public AudioBookFileInfo(string path, string container, int? partNumber = default, int? chapterNumber = default, bool isDirectory = default)
|
|
||||||
{
|
{
|
||||||
Path = path;
|
Path = path;
|
||||||
Container = container;
|
Container = container;
|
||||||
PartNumber = partNumber;
|
PartNumber = partNumber;
|
||||||
ChapterNumber = chapterNumber;
|
ChapterNumber = chapterNumber;
|
||||||
IsDirectory = isDirectory;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -48,12 +46,6 @@ namespace Emby.Naming.AudioBook
|
||||||
/// <value>The chapter number.</value>
|
/// <value>The chapter number.</value>
|
||||||
public int? ChapterNumber { get; set; }
|
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 />
|
/// <inheritdoc />
|
||||||
public int CompareTo(AudioBookFileInfo? other)
|
public int CompareTo(AudioBookFileInfo? other)
|
||||||
{
|
{
|
||||||
|
|
|
@ -22,21 +22,21 @@ namespace Emby.Naming.AudioBook
|
||||||
var audioBookResolver = new AudioBookResolver(_options);
|
var audioBookResolver = new AudioBookResolver(_options);
|
||||||
|
|
||||||
var audiobookFileInfos = files
|
var audiobookFileInfos = files
|
||||||
.Select(i => audioBookResolver.Resolve(i.FullName, i.IsDirectory))
|
.Select(i => audioBookResolver.Resolve(i.FullName))
|
||||||
.OfType<AudioBookFileInfo>()
|
.OfType<AudioBookFileInfo>()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
// Filter out all extras, otherwise they could cause stacks to not be resolved
|
// Filter out all extras, otherwise they could cause stacks to not be resolved
|
||||||
// See the unit test TestStackedWithTrailer
|
// See the unit test TestStackedWithTrailer
|
||||||
var metadata = audiobookFileInfos
|
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)
|
var stackResult = new StackResolver(_options)
|
||||||
.ResolveAudioBooks(metadata);
|
.ResolveAudioBooks(audiobookFileInfos);
|
||||||
|
|
||||||
foreach (var stack in stackResult)
|
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();
|
stackFiles.Sort();
|
||||||
// TODO nullable discover if name can be empty
|
// TODO nullable discover if name can be empty
|
||||||
var info = new AudioBookInfo(stack.Name ?? string.Empty) { Files = stackFiles };
|
var info = new AudioBookInfo(stack.Name ?? string.Empty) { Files = stackFiles };
|
||||||
|
|
|
@ -17,19 +17,13 @@ namespace Emby.Naming.AudioBook
|
||||||
_options = options;
|
_options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AudioBookFileInfo? Resolve(string path, bool isDirectory = false)
|
public AudioBookFileInfo? Resolve(string path)
|
||||||
{
|
{
|
||||||
if (path.Length == 0)
|
if (path.Length == 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("String can't be empty.", nameof(path));
|
throw new ArgumentException("String can't be empty.", nameof(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
if (isDirectory)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var extension = Path.GetExtension(path);
|
var extension = Path.GetExtension(path);
|
||||||
|
|
||||||
// Check supported extensions
|
// Check supported extensions
|
||||||
|
@ -46,8 +40,7 @@ namespace Emby.Naming.AudioBook
|
||||||
path,
|
path,
|
||||||
container,
|
container,
|
||||||
chapterNumber: parsingResult.ChapterNumber,
|
chapterNumber: parsingResult.ChapterNumber,
|
||||||
partNumber: parsingResult.PartNumber,
|
partNumber: parsingResult.PartNumber);
|
||||||
isDirectory: isDirectory);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using Emby.Naming.AudioBook;
|
||||||
using Emby.Naming.Common;
|
using Emby.Naming.Common;
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
|
|
||||||
|
@ -29,24 +30,16 @@ namespace Emby.Naming.Video
|
||||||
return Resolve(files.Select(i => new FileSystemMetadata { FullName = i, IsDirectory = false }));
|
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 =>
|
var groupedDirectoryFiles = files.GroupBy(file => Path.GetDirectoryName(file.Path));
|
||||||
file.IsDirectory
|
|
||||||
? file.FullName
|
|
||||||
: Path.GetDirectoryName(file.FullName));
|
|
||||||
|
|
||||||
foreach (var directory in groupedDirectoryFiles)
|
foreach (var directory in groupedDirectoryFiles)
|
||||||
{
|
{
|
||||||
var stack = new FileStack { Name = Path.GetFileName(directory.Key), IsDirectoryStack = false };
|
var stack = new FileStack { Name = Path.GetFileName(directory.Key), IsDirectoryStack = false };
|
||||||
foreach (var file in directory)
|
foreach (var file in directory)
|
||||||
{
|
{
|
||||||
if (file.IsDirectory)
|
stack.Files.Add(file.Path);
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
stack.Files.Add(file.FullName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return stack;
|
yield return stack;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user