aboutsummaryrefslogtreecommitdiff
path: root/Emby.Naming/AudioBook
diff options
context:
space:
mode:
authorStepan <ste.martinek+git@gmail.com>2020-11-01 10:47:31 +0100
committerStepan <ste.martinek+git@gmail.com>2020-11-01 10:47:31 +0100
commit59619b6ea74ab555977fd213f6ee5737897b0fbd (patch)
treedbe590f079d354632bc9192ee7fb24e59c541756 /Emby.Naming/AudioBook
parent4f320308f333507a324740248c7dd025085a7d67 (diff)
Enable nullable in Emby.Naming
Diffstat (limited to 'Emby.Naming/AudioBook')
-rw-r--r--Emby.Naming/AudioBook/AudioBookFileInfo.cs19
-rw-r--r--Emby.Naming/AudioBook/AudioBookInfo.cs4
-rw-r--r--Emby.Naming/AudioBook/AudioBookListResolver.cs8
-rw-r--r--Emby.Naming/AudioBook/AudioBookResolver.cs14
4 files changed, 32 insertions, 13 deletions
diff --git a/Emby.Naming/AudioBook/AudioBookFileInfo.cs b/Emby.Naming/AudioBook/AudioBookFileInfo.cs
index c4863b50a..e5200416e 100644
--- a/Emby.Naming/AudioBook/AudioBookFileInfo.cs
+++ b/Emby.Naming/AudioBook/AudioBookFileInfo.cs
@@ -8,6 +8,23 @@ namespace Emby.Naming.AudioBook
public class AudioBookFileInfo : IComparable<AudioBookFileInfo>
{
/// <summary>
+ /// Initializes a new instance of the <see cref="AudioBookFileInfo"/> class.
+ /// </summary>
+ /// <param name="path">Path to audiobook file.</param>
+ /// <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)
+ {
+ Path = path;
+ Container = container;
+ PartNumber = partNumber;
+ ChapterNumber = chapterNumber;
+ IsDirectory = isDirectory;
+ }
+
+ /// <summary>
/// Gets or sets the path.
/// </summary>
/// <value>The path.</value>
@@ -38,7 +55,7 @@ namespace Emby.Naming.AudioBook
public bool IsDirectory { get; set; }
/// <inheritdoc />
- public int CompareTo(AudioBookFileInfo other)
+ public int CompareTo(AudioBookFileInfo? other)
{
if (ReferenceEquals(this, other))
{
diff --git a/Emby.Naming/AudioBook/AudioBookInfo.cs b/Emby.Naming/AudioBook/AudioBookInfo.cs
index b0b5bd881..fba11ea72 100644
--- a/Emby.Naming/AudioBook/AudioBookInfo.cs
+++ b/Emby.Naming/AudioBook/AudioBookInfo.cs
@@ -10,11 +10,13 @@ namespace Emby.Naming.AudioBook
/// <summary>
/// Initializes a new instance of the <see cref="AudioBookInfo" /> class.
/// </summary>
- public AudioBookInfo()
+ /// <param name="name">Name of audiobook.</param>
+ public AudioBookInfo(string name)
{
Files = new List<AudioBookFileInfo>();
Extras = new List<AudioBookFileInfo>();
AlternateVersions = new List<AudioBookFileInfo>();
+ Name = name;
}
/// <summary>
diff --git a/Emby.Naming/AudioBook/AudioBookListResolver.cs b/Emby.Naming/AudioBook/AudioBookListResolver.cs
index f4ba11a0d..f350e5a4a 100644
--- a/Emby.Naming/AudioBook/AudioBookListResolver.cs
+++ b/Emby.Naming/AudioBook/AudioBookListResolver.cs
@@ -1,5 +1,6 @@
#pragma warning disable CS1591
+using System;
using System.Collections.Generic;
using System.Linq;
using Emby.Naming.Common;
@@ -23,7 +24,7 @@ namespace Emby.Naming.AudioBook
var audiobookFileInfos = files
.Select(i => audioBookResolver.Resolve(i.FullName, i.IsDirectory))
- .Where(i => i != null)
+ .OfType<AudioBookFileInfo>()
.ToList();
// Filter out all extras, otherwise they could cause stacks to not be resolved
@@ -36,9 +37,10 @@ namespace Emby.Naming.AudioBook
foreach (var stack in stackResult)
{
- var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i, stack.IsDirectoryStack)).ToList();
+ var stackFiles = stack.Files.Select(i => audioBookResolver.Resolve(i, stack.IsDirectoryStack)).OfType<AudioBookFileInfo>().ToList();
stackFiles.Sort();
- var info = new AudioBookInfo { Files = stackFiles, Name = stack.Name };
+ // TODO nullable discover if name can be empty
+ var info = new AudioBookInfo(stack.Name ?? string.Empty) { Files = stackFiles };
yield return info;
}
diff --git a/Emby.Naming/AudioBook/AudioBookResolver.cs b/Emby.Naming/AudioBook/AudioBookResolver.cs
index 5807d4688..e76cfd744 100644
--- a/Emby.Naming/AudioBook/AudioBookResolver.cs
+++ b/Emby.Naming/AudioBook/AudioBookResolver.cs
@@ -42,14 +42,12 @@ namespace Emby.Naming.AudioBook
var parsingResult = new AudioBookFilePathParser(_options).Parse(path);
- return new AudioBookFileInfo
- {
- Path = path,
- Container = container,
- ChapterNumber = parsingResult.ChapterNumber,
- PartNumber = parsingResult.PartNumber,
- IsDirectory = isDirectory
- };
+ return new AudioBookFileInfo(
+ path,
+ container,
+ chapterNumber: parsingResult.ChapterNumber,
+ partNumber: parsingResult.PartNumber,
+ isDirectory: isDirectory );
}
}
}