Code cleanups. Remove pragma commands

This commit is contained in:
1hitsong 2022-09-17 17:37:38 -04:00
parent 29932466a9
commit c65819221d
9 changed files with 247 additions and 271 deletions

View file

@ -1,9 +1,10 @@
#pragma warning disable CS1591
using MediaBrowser.Controller.Entities;
namespace MediaBrowser.Controller.Lyrics
{
namespace MediaBrowser.Controller.Lyrics;
/// <summary>
/// Interface ILyricManager.
/// </summary>
public interface ILyricManager
{
/// <summary>
@ -20,4 +21,3 @@ namespace MediaBrowser.Controller.Lyrics
/// <returns>True if item has a matching lyric file; otherwise false.</returns>
bool HasLyricFile(BaseItem item);
}
}

View file

@ -1,8 +1,8 @@
using System.Collections.Generic;
using MediaBrowser.Controller.Entities;
namespace MediaBrowser.Controller.Lyrics
{
namespace MediaBrowser.Controller.Lyrics;
/// <summary>
/// Interface ILyricsProvider.
/// </summary>
@ -26,4 +26,3 @@ namespace MediaBrowser.Controller.Lyrics
/// <returns>If found, returns lyrics for passed item; otherwise, null.</returns>
LyricResponse? GetLyrics(BaseItem item);
}
}

View file

@ -1,18 +1,28 @@
namespace MediaBrowser.Controller.Lyrics
{
namespace MediaBrowser.Controller.Lyrics;
/// <summary>
/// Lyric model.
/// </summary>
public class Lyric
{
/// <summary>
/// Gets or sets the start time in ticks.
/// Initializes a new instance of the <see cref="Lyric"/> class.
/// </summary>
public long? Start { get; set; }
/// <param name="start">The lyric start time in ticks.</param>
/// <param name="text">The lyric text.</param>
public Lyric(string text, long? start = null)
{
Start = start;
Text = text;
}
/// <summary>
/// Gets or sets the text.
/// Gets the start time in ticks.
/// </summary>
public string Text { get; set; } = string.Empty;
}
public long? Start { get; }
/// <summary>
/// Gets the text.
/// </summary>
public string Text { get; }
}

View file

@ -1,8 +1,7 @@
using System.IO;
using System.Linq;
namespace MediaBrowser.Controller.Lyrics
{
namespace MediaBrowser.Controller.Lyrics;
/// <summary>
/// Lyric helper methods.
/// </summary>
@ -15,20 +14,16 @@ namespace MediaBrowser.Controller.Lyrics
/// <param name="itemPath">Path of requested item.</param>
/// <returns>Lyric file path if passed lyric provider's supported media type is found; otherwise, null.</returns>
public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
{
if (lyricProvider.SupportedMediaTypes.Any())
{
foreach (string lyricFileExtension in lyricProvider.SupportedMediaTypes)
{
string lyricFilePath = @Path.ChangeExtension(itemPath, lyricFileExtension);
if (System.IO.File.Exists(lyricFilePath))
var lyricFilePath = Path.ChangeExtension(itemPath, lyricFileExtension);
if (File.Exists(lyricFilePath))
{
return lyricFilePath;
}
}
}
return null;
}
}
}

View file

@ -1,9 +1,7 @@
#nullable disable
using System.Collections.Generic;
namespace MediaBrowser.Controller.Lyrics
{
namespace MediaBrowser.Controller.Lyrics;
/// <summary>
/// LyricResponse model.
/// </summary>
@ -12,11 +10,10 @@ namespace MediaBrowser.Controller.Lyrics
/// <summary>
/// Gets or sets Metadata.
/// </summary>
public IDictionary<string, string> Metadata { get; set; }
public IDictionary<string, string>? Metadata { get; set; }
/// <summary>
/// Gets or sets Lyrics.
/// </summary>
public IEnumerable<Lyric> Lyrics { get; set; }
}
public IEnumerable<Lyric>? Lyrics { get; set; }
}

View file

