|  |  | 1 |  | using System; | 
|  |  | 2 |  | using System.IO; | 
|  |  | 3 |  | using Emby.Naming.Common; | 
|  |  | 4 |  | using Jellyfin.Extensions; | 
|  |  | 5 |  |  | 
|  |  | 6 |  | namespace Emby.Naming.AudioBook | 
|  |  | 7 |  | { | 
|  |  | 8 |  |     /// <summary> | 
|  |  | 9 |  |     /// Resolve specifics (path, container, partNumber, chapterNumber) about audiobook file. | 
|  |  | 10 |  |     /// </summary> | 
|  |  | 11 |  |     public class AudioBookResolver | 
|  |  | 12 |  |     { | 
|  |  | 13 |  |         private readonly NamingOptions _options; | 
|  |  | 14 |  |  | 
|  |  | 15 |  |         /// <summary> | 
|  |  | 16 |  |         /// Initializes a new instance of the <see cref="AudioBookResolver"/> class. | 
|  |  | 17 |  |         /// </summary> | 
|  |  | 18 |  |         /// <param name="options"><see cref="NamingOptions"/> containing AudioFileExtensions and also used to pass to Au | 
|  |  | 19 |  |         public AudioBookResolver(NamingOptions options) | 
|  |  | 20 |  |         { | 
|  | 30 | 21 |  |             _options = options; | 
|  | 30 | 22 |  |         } | 
|  |  | 23 |  |  | 
|  |  | 24 |  |         /// <summary> | 
|  |  | 25 |  |         /// Resolve specifics (path, container, partNumber, chapterNumber) about audiobook file. | 
|  |  | 26 |  |         /// </summary> | 
|  |  | 27 |  |         /// <param name="path">Path to audiobook file.</param> | 
|  |  | 28 |  |         /// <returns>Returns <see cref="AudioBookResolver"/> object.</returns> | 
|  |  | 29 |  |         public AudioBookFileInfo? Resolve(string path) | 
|  |  | 30 |  |         { | 
|  | 124 | 31 |  |             if (path.Length == 0 || Path.GetFileNameWithoutExtension(path).Length == 0) | 
|  |  | 32 |  |             { | 
|  |  | 33 |  |                 // Return null to indicate this path will not be used, instead of stopping whole process with exception | 
|  | 2 | 34 |  |                 return null; | 
|  |  | 35 |  |             } | 
|  |  | 36 |  |  | 
|  | 122 | 37 |  |             var extension = Path.GetExtension(path); | 
|  |  | 38 |  |  | 
|  |  | 39 |  |             // Check supported extensions | 
|  | 122 | 40 |  |             if (!_options.AudioFileExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase)) | 
|  |  | 41 |  |             { | 
|  | 5 | 42 |  |                 return null; | 
|  |  | 43 |  |             } | 
|  |  | 44 |  |  | 
|  | 117 | 45 |  |             var container = extension.TrimStart('.'); | 
|  |  | 46 |  |  | 
|  | 117 | 47 |  |             var parsingResult = new AudioBookFilePathParser(_options).Parse(path); | 
|  |  | 48 |  |  | 
|  | 117 | 49 |  |             return new AudioBookFileInfo( | 
|  | 117 | 50 |  |                 path, | 
|  | 117 | 51 |  |                 container, | 
|  | 117 | 52 |  |                 chapterNumber: parsingResult.ChapterNumber, | 
|  | 117 | 53 |  |                 partNumber: parsingResult.PartNumber); | 
|  |  | 54 |  |         } | 
|  |  | 55 |  |     } | 
|  |  | 56 |  | } |