The Free Software Media System - Server Backend & API
Update summaries, Use spans
1hitsong35399ce8fef0
diff --git a/MediaBrowser.Controller/Lyrics/LyricLine.cs b/MediaBrowser.Controller/Lyrics/LyricLine.csindex eb5ff9972e..c406f92fcc 100644--- a/MediaBrowser.Controller/Lyrics/LyricLine.cs+++ b/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; }}diff --git a/MediaBrowser.Controller/Lyrics/LyricMetadata.cs b/MediaBrowser.Controller/Lyrics/LyricMetadata.csindex 0ba7779750..6091ede52a 100644--- a/MediaBrowser.Controller/Lyrics/LyricMetadata.cs+++ b/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; }}diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.csindex 56a5696450..0d52b5ec50 100644--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs+++ b/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>();}diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.csindex 8ed0552cc2..1dbe5958e8 100644--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs+++ b/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 : ILyricProviderforeach (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)diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.csindex df6d526301..bce8810545 100644--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs+++ b/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 : ILyricProviderreturn 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 };