mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Code cleanups. Remove pragma commands
This commit is contained in:
parent
29932466a9
commit
c65819221d
@ -1,9 +1,10 @@
|
|||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Lyrics
|
namespace MediaBrowser.Controller.Lyrics;
|
||||||
{
|
|
||||||
|
/// <summary>
|
||||||
|
/// Interface ILyricManager.
|
||||||
|
/// </summary>
|
||||||
public interface ILyricManager
|
public interface ILyricManager
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -20,4 +21,3 @@ namespace MediaBrowser.Controller.Lyrics
|
|||||||
/// <returns>True if item has a matching lyric file; otherwise false.</returns>
|
/// <returns>True if item has a matching lyric file; otherwise false.</returns>
|
||||||
bool HasLyricFile(BaseItem item);
|
bool HasLyricFile(BaseItem item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Lyrics
|
namespace MediaBrowser.Controller.Lyrics;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Interface ILyricsProvider.
|
/// Interface ILyricsProvider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -26,4 +26,3 @@ namespace MediaBrowser.Controller.Lyrics
|
|||||||
/// <returns>If found, returns lyrics for passed item; otherwise, null.</returns>
|
/// <returns>If found, returns lyrics for passed item; otherwise, null.</returns>
|
||||||
LyricResponse? GetLyrics(BaseItem item);
|
LyricResponse? GetLyrics(BaseItem item);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,18 +1,28 @@
|
|||||||
namespace MediaBrowser.Controller.Lyrics
|
namespace MediaBrowser.Controller.Lyrics;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lyric model.
|
/// Lyric model.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Lyric
|
public class Lyric
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the start time in ticks.
|
/// Initializes a new instance of the <see cref="Lyric"/> class.
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Gets or sets the text.
|
/// Gets the start time in ticks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Text { get; set; } = string.Empty;
|
public long? Start { get; }
|
||||||
}
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the text.
|
||||||
|
/// </summary>
|
||||||
|
public string Text { get; }
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Lyrics
|
namespace MediaBrowser.Controller.Lyrics;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lyric helper methods.
|
/// Lyric helper methods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -15,20 +14,16 @@ namespace MediaBrowser.Controller.Lyrics
|
|||||||
/// <param name="itemPath">Path of requested item.</param>
|
/// <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>
|
/// <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)
|
public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
|
||||||
{
|
|
||||||
if (lyricProvider.SupportedMediaTypes.Any())
|
|
||||||
{
|
{
|
||||||
foreach (string lyricFileExtension in lyricProvider.SupportedMediaTypes)
|
foreach (string lyricFileExtension in lyricProvider.SupportedMediaTypes)
|
||||||
{
|
{
|
||||||
string lyricFilePath = @Path.ChangeExtension(itemPath, lyricFileExtension);
|
var lyricFilePath = Path.ChangeExtension(itemPath, lyricFileExtension);
|
||||||
if (System.IO.File.Exists(lyricFilePath))
|
if (File.Exists(lyricFilePath))
|
||||||
{
|
{
|
||||||
return lyricFilePath;
|
return lyricFilePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
#nullable disable
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Lyrics
|
namespace MediaBrowser.Controller.Lyrics;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LyricResponse model.
|
/// LyricResponse model.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -12,11 +10,10 @@ namespace MediaBrowser.Controller.Lyrics
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets Metadata.
|
/// Gets or sets Metadata.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IDictionary<string, string> Metadata { get; set; }
|
public IDictionary<string, string>? Metadata { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets Lyrics.
|
/// Gets or sets Lyrics.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<Lyric> Lyrics { get; set; }
|
public IEnumerable<Lyric>? Lyrics { get; set; }
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,45 +1,32 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Dynamic;
|
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using LrcParser.Model;
|
using LrcParser.Model;
|
||||||
using LrcParser.Parser;
|
using LrcParser.Parser;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Lyrics;
|
using MediaBrowser.Controller.Lyrics;
|
||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Lyric
|
namespace MediaBrowser.Providers.Lyric;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LRC Lyric Provider.
|
/// LRC Lyric Provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LrcLyricProvider : ILyricProvider
|
public class LrcLyricProvider : ILyricProvider
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <inheritdoc />
|
||||||
/// Initializes a new instance of the <see cref="LrcLyricProvider"/> class.
|
public string Name { get; } = "LrcLyricProvider";
|
||||||
/// </summary>
|
|
||||||
public LrcLyricProvider()
|
|
||||||
{
|
|
||||||
Name = "LrcLyricProvider";
|
|
||||||
|
|
||||||
SupportedMediaTypes = new Collection<string>
|
/// <inheritdoc />
|
||||||
|
public IEnumerable<string> SupportedMediaTypes
|
||||||
|
{
|
||||||
|
get => new Collection<string>
|
||||||
{
|
{
|
||||||
"lrc"
|
"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>
|
/// <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>
|
||||||
@ -65,21 +52,25 @@ namespace MediaBrowser.Providers.Lyric
|
|||||||
// Parse and sort lyric rows
|
// Parse and sort lyric rows
|
||||||
LyricParser lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
|
LyricParser lrcLyricParser = new LrcParser.Parser.Lrc.LrcParser();
|
||||||
Song lyricData = lrcLyricParser.Decode(lrcFileContent);
|
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
|
// Parse metadata rows
|
||||||
var metaDataRows = lyricData.Lyrics
|
var metaDataRows = lyricData.Lyrics
|
||||||
.Where(x => x.TimeTags.Count == 0)
|
.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)
|
.Select(x => x.Text)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
foreach (string metaDataRow in metaDataRows)
|
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 metaDataFieldName = metaDataField[0][1..].Trim();
|
||||||
string metaDataFieldValue = metaDataField[1].Replace("]", string.Empty, StringComparison.Ordinal).Trim();
|
string metaDataFieldValue = metaDataField[1][..^1].Trim();
|
||||||
|
|
||||||
metaData.Add(metaDataFieldName, metaDataFieldValue);
|
metaData.Add(metaDataFieldName, metaDataFieldValue);
|
||||||
}
|
}
|
||||||
@ -89,7 +80,7 @@ namespace MediaBrowser.Providers.Lyric
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!sortedLyricData.Any())
|
if (sortedLyricData.Count == 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -97,8 +88,8 @@ namespace MediaBrowser.Providers.Lyric
|
|||||||
for (int i = 0; i < sortedLyricData.Count; i++)
|
for (int i = 0; i < sortedLyricData.Count; i++)
|
||||||
{
|
{
|
||||||
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
|
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
|
||||||
long ticks = Convert.ToInt64(timeData, new NumberFormatInfo()) * 10000;
|
long ticks = TimeSpan.FromMilliseconds((double)timeData).Ticks;
|
||||||
lyricList.Add(new Controller.Lyrics.Lyric { Start = ticks, Text = sortedLyricData[i].Text });
|
lyricList.Add(new Controller.Lyrics.Lyric(sortedLyricData[i].Text, ticks));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metaData.Any())
|
if (metaData.Any())
|
||||||
@ -109,4 +100,3 @@ namespace MediaBrowser.Providers.Lyric
|
|||||||
return new LyricResponse { Lyrics = lyricList };
|
return new LyricResponse { Lyrics = lyricList };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,18 +1,21 @@
|
|||||||
#nullable disable
|
|
||||||
|
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Lyrics;
|
using MediaBrowser.Controller.Lyrics;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Lyric
|
namespace MediaBrowser.Providers.Lyric;
|
||||||
{
|
|
||||||
|
/// <summary>
|
||||||
|
/// Lyric Manager.
|
||||||
|
/// </summary>
|
||||||
public class LyricManager : ILyricManager
|
public class LyricManager : ILyricManager
|
||||||
{
|
{
|
||||||
private readonly ILyricProvider[] _lyricProviders;
|
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)
|
public LyricManager(IEnumerable<ILyricProvider> lyricProviders)
|
||||||
{
|
{
|
||||||
_lyricProviders = lyricProviders.ToArray();
|
_lyricProviders = lyricProviders.ToArray();
|
||||||
@ -52,4 +55,3 @@ namespace MediaBrowser.Providers.Lyric
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -5,36 +5,25 @@ using System.Linq;
|
|||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Lyrics;
|
using MediaBrowser.Controller.Lyrics;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Lyric
|
namespace MediaBrowser.Providers.Lyric;
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// TXT Lyric Provider.
|
/// TXT Lyric Provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TxtLyricProvider : ILyricProvider
|
public class TxtLyricProvider : ILyricProvider
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <inheritdoc />
|
||||||
/// Initializes a new instance of the <see cref="TxtLyricProvider"/> class.
|
public string Name { get; } = "TxtLyricProvider";
|
||||||
/// </summary>
|
|
||||||
public TxtLyricProvider()
|
|
||||||
{
|
|
||||||
Name = "TxtLyricProvider";
|
|
||||||
|
|
||||||
SupportedMediaTypes = new Collection<string>
|
/// <inheritdoc />
|
||||||
|
public IEnumerable<string> SupportedMediaTypes
|
||||||
|
{
|
||||||
|
get => new Collection<string>
|
||||||
{
|
{
|
||||||
"lrc", "txt"
|
"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>
|
/// <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>
|
||||||
@ -49,25 +38,20 @@ namespace MediaBrowser.Providers.Lyric
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string[] lyricTextLines = System.IO.File.ReadAllLines(lyricFilePath);
|
||||||
|
|
||||||
List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
|
List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
|
||||||
|
|
||||||
string lyricData = System.IO.File.ReadAllText(lyricFilePath);
|
if (lyricTextLines.Length == 0)
|
||||||
|
|
||||||
// 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())
|
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string lyricTextLine in lyricTextLines)
|
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 };
|
return new LyricResponse { Lyrics = lyricList };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Jellyfin.Api\Jellyfin.Api.csproj" />
|
|
||||||
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
|
<ProjectReference Include="..\MediaBrowser.Controller\MediaBrowser.Controller.csproj" />
|
||||||
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
|
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
|
||||||
<ProjectReference Include="..\DvdLib\DvdLib.csproj" />
|
<ProjectReference Include="..\DvdLib\DvdLib.csproj" />
|
||||||
|
Loading…
x
Reference in New Issue
Block a user