diff options
| author | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-20 08:36:43 -0400 |
|---|---|---|
| committer | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-20 08:36:54 -0400 |
| commit | 6f0d33b1caafdf5c8c0413bf3fdcddc822a08f51 (patch) | |
| tree | 91eb0e6a9017a1d8639b0cbd25c2963f9a52bd92 /MediaBrowser.Providers/Lyric | |
| parent | b442c79e620d2bdbb9007038371b75fe41b7cd8a (diff) | |
Use Directory GetFiles to find lyric files
Diffstat (limited to 'MediaBrowser.Providers/Lyric')
| -rw-r--r-- | MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 12 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Lyric/LyricManager.cs | 2 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Lyric/TxtLyricProvider.cs | 2 |
3 files changed, 10 insertions, 6 deletions
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs index 3177abb96..8ed0552cc 100644 --- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs +++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs @@ -20,7 +20,7 @@ public class LrcLyricProvider : ILyricProvider private readonly LyricParser _lrcLyricParser; - private static readonly IReadOnlyList<string> _acceptedTimeFormats = new string[] { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" }; + private static readonly string[] _acceptedTimeFormats = { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" }; /// <summary> /// Initializes a new instance of the <see cref="LrcLyricProvider"/> class. @@ -51,14 +51,14 @@ public class LrcLyricProvider : ILyricProvider /// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/> with or without metadata; otherwise, null.</returns> public LyricResponse? GetLyrics(BaseItem item) { - string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path); + string? lyricFilePath = this.GetLyricFilePath(item.Path); if (string.IsNullOrEmpty(lyricFilePath)) { return null; } - IDictionary<string, string> fileMetaData = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); + var fileMetaData = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase); string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath); Song lyricData; @@ -90,6 +90,10 @@ public class LrcLyricProvider : ILyricProvider } string[] metaDataField = metaDataRow.Split(':', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + + // Remove square bracket before field name, and after field value + // Example 1: [au: 1hitsong] + // Example 2: [ar: Calabrese] string metaDataFieldName = metaDataField[0][1..]; string metaDataFieldValue = metaDataField[1][..^1]; @@ -162,7 +166,7 @@ public class LrcLyricProvider : ILyricProvider if (metaData.TryGetValue("length", out var length) && !string.IsNullOrEmpty(length)) { - if (DateTime.TryParseExact(length, _acceptedTimeFormats.ToArray(), null, DateTimeStyles.None, out var value)) + if (DateTime.TryParseExact(length, _acceptedTimeFormats, null, DateTimeStyles.None, out var value)) { lyricMetadata.Length = value.TimeOfDay.Ticks; } diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs index 7487c6861..336b324a7 100644 --- a/MediaBrowser.Providers/Lyric/LyricManager.cs +++ b/MediaBrowser.Providers/Lyric/LyricManager.cs @@ -46,7 +46,7 @@ public class LyricManager : ILyricManager continue; } - if (LyricInfo.GetLyricFilePath(provider, item.Path) is not null) + if (provider.GetLyricFilePath(item.Path) is not null) { return true; } diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs index 6a189e132..df6d52630 100644 --- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs +++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs @@ -29,7 +29,7 @@ public class TxtLyricProvider : ILyricProvider /// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/>; otherwise, null.</returns> public LyricResponse? GetLyrics(BaseItem item) { - string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path); + string? lyricFilePath = this.GetLyricFilePath(item.Path); if (string.IsNullOrEmpty(lyricFilePath)) { |
