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