Simplify file extension checks in lyrics parsers and provider

This commit is contained in:
Niels van Velzen 2023-06-29 21:16:29 +02:00
parent 1ed5f0a624
commit 6be45f73bc
3 changed files with 6 additions and 6 deletions

View File

@ -10,7 +10,7 @@ namespace MediaBrowser.Providers.Lyric;
/// <inheritdoc />
public class DefaultLyricProvider : ILyricProvider
{
private static readonly string[] _lyricExtensions = { "lrc", "elrc", "txt", "elrc" };
private static readonly string[] _lyricExtensions = { ".lrc", ".elrc", ".txt" };
/// <inheritdoc />
public string Name => "DefaultLyricProvider";
@ -55,7 +55,7 @@ public class DefaultLyricProvider : ILyricProvider
foreach (var lyricFilePath in Directory.GetFiles(itemDirectoryPath, $"{Path.GetFileNameWithoutExtension(item.Path)}.*"))
{
if (_lyricExtensions.Contains(Path.GetExtension(lyricFilePath.AsSpan())[1..], StringComparison.OrdinalIgnoreCase))
if (_lyricExtensions.Contains(Path.GetExtension(lyricFilePath.AsSpan()), StringComparison.OrdinalIgnoreCase))
{
return lyricFilePath;
}

View File

@ -18,7 +18,7 @@ public class LrcLyricParser : ILyricParser
{
private readonly LyricParser _lrcLyricParser;
private static readonly string[] _supportedMediaTypes = { "lrc", "elrc" };
private static readonly string[] _supportedMediaTypes = { ".lrc", ".elrc" };
private static readonly string[] _acceptedTimeFormats = { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" };
/// <summary>
@ -41,7 +41,7 @@ public class LrcLyricParser : ILyricParser
/// <inheritdoc />
public LyricResponse? ParseLyrics(LyricFile lyrics)
{
if (!_supportedMediaTypes.Contains(Path.GetExtension(lyrics.Name.AsSpan())[1..], StringComparison.OrdinalIgnoreCase))
if (!_supportedMediaTypes.Contains(Path.GetExtension(lyrics.Name.AsSpan()), StringComparison.OrdinalIgnoreCase))
{
return null;
}

View File

@ -11,7 +11,7 @@ namespace MediaBrowser.Providers.Lyric;
/// </summary>
public class TxtLyricParser : ILyricParser
{
private static readonly string[] _supportedMediaTypes = { "lrc", "elrc", "txt" };
private static readonly string[] _supportedMediaTypes = { ".lrc", ".elrc", ".txt" };
private static readonly string[] _lineBreakCharacters = { "\r\n", "\r", "\n" };
/// <inheritdoc />
@ -26,7 +26,7 @@ public class TxtLyricParser : ILyricParser
/// <inheritdoc />
public LyricResponse? ParseLyrics(LyricFile lyrics)
{
if (!_supportedMediaTypes.Contains(Path.GetExtension(lyrics.Name.AsSpan())[1..], StringComparison.OrdinalIgnoreCase))
if (!_supportedMediaTypes.Contains(Path.GetExtension(lyrics.Name.AsSpan()), StringComparison.OrdinalIgnoreCase))
{
return null;
}