aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--MediaBrowser.Controller/Lyrics/ILyricProvider.cs7
-rw-r--r--MediaBrowser.Providers/Lyric/LrcLyricProvider.cs48
-rw-r--r--MediaBrowser.Providers/Lyric/LyricManager.cs2
-rw-r--r--MediaBrowser.Providers/Lyric/TxtLyricProvider.cs7
4 files changed, 47 insertions, 17 deletions
diff --git a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
index 1b52de255..651fe507f 100644
--- a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
+++ b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Resolvers;
namespace MediaBrowser.Controller.Lyrics;
@@ -14,6 +15,12 @@ public interface ILyricProvider
string Name { get; }
/// <summary>
+ /// Gets the priority.
+ /// </summary>
+ /// <value>The priority.</value>
+ ResolverPriority Priority { get; }
+
+ /// <summary>
/// Gets the supported media types for this provider.
/// </summary>
/// <value>The supported media types.</value>
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 90396e553..4690c3e20 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -1,12 +1,12 @@
using System;
using System.Collections.Generic;
-using System.Collections.ObjectModel;
using System.Linq;
using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
-using Newtonsoft.Json.Linq;
+using MediaBrowser.Controller.Resolvers;
+using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Lyric;
@@ -15,9 +15,26 @@ namespace MediaBrowser.Providers.Lyric;
/// </summary>
public class LrcLyricProvider : ILyricProvider
{
+ private readonly ILogger<LrcLyricProvider> _logger;
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="LrcLyricProvider"/> class.
+ /// </summary>
+ /// <param name="logger">Instance of the <see cref="ILogger"/> interface.</param>
+ public LrcLyricProvider(ILogger<LrcLyricProvider> logger)
+ {
+ _logger = logger;
+ }
+
/// <inheritdoc />
public string Name => "LrcLyricProvider";
+ /// <summary>
+ /// Gets the priority.
+ /// </summary>
+ /// <value>The priority.</value>
+ public ResolverPriority Priority => ResolverPriority.First;
+
/// <inheritdoc />
public IEnumerable<string> SupportedMediaTypes { get; } = new[] { "lrc" };
@@ -38,7 +55,7 @@ public class LrcLyricProvider : ILyricProvider
List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();
- IDictionary<string, string> fileMetaData = new Dictionary<string, string>();
+ IDictionary<string, string> fileMetaData = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
try
@@ -63,15 +80,15 @@ public class LrcLyricProvider : ILyricProvider
continue;
}
- string metaDataFieldName = metaDataField[0][1..].Trim().ToLowerInvariant();
+ string metaDataFieldName = metaDataField[0][1..].Trim();
string metaDataFieldValue = metaDataField[1][..^1].Trim();
fileMetaData.Add(metaDataFieldName, metaDataFieldValue);
}
}
- catch
+ catch (Exception ex)
{
- return null;
+ _logger.LogError(ex, "Error parsing lyric data from {Provider}", Name);
}
if (sortedLyricData.Count == 0)
@@ -111,52 +128,51 @@ public class LrcLyricProvider : ILyricProvider
{
LyricMetadata lyricMetadata = new LyricMetadata();
- if (metaData.TryGetValue("ar", out var artist) && artist is not null)
+ if (metaData.TryGetValue("ar", out var artist) && !string.IsNullOrEmpty(artist))
{
lyricMetadata.Artist = artist;
}
- if (metaData.TryGetValue("al", out var album) && album is not null)
+ if (metaData.TryGetValue("al", out var album) && !string.IsNullOrEmpty(album))
{
lyricMetadata.Album = album;
}
- if (metaData.TryGetValue("ti", out var title) && title is not null)
+ if (metaData.TryGetValue("ti", out var title) && !string.IsNullOrEmpty(title))
{
lyricMetadata.Title = title;
}
- if (metaData.TryGetValue("au", out var author) && author is not null)
+ if (metaData.TryGetValue("au", out var author) && !string.IsNullOrEmpty(author))
{
lyricMetadata.Author = author;
}
- if (metaData.TryGetValue("length", out var length) && length is not null)
+ if (metaData.TryGetValue("length", out var length) && !string.IsNullOrEmpty(length))
{
lyricMetadata.Length = length;
}
- if (metaData.TryGetValue("by", out var by) && by is not null)
+ if (metaData.TryGetValue("by", out var by) && !string.IsNullOrEmpty(by))
{
lyricMetadata.By = by;
}
- if (metaData.TryGetValue("offset", out var offset) && offset is not null)
+ if (metaData.TryGetValue("offset", out var offset) && !string.IsNullOrEmpty(offset))
{
lyricMetadata.Offset = offset;
}
- if (metaData.TryGetValue("re", out var creator) && creator is not null)
+ if (metaData.TryGetValue("re", out var creator) && !string.IsNullOrEmpty(creator))
{
lyricMetadata.Creator = creator;
}
- if (metaData.TryGetValue("ve", out var version) && version is not null)
+ if (metaData.TryGetValue("ve", out var version) && !string.IsNullOrEmpty(version))
{
lyricMetadata.Version = version;
}
return lyricMetadata;
-
}
}
diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs
index 0de008db7..7487c6861 100644
--- a/MediaBrowser.Providers/Lyric/LyricManager.cs
+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs
@@ -18,7 +18,7 @@ public class LyricManager : ILyricManager
/// <param name="lyricProviders">All found lyricProviders.</param>
public LyricManager(IEnumerable<ILyricProvider> lyricProviders)
{
- _lyricProviders = lyricProviders.ToArray();
+ _lyricProviders = lyricProviders.OrderBy(i => i.Priority).ToArray();
}
/// <inheritdoc />
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
index a2161c427..c69008686 100644
--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
+using MediaBrowser.Controller.Resolvers;
namespace MediaBrowser.Providers.Lyric;
@@ -15,6 +16,12 @@ public class TxtLyricProvider : ILyricProvider
/// <inheritdoc />
public string Name => "TxtLyricProvider";
+ /// <summary>
+ /// Gets the priority.
+ /// </summary>
+ /// <value>The priority.</value>
+ public ResolverPriority Priority => ResolverPriority.Second;
+
/// <inheritdoc />
public IEnumerable<string> SupportedMediaTypes { get; } = new[] { "lrc", "txt" };