2020-10-12 14:09:15 -04:00
|
|
|
#nullable enable
|
2019-12-13 14:11:37 -05:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
|
2019-01-13 14:54:44 -05:00
|
|
|
using System;
|
2018-09-12 13:26:21 -04: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-10-12 14:09:15 -04:00
|
|
|
public AudioBookFileInfo? Resolve(string path, bool isDirectory = false)
|
2018-09-12 13:26:21 -04:00
|
|
|
{
|
2020-10-12 14:09:15 -04:00
|
|
|
if (path.Length == 0)
|
2018-09-12 13:26:21 -04:00
|
|
|
{
|
2020-10-12 14:09:15 -04:00
|
|
|
throw new ArgumentException("String can't be empty.", nameof(path));
|
2018-09-12 13:26:21 -04:00
|
|
|
}
|
2019-01-21 14:18:52 -05:00
|
|
|
|
2019-05-10 14:37:42 -04:00
|
|
|
// TODO
|
|
|
|
if (isDirectory)
|
2019-01-21 14:18:52 -05:00
|
|
|
{
|
2018-09-12 13:26:21 -04:00
|
|
|
return null;
|
2019-01-21 14:18:52 -05:00
|
|
|
}
|
2018-09-12 13:26:21 -04:00
|
|
|
|
2019-01-25 15:52:10 -05:00
|
|
|
var extension = Path.GetExtension(path);
|
2019-05-10 14:37:42 -04:00
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
// Check supported extensions
|
|
|
|
if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var container = extension.TrimStart('.');
|
|
|
|
|
2019-05-10 14:37:42 -04:00
|
|
|
var parsingResult = new AudioBookFilePathParser(_options).Parse(path);
|
2019-01-07 18:27:46 -05:00
|
|
|
|
2018-09-12 13:26:21 -04:00
|
|
|
return new AudioBookFileInfo
|
|
|
|
{
|
|
|
|
Path = path,
|
|
|
|
Container = container,
|
|
|
|
ChapterNumber = parsingResult.ChapterNumber,
|
2020-09-08 19:57:09 -04:00
|
|
|
PartNumber = parsingResult.PartNumber,
|
2019-05-10 14:37:42 -04:00
|
|
|
IsDirectory = isDirectory
|
2018-09-12 13:26:21 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|