@ -1,45 +1,32 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using LrcParser.Model;
using LrcParser.Parser;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace MediaBrowser.Providers.Lyric
{
namespace MediaBrowser.Providers.Lyric;
/// <summary>
/// LRC Lyric Provider.
/// </summary>
public class LrcLyricProvider : ILyricProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="LrcLyricProvider"/> class.
/// </summary>
public LrcLyricProvider()
{
Name = "LrcLyricProvider";
/// <inheritdoc />
public string Name { get; } = "LrcLyricProvider";
SupportedMediaTypes = new Collection<string>
/// <inheritdoc />
public IEnumerable<string> SupportedMediaTypes
{
get => new Collection<string>
{
"lrc"
};
}
/// <summary>
/// Gets a value indicating the provider name.
/// </summary>
public string Name { get; }
/// <summary>
/// Gets a value indicating the File Extenstions this provider supports.
/// </summary>
public IEnumerable<string> SupportedMediaTypes { get; }
/// <summary>
/// Opens lyric file for the requested item, and processes it for API return.
/// </summary>
@ -65,21 +52,25 @@ namespace MediaBrowser.Providers.Lyric
// Parse and sort lyric rows
LyricParser lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
Song lyricData = lrcLyricParser.Decode(lrcFileContent);
sortedLyricData = lyricData.Lyrics.Where(x => x.TimeTags.Count > 0).OrderBy(x => x.TimeTags.ToArray()[0].Value).ToList();
sortedLyricData = lyricData.Lyrics.Where(x => x.TimeTags.Count > 0).OrderBy(x => x.TimeTags.First().Value).ToList();
// Parse metadata rows
var metaDataRows = lyricData.Lyrics
.Where(x => x.TimeTags.Count == 0)
.Where(x => x.Text.StartsWith("[", StringComparison.Ordinal) && x.Text.EndsWith("]", StringComparison.Ordinal))
.Where(x => x.Text.StartsWith('[') && x.Text.EndsWith(']'))
.Select(x => x.Text)
.ToList();
foreach (string metaDataRow in metaDataRows)
{
var metaDataField = metaDataRow.Split(":");
var metaDataField = metaDataRow.Split(':');
if (metaDataField.Length != 2)
{
continue;
}
string metaDataFieldName = metaDataField[0].Replace("[", string.Empty, StringComparison.Ordinal).Trim();
string metaDataFieldValue = metaDataField[1].Replace("]", string.Empty, StringComparison.Ordinal).Trim();
string metaDataFieldName = metaDataField[0][1..].Trim();
string metaDataFieldValue = metaDataField[1][..^1].Trim();
metaData.Add(metaDataFieldName, metaDataFieldValue);
}
@ -89,7 +80,7 @@ namespace MediaBrowser.Providers.Lyric
return null;
}
if (!sortedLyricData.Any())
if (sortedLyricData.Count == 0)
{
return null;
}
@ -97,8 +88,8 @@ namespace MediaBrowser.Providers.Lyric
for (int i = 0; i < sortedLyricData.Count; i++)
{
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
long ticks = Convert.ToInt64(timeData, new NumberFormatInfo()) * 10000;
lyricList.Add(new Controller.Lyrics.Lyric { Start = ticks, Text = sortedLyricData[i].Text });
long ticks = TimeSpan.FromMilliseconds((double)timeData).Ticks;
lyricList.Add(new Controller.Lyrics.Lyric(sortedLyricData[i].Text, ticks));
}
if (metaData.Any())
@ -109,4 +100,3 @@ namespace MediaBrowser.Providers.Lyric
return new LyricResponse { Lyrics = lyricList };
}
}
}

View file

@ -1,18 +1,21 @@
#nullable disable
#pragma warning disable CS1591
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
namespace MediaBrowser.Providers.Lyric
{
namespace MediaBrowser.Providers.Lyric;
/// <summary>
/// Lyric Manager.
/// </summary>
public class LyricManager : ILyricManager
{
private readonly ILyricProvider[] _lyricProviders;
/// <summary>
/// Initializes a new instance of the <see cref="LyricManager"/> class.
/// </summary>
/// <param name="lyricProviders">All found lyricProviders.</param>
public LyricManager(IEnumerable<ILyricProvider> lyricProviders)
{
_lyricProviders = lyricProviders.ToArray();
@ -52,4 +55,3 @@ namespace MediaBrowser.Providers.Lyric
return false;
}
}
}

View file

@ -5,36 +5,25 @@ using System.Linq;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Lyrics;
namespace MediaBrowser.Providers.Lyric
{
namespace MediaBrowser.Providers.Lyric;
/// <summary>
/// TXT Lyric Provider.
/// </summary>
public class TxtLyricProvider : ILyricProvider
{
/// <summary>
/// Initializes a new instance of the <see cref="TxtLyricProvider"/> class.
/// </summary>
public TxtLyricProvider()
{
Name = "TxtLyricProvider";
/// <inheritdoc />
public string Name { get; } = "TxtLyricProvider";
SupportedMediaTypes = new Collection<string>
/// <inheritdoc />
public IEnumerable<string> SupportedMediaTypes
{
get => new Collection<string>
{
"lrc", "txt"
};
}
/// <summary>
/// Gets a value indicating the provider name.
/// </summary>
public string Name { get; }
/// <summary>
/// Gets a value indicating the File Extenstions this provider supports.
/// </summary>
public IEnumerable<string> SupportedMediaTypes { get; }
/// <summary>
/// Opens lyric file for the requested item, and processes it for API return.
/// </summary>
@ -49,25 +38,20 @@ namespace MediaBrowser.Providers.Lyric
return null;
}
string[] lyricTextLines = System.IO.File.ReadAllLines(lyricFilePath);
List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
string lyricData = System.IO.File.ReadAllText(lyricFilePath);
// Splitting on Environment.NewLine caused some new lines to be missed in Windows.
char[] newLineDelims = new[] { '\r', '\n' };
string[] lyricTextLines = lyricData.Split(newLineDelims, StringSplitOptions.RemoveEmptyEntries);
if (!lyricTextLines.Any())
if (lyricTextLines.Length == 0)
{
return null;
}
foreach (string lyricTextLine in lyricTextLines)
{
lyricList.Add(new Controller.Lyrics.Lyric { Text = lyricTextLine });
lyricList.Add(new Controller.Lyrics.Lyric(lyricTextLine));
}
return new LyricResponse { Lyrics = lyricList };
}
}
}

View file

@ -6,7 +6,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Jellyfin.Api\Jellyfin.Api.csproj" />
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
<ProjectReference Include="..\DvdLib\DvdLib.csproj" />