Forráskód Böngészése

Update summaries, Use spans

1hitsong 2 éve
szülő
commit
35399ce8fe

+ 5 - 5
MediaBrowser.Controller/Lyrics/LyricLine.cs

@@ -12,17 +12,17 @@ public class LyricLine
     /// <param name="start">The lyric start time in ticks.</param>
     public LyricLine(string text, long? start = null)
     {
-        Start = start;
         Text = text;
+        Start = start;
     }
 
     /// <summary>
-    /// Gets the start time in ticks.
+    /// Gets the text of this lyric line.
     /// </summary>
-    public long? Start { get; }
+    public string Text { get; }
 
     /// <summary>
-    /// Gets the text.
+    /// Gets the start time in ticks.
     /// </summary>
-    public string Text { get; }
+    public long? Start { get; }
 }

+ 9 - 9
MediaBrowser.Controller/Lyrics/LyricMetadata.cs

@@ -8,47 +8,47 @@ namespace MediaBrowser.Controller.Lyrics;
 public class LyricMetadata
 {
     /// <summary>
-    /// Gets or sets Artist - The song artist.
+    /// Gets or sets the song artist.
     /// </summary>
     public string? Artist { get; set; }
 
     /// <summary>
-    /// Gets or sets Album - The album this song is on.
+    /// Gets or sets the album this song is on.
     /// </summary>
     public string? Album { get; set; }
 
     /// <summary>
-    /// Gets or sets Title - The title of the song.
+    /// Gets or sets the title of the song.
     /// </summary>
     public string? Title { get; set; }
 
     /// <summary>
-    /// Gets or sets Author - Creator of the lyric data.
+    /// Gets or sets the author of the lyric data.
     /// </summary>
     public string? Author { get; set; }
 
     /// <summary>
-    /// Gets or sets Length - How long the song is.
+    /// Gets or sets the length of the song in ticks.
     /// </summary>
     public long? Length { get; set; }
 
     /// <summary>
-    /// Gets or sets By - Creator of the LRC file.
+    /// Gets or sets who the LRC file was created by.
     /// </summary>
     public string? By { get; set; }
 
     /// <summary>
-    /// Gets or sets Offset - Offset:+/- Timestamp adjustment in milliseconds.
+    /// Gets or sets the lyric offset compared to audio in ticks.
     /// </summary>
     public long? Offset { get; set; }
 
     /// <summary>
-    /// Gets or sets Creator - The Software used to create the LRC file.
+    /// Gets or sets the software used to create the LRC file.
     /// </summary>
     public string? Creator { get; set; }
 
     /// <summary>
-    /// Gets or sets Version - The version of the Creator used.
+    /// Gets or sets the version of the creator used.
     /// </summary>
     public string? Version { get; set; }
 }

+ 2 - 2
MediaBrowser.Controller/Lyrics/LyricResponse.cs

@@ -9,12 +9,12 @@ namespace MediaBrowser.Controller.Lyrics;
 public class LyricResponse
 {
     /// <summary>
-    /// Gets or sets Metadata.
+    /// Gets or sets Metadata for the lyrics.
     /// </summary>
     public LyricMetadata Metadata { get; set; } = new();
 
     /// <summary>
-    /// Gets or sets Lyrics.
+    /// Gets or sets a collection of individual lyric lines.
     /// </summary>
     public IReadOnlyList<LyricLine> Lyrics { get; set; } = Array.Empty<LyricLine>();
 }

+ 8 - 8
MediaBrowser.Providers/Lyric/LrcLyricProvider.cs

@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Generic;
 using System.Globalization;
+using System.IO;
 using System.Linq;
 using LrcParser.Model;
 using LrcParser.Parser;
@@ -59,7 +60,7 @@ public class LrcLyricProvider : ILyricProvider
         }
 
         var fileMetaData = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
-        string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
+        string lrcFileContent = File.ReadAllText(lyricFilePath);
 
         Song lyricData;
 
@@ -84,25 +85,24 @@ public class LrcLyricProvider : ILyricProvider
 
         foreach (string metaDataRow in metaDataRows)
         {
-            if (!metaDataRow.Contains(':', StringComparison.OrdinalIgnoreCase))
+            var index = metaDataRow.IndexOf(':', StringComparison.OrdinalIgnoreCase);
+            if (index == -1)
             {
                 continue;
             }
 
-            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];
+            var metaDataFieldNameSpan = metaDataRow.AsSpan(1, index - 1).Trim();
+            var metaDataFieldValueSpan = metaDataRow.AsSpan(index + 1, metaDataRow.Length - index - 2).Trim();
 
-            if (string.IsNullOrEmpty(metaDataFieldName) || string.IsNullOrEmpty(metaDataFieldValue))
+            if (metaDataFieldValueSpan.IsEmpty || metaDataFieldValueSpan.IsEmpty)
             {
                 continue;
             }
 
-            fileMetaData[metaDataFieldName] = metaDataFieldValue;
+            fileMetaData[metaDataFieldNameSpan.ToString()] = metaDataFieldValueSpan.ToString();
         }
 
         if (sortedLyricData.Count == 0)

+ 6 - 4
MediaBrowser.Providers/Lyric/TxtLyricProvider.cs

@@ -1,4 +1,6 @@
 using System.Collections.Generic;
+using System.IO;
+using System.Linq;
 using MediaBrowser.Controller.Entities;
 using MediaBrowser.Controller.Lyrics;
 using MediaBrowser.Controller.Resolvers;
@@ -36,18 +38,18 @@ public class TxtLyricProvider : ILyricProvider
             return null;
         }
 
-        string[] lyricTextLines = System.IO.File.ReadAllLines(lyricFilePath);
+        string[] lyricTextLines = File.ReadAllLines(lyricFilePath);
 
         if (lyricTextLines.Length == 0)
         {
             return null;
         }
 
-        List<LyricLine> lyricList = new(lyricTextLines.Length);
+        LyricLine[] lyricList = new LyricLine[lyricTextLines.Length];
 
-        foreach (string lyricTextLine in lyricTextLines)
+        for (int lyricLine = 0; lyricLine < lyricTextLines.Length; lyricLine++)
         {
-            lyricList.Add(new LyricLine(lyricTextLine));
+            lyricList[lyricLine] = new LyricLine(lyricTextLines[lyricLine]);
         }
 
         return new LyricResponse { Lyrics = lyricList };