aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Providers/Lyric
diff options
context:
space:
mode:
author1hitsong <3330318+1hitsong@users.noreply.github.com>2022-09-22 08:13:53 -0400
committer1hitsong <3330318+1hitsong@users.noreply.github.com>2022-09-22 08:13:53 -0400
commita50bdb47709be0412b3abb2729f8c657b5d0c779 (patch)
treed5d261858c3248246014a80db58e004f3140ed57 /MediaBrowser.Providers/Lyric
parent35399ce8fef0559f65bee4f519c582d192a04e52 (diff)
Use async functions
Diffstat (limited to 'MediaBrowser.Providers/Lyric')
-rw-r--r--MediaBrowser.Providers/Lyric/LrcLyricProvider.cs23
-rw-r--r--MediaBrowser.Providers/Lyric/LyricManager.cs5
-rw-r--r--MediaBrowser.Providers/Lyric/TxtLyricProvider.cs5
3 files changed, 23 insertions, 10 deletions
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 1dbe5958e..d06db3afc 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
+using System.Threading.Tasks;
using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
@@ -50,7 +51,7 @@ public class LrcLyricProvider : ILyricProvider
/// </summary>
/// <param name="item">The item to to process.</param>
/// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/> with or without metadata; otherwise, null.</returns>
- public LyricResponse? GetLyrics(BaseItem item)
+ public async Task<LyricResponse?> GetLyrics(BaseItem item)
{
string? lyricFilePath = this.GetLyricFilePath(item.Path);
@@ -60,7 +61,7 @@ public class LrcLyricProvider : ILyricProvider
}
var fileMetaData = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
- string lrcFileContent = File.ReadAllText(lyricFilePath);
+ string lrcFileContent = await Task.FromResult(File.ReadAllText(lyricFilePath)).ConfigureAwait(false);
Song lyricData;
@@ -94,15 +95,15 @@ public class LrcLyricProvider : ILyricProvider
// Remove square bracket before field name, and after field value
// Example 1: [au: 1hitsong]
// Example 2: [ar: Calabrese]
- var metaDataFieldNameSpan = metaDataRow.AsSpan(1, index - 1).Trim();
- var metaDataFieldValueSpan = metaDataRow.AsSpan(index + 1, metaDataRow.Length - index - 2).Trim();
+ var metaDataFieldName = GetMetadataFieldName(metaDataRow, index);
+ var metaDataFieldValue = GetMetadataValue(metaDataRow, index);
- if (metaDataFieldValueSpan.IsEmpty || metaDataFieldValueSpan.IsEmpty)
+ if (string.IsNullOrEmpty(metaDataFieldName) || string.IsNullOrEmpty(metaDataFieldValue))
{
continue;
}
- fileMetaData[metaDataFieldNameSpan.ToString()] = metaDataFieldValueSpan.ToString();
+ fileMetaData[metaDataFieldName.ToString()] = metaDataFieldValue.ToString();
}
if (sortedLyricData.Count == 0)
@@ -197,4 +198,14 @@ public class LrcLyricProvider : ILyricProvider
return lyricMetadata;
}
+
+ private static string GetMetadataFieldName(string metaDataRow, int index)
+ {
+ return metaDataRow.AsSpan(1, index - 1).Trim().ToString();
+ }
+
+ private static string GetMetadataValue(string metaDataRow, int index)
+ {
+ return metaDataRow.AsSpan(index + 1, metaDataRow.Length - index - 2).Trim().ToString();
+ }
}
diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs
index 336b324a7..f9547e0f0 100644
--- a/MediaBrowser.Providers/Lyric/LyricManager.cs
+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
+using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
@@ -22,11 +23,11 @@ public class LyricManager : ILyricManager
}
/// <inheritdoc />
- public LyricResponse? GetLyrics(BaseItem item)
+ public async Task<LyricResponse?> GetLyrics(BaseItem item)
{
foreach (ILyricProvider provider in _lyricProviders)
{
- var results = provider.GetLyrics(item);
+ var results = await provider.GetLyrics(item).ConfigureAwait(false);
if (results is not null)
{
return results;
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
index bce881054..9df4ec83e 100644
--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -1,6 +1,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Threading.Tasks;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
using MediaBrowser.Controller.Resolvers;
@@ -29,7 +30,7 @@ public class TxtLyricProvider : ILyricProvider
/// </summary>
/// <param name="item">The item to to process.</param>
/// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/>; otherwise, null.</returns>
- public LyricResponse? GetLyrics(BaseItem item)
+ public async Task<LyricResponse?> GetLyrics(BaseItem item)
{
string? lyricFilePath = this.GetLyricFilePath(item.Path);
@@ -38,7 +39,7 @@ public class TxtLyricProvider : ILyricProvider
return null;
}
- string[] lyricTextLines = File.ReadAllLines(lyricFilePath);
+ string[] lyricTextLines = await Task.FromResult(File.ReadAllLines(lyricFilePath)).ConfigureAwait(false);
if (lyricTextLines.Length == 0)
{