2019-01-13 12:54:44 -07:00
|
|
|
using System;
|
2018-09-12 10:26:21 -07: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;
|
|
|
|
}
|
|
|
|
|
|
|
|
public AudioBookFileInfo ParseFile(string path)
|
|
|
|
{
|
|
|
|
return Resolve(path, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public AudioBookFileInfo ParseDirectory(string path)
|
|
|
|
{
|
|
|
|
return Resolve(path, true);
|
|
|
|
}
|
|
|
|
|
2019-05-10 11:37:42 -07:00
|
|
|
public AudioBookFileInfo Resolve(string path, bool isDirectory = false)
|
2018-09-12 10:26:21 -07:00
|
|
|
{
|
|
|
|
if (string.IsNullOrEmpty(path))
|
|
|
|
{
|
2019-01-06 13:50:43 -07:00
|
|
|
throw new ArgumentNullException(nameof(path));
|
2018-09-12 10:26:21 -07:00
|
|
|
}
|
2019-01-21 12:18:52 -07:00
|
|
|
|
2019-05-10 11:37:42 -07:00
|
|
|
// TODO
|
|
|
|
if (isDirectory)
|
2019-01-21 12:18:52 -07:00
|
|
|
{
|
2018-09-12 10:26:21 -07:00
|
|
|
return null;
|
2019-01-21 12:18:52 -07:00
|
|
|
}
|
2018-09-12 10:26:21 -07:00
|
|
|
|
2019-01-25 13:52:10 -07:00
|
|
|
var extension = Path.GetExtension(path);
|
2019-05-10 11:37:42 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
// Check supported extensions
|
|
|
|
if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var container = extension.TrimStart('.');
|
|
|
|
|
2019-05-10 11:37:42 -07:00
|
|
|
var parsingResult = new AudioBookFilePathParser(_options).Parse(path);
|
2019-01-07 16:27:46 -07:00
|
|
|
|
2018-09-12 10:26:21 -07:00
|
|
|
return new AudioBookFileInfo
|
|
|
|
{
|
|
|
|
Path = path,
|
|
|
|
Container = container,
|
|
|
|
PartNumber = parsingResult.PartNumber,
|
|
|
|
ChapterNumber = parsingResult.ChapterNumber,
|
2019-05-10 11:37:42 -07:00
|
|
|
IsDirectory = isDirectory
|
2018-09-12 10:26:21 -07:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|