Move AcceptedTimeFormats to class level variable

pull/8381/head
1hitsong 2 years ago
parent d7fedf3512
commit 5d2364f064

@ -1,3 +1,4 @@
using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace MediaBrowser.Controller.Lyrics; namespace MediaBrowser.Controller.Lyrics;
@ -15,5 +16,5 @@ public class LyricResponse
/// <summary> /// <summary>
/// Gets or sets Lyrics. /// Gets or sets Lyrics.
/// </summary> /// </summary>
public IReadOnlyList<LyricLine> Lyrics { get; set; } = new List<LyricLine>(); public IReadOnlyList<LyricLine> Lyrics { get; set; } = Array.Empty<LyricLine>();
} }

@ -39,6 +39,8 @@ public class LrcLyricProvider : ILyricProvider
/// <inheritdoc /> /// <inheritdoc />
public IReadOnlyCollection<string> SupportedMediaTypes { get; } = new[] { "lrc", "elrc" }; public IReadOnlyCollection<string> SupportedMediaTypes { get; } = new[] { "lrc", "elrc" };
private static string[] AcceptedTimeFormats => new[] { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" };
/// <summary> /// <summary>
/// Opens lyric file for the requested item, and processes it for API return. /// Opens lyric file for the requested item, and processes it for API return.
/// </summary> /// </summary>
@ -88,8 +90,8 @@ public class LrcLyricProvider : ILyricProvider
} }
string[] metaDataField = metaDataRow.Split(':', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); string[] metaDataField = metaDataRow.Split(':', 2, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
string metaDataFieldName = metaDataField[0][1..].Trim(); string metaDataFieldName = metaDataField[0][1..];
string metaDataFieldValue = metaDataField[1][..^1].Trim(); string metaDataFieldValue = metaDataField[1][..^1];
fileMetaData.Add(metaDataFieldName, metaDataFieldValue); fileMetaData.Add(metaDataFieldName, metaDataFieldValue);
} }
@ -155,7 +157,7 @@ public class LrcLyricProvider : ILyricProvider
if (metaData.TryGetValue("length", out var length) && !string.IsNullOrEmpty(length)) if (metaData.TryGetValue("length", out var length) && !string.IsNullOrEmpty(length))
{ {
if (DateTime.TryParseExact(length, new string[] { "HH:mm:ss", "H:mm:ss", "mm:ss", "m:ss" }, null, DateTimeStyles.None, out var value)) if (DateTime.TryParseExact(length, AcceptedTimeFormats, null, DateTimeStyles.None, out var value))
{ {
lyricMetadata.Length = value.TimeOfDay.Ticks; lyricMetadata.Length = value.TimeOfDay.Ticks;
} }

Loading…
Cancel
Save