2020-10-12 18:09:15 +00:00
|
|
|
#nullable enable
|
2019-12-13 19:11:37 +00:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 19:54:44 +00:00
|
|
|
using System;
|
2018-09-12 17:26:21 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using Emby.Naming.Common;
|
|
|
|
|
|
|
|
namespace Emby.Naming.AudioBook
|
|
|
|
{
|
|
|
|
public class AudioBookResolver
|
|
|
|
{
|
|
|
|
private readonly NamingOptions _options;
|
|
|
|
|
|
|
|
public AudioBookResolver(NamingOptions options)
|
|
|
|
{
|
|
|
|
_options = options;
|
|
|
|
}
|
|
|
|
|
2020-11-01 12:42:56 +00:00
|
|
|
public AudioBookFileInfo? Resolve(string path)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
2020-10-12 18:09:15 +00:00
|
|
|
if (path.Length == 0)
|
2018-09-12 17:26:21 +00:00
|
|
|
{
|
2020-11-01 16:10:48 +00:00
|
|
|
// Return null to indicate this path will not be used, instead of stopping whole process with exception
|
|
|
|
return null;
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
2019-01-21 19:18:52 +00:00
|
|
|
|
2019-01-25 20:52:10 +00:00
|
|
|
var extension = Path.GetExtension(path);
|
2019-05-10 18:37:42 +00:00
|
|
|
|
2018-09-12 17:26:21 +00:00
|
|
|
// Check supported extensions
|
|
|
|
if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var container = extension.TrimStart('.');
|
|
|
|
|
2019-05-10 18:37:42 +00:00
|
|
|
var parsingResult = new AudioBookFilePathParser(_options).Parse(path);
|
2019-01-07 23:27:46 +00:00
|
|
|
|
2020-11-01 09:47:31 +00:00
|
|
|
return new AudioBookFileInfo(
|
|
|
|
path,
|
|
|
|
container,
|
|
|
|
chapterNumber: parsingResult.ChapterNumber,
|
2020-11-01 12:42:56 +00:00
|
|
|
partNumber: parsingResult.PartNumber);
|
2018-09-12 17:26:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|