jellyfin/Emby.Naming/AudioBook/AudioBookResolver.cs

47 lines
1.2 KiB
C#
Raw Normal View History

#nullable enable
#pragma warning disable CS1591
using System;
2018-09-12 19:26:21 +02: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? Resolve(string path)
2018-09-12 19:26:21 +02:00
{
if (path.Length == 0)
2018-09-12 19:26:21 +02:00
{
throw new ArgumentException("String can't be empty.", nameof(path));
2018-09-12 19:26:21 +02:00
}
2019-01-25 21:52:10 +01:00
var extension = Path.GetExtension(path);
2019-05-10 20:37:42 +02:00
2018-09-12 19:26:21 +02:00
// Check supported extensions
if (!_options.AudioFileExtensions.Contains(extension, StringComparer.OrdinalIgnoreCase))
{
return null;
}
var container = extension.TrimStart('.');
2019-05-10 20:37:42 +02:00
var parsingResult = new AudioBookFilePathParser(_options).Parse(path);
2019-01-08 00:27:46 +01:00
2020-11-01 10:47:31 +01:00
return new AudioBookFileInfo(
path,
container,
chapterNumber: parsingResult.ChapterNumber,
partNumber: parsingResult.PartNumber);
2018-09-12 19:26:21 +02:00
}
}
}