From 28d017865b7f51babc7c13dbfaf71a660d834d46 Mon Sep 17 00:00:00 2001
From: 1hitsong <3330318+1hitsong@users.noreply.github.com>
Date: Sun, 18 Sep 2022 21:17:53 -0400
Subject: [PATCH] Code Cleanup
---
MediaBrowser.Controller/Lyrics/LyricLine.cs | 2 +-
.../Lyrics/LyricResponse.cs | 4 +-
.../Lyric/LrcLyricProvider.cs | 39 +++++--------------
.../Lyric/TxtLyricProvider.cs | 4 +-
4 files changed, 14 insertions(+), 35 deletions(-)
diff --git a/MediaBrowser.Controller/Lyrics/LyricLine.cs b/MediaBrowser.Controller/Lyrics/LyricLine.cs
index 43997f6564..eb5ff9972e 100644
--- a/MediaBrowser.Controller/Lyrics/LyricLine.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricLine.cs
@@ -8,8 +8,8 @@ public class LyricLine
///
/// Initializes a new instance of the class.
///
- /// The lyric start time in ticks.
/// The lyric text.
+ /// The lyric start time in ticks.
public LyricLine(string text, long? start = null)
{
Start = start;
diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
index ded3ca10e2..64c3b3c28b 100644
--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs
+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs
@@ -10,10 +10,10 @@ public class LyricResponse
///
/// Gets or sets Metadata.
///
- public LyricMetadata Metadata { get; set; } = new LyricMetadata();
+ public LyricMetadata Metadata { get; set; } = new();
///
/// Gets or sets Lyrics.
///
- public IReadOnlyCollection Lyrics { get; set; } = new List();
+ public IReadOnlyList Lyrics { get; set; } = new List();
}
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
index 50fa519b3e..9d622a1cdf 100644
--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs
@@ -38,7 +38,7 @@ public class LrcLyricProvider : ILyricProvider
public ResolverPriority Priority => ResolverPriority.First;
///
- public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc" };
+ public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc", "elrc" };
///
/// Opens lyric file for the requested item, and processes it for API return.
@@ -54,8 +54,8 @@ public class LrcLyricProvider : ILyricProvider
return null;
}
- List lyricList = new List();
- List sortedLyricData = new List();
+ List lyricList = new();
+ List sortedLyricData = new();
IDictionary fileMetaData = new Dictionary(StringComparer.OrdinalIgnoreCase);
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
@@ -85,19 +85,11 @@ public class LrcLyricProvider : ILyricProvider
string[] metaDataField;
string metaDataFieldName;
string metaDataFieldValue;
+ string[] test;
- if (colonCount == 1)
- {
- metaDataField = metaDataRow.Split(':');
- metaDataFieldName = metaDataField[0][1..].Trim();
- metaDataFieldValue = metaDataField[1][..^1].Trim();
- }
- else
- {
- int colonIndex = metaDataRow.IndexOf(':', StringComparison.OrdinalIgnoreCase);
- metaDataFieldName = metaDataRow[..colonIndex][1..].Trim();
- metaDataFieldValue = metaDataRow[(colonIndex + 1)..][..^1].Trim();
- }
+ metaDataField = metaDataRow.Split(':', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
+ metaDataFieldName = metaDataField[0][1..].Trim();
+ metaDataFieldValue = metaDataField[1][..^1].Trim();
fileMetaData.Add(metaDataFieldName, metaDataFieldValue);
}
@@ -142,7 +134,7 @@ public class LrcLyricProvider : ILyricProvider
/// A lyricMetadata object with mapped property data.
private LyricMetadata MapMetadataValues(IDictionary metaData)
{
- LyricMetadata lyricMetadata = new LyricMetadata();
+ LyricMetadata lyricMetadata = new();
if (metaData.TryGetValue("ar", out var artist) && !string.IsNullOrEmpty(artist))
{
@@ -166,20 +158,7 @@ public class LrcLyricProvider : ILyricProvider
if (metaData.TryGetValue("length", out var length) && !string.IsNullOrEmpty(length))
{
- // Ensure minutes include leading zero
- var lengthData = length.Split(':');
- if (lengthData[0].Length == 1)
- {
- length = "0" + length;
- }
-
- // If only Minutes and Seconds were provided, prepend zeros for hours
- if (lengthData.Length == 2)
- {
- length = "00:" + length;
- }
-
- if (DateTime.TryParseExact(length, "HH:mm:ss", null, DateTimeStyles.None, out var value))
+ if (DateTime.TryParseExact(length, new string[] { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" }, null, DateTimeStyles.None, out var value))
{
lyricMetadata.Length = value.TimeOfDay.Ticks;
}
diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
index cd0e1599e7..542df13873 100644
--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs
@@ -20,7 +20,7 @@ public class TxtLyricProvider : ILyricProvider
public ResolverPriority Priority => ResolverPriority.Second;
///
- public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc", "txt" };
+ public IReadOnlyCollection SupportedMediaTypes { get; } = new[] { "lrc", "elrc", "txt" };
///
/// Opens lyric file for the requested item, and processes it for API return.
@@ -38,7 +38,7 @@ public class TxtLyricProvider : ILyricProvider
string[] lyricTextLines = System.IO.File.ReadAllLines(lyricFilePath);
- List lyricList = new List();
+ List lyricList = new();
if (lyricTextLines.Length == 0)
{