| | 1 | | using System; |
| | 2 | | using System.IO; |
| | 3 | | using Emby.Naming.Common; |
| | 4 | | using Jellyfin.Extensions; |
| | 5 | |
|
| | 6 | | namespace Emby.Naming.Video |
| | 7 | | { |
| | 8 | | /// <summary> |
| | 9 | | /// Resolve if file is stub (.disc). |
| | 10 | | /// </summary> |
| | 11 | | public static class StubResolver |
| | 12 | | { |
| | 13 | | /// <summary> |
| | 14 | | /// Tries to resolve if file is stub (.disc). |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="path">Path to file.</param> |
| | 17 | | /// <param name="options">NamingOptions containing StubFileExtensions and StubTypes.</param> |
| | 18 | | /// <param name="stubType">Stub type.</param> |
| | 19 | | /// <returns>True if file is a stub.</returns> |
| | 20 | | public static bool TryResolveFile(string path, NamingOptions options, out string? stubType) |
| | 21 | | { |
| 21 | 22 | | stubType = default; |
| | 23 | |
|
| 21 | 24 | | if (string.IsNullOrEmpty(path)) |
| | 25 | | { |
| 1 | 26 | | return false; |
| | 27 | | } |
| | 28 | |
|
| 20 | 29 | | var extension = Path.GetExtension(path.AsSpan()); |
| | 30 | |
|
| 20 | 31 | | if (!options.StubFileExtensions.Contains(extension, StringComparison.OrdinalIgnoreCase)) |
| | 32 | | { |
| 3 | 33 | | return false; |
| | 34 | | } |
| | 35 | |
|
| 17 | 36 | | var token = Path.GetExtension(Path.GetFileNameWithoutExtension(path.AsSpan())).TrimStart('.'); |
| | 37 | |
|
| 195 | 38 | | foreach (var rule in options.StubTypes) |
| | 39 | | { |
| 88 | 40 | | if (token.Equals(rule.Token, StringComparison.OrdinalIgnoreCase)) |
| | 41 | | { |
| 15 | 42 | | stubType = rule.StubType; |
| 15 | 43 | | return true; |
| | 44 | | } |
| | 45 | | } |
| | 46 | |
|
| 2 | 47 | | return true; |
| | 48 | | } |
| | 49 | | } |
| | 50 | | } |