The Free Software Media System - Server Backend & API
Remove use of AddParts. Cleanup use of Lyric vs Lyrics.
1hitsongf740d1b9f00d
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.csindex 409fc04b16..5edc25952d 100644--- a/Emby.Server.Implementations/ApplicationHost.cs+++ b/Emby.Server.Implementations/ApplicationHost.cs@@ -789,7 +789,7 @@ namespace Emby.Server.ImplementationsResolve<ILiveTvManager>().AddParts(GetExports<ILiveTvService>(), GetExports<ITunerHost>(), GetExports<IListingsProvider>());Resolve<ISubtitleManager>().AddParts(GetExports<ISubtitleProvider>());- Resolve<ILyricManager>().AddParts(GetExports<ILyricProvider>());+ //Resolve<ILyricManager>().AddParts(GetExports<ILyricProvider>());Resolve<IChannelManager>().AddParts(GetExports<IChannel>());diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.csindex 1421ab444a..2cb2e93284 100644--- a/Jellyfin.Api/Controllers/UserLibraryController.cs+++ b/Jellyfin.Api/Controllers/UserLibraryController.cs@@ -394,10 +394,10 @@ namespace Jellyfin.Api.Controllers/// <param name="itemId">Item id.</param>/// <response code="200">Lyrics returned.</response>/// <response code="404">Something went wrong. No Lyrics will be returned.</response>- /// <returns>An <see cref="OkResult"/> containing the intros to play.</returns>+ /// <returns>An <see cref="OkResult"/> containing the item's lyrics.</returns>[HttpGet("Users/{userId}/Items/{itemId}/Lyrics")][ProducesResponseType(StatusCodes.Status200OK)]- public ActionResult<QueryResult<BaseItemDto>> GetLyrics([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)+ public ActionResult<QueryResult<LyricResponse>> GetLyrics([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId){var user = _userManager.GetUserById(userId);@@ -415,7 +415,7 @@ namespace Jellyfin.Api.Controllersreturn NotFound();}- var result = _lyricManager.GetLyric(item);+ var result = _lyricManager.GetLyrics(item);if (result is not null){return Ok(result);diff --git a/Jellyfin.Server/CoreAppHost.cs b/Jellyfin.Server/CoreAppHost.csindex 67e50b92d9..984711dc2d 100644--- a/Jellyfin.Server/CoreAppHost.cs+++ b/Jellyfin.Server/CoreAppHost.cs@@ -19,6 +19,7 @@ using MediaBrowser.Controller.Devices;using MediaBrowser.Controller.Drawing;using MediaBrowser.Controller.Events;using MediaBrowser.Controller.Library;+using MediaBrowser.Controller.Lyrics;using MediaBrowser.Controller.Net;using MediaBrowser.Controller.Security;using MediaBrowser.Model.Activity;@@ -95,6 +96,11 @@ namespace Jellyfin.ServerserviceCollection.AddScoped<IAuthenticationManager, AuthenticationManager>();+ foreach (var type in GetExportTypes<ILyricProvider>())+ {+ serviceCollection.AddSingleton(typeof(ILyricProvider), type);+ }+base.RegisterServices(serviceCollection);}diff --git a/MediaBrowser.Controller/Lyrics/ILyricManager.cs b/MediaBrowser.Controller/Lyrics/ILyricManager.csindex 4fd11b9e02..c0f78d177d 100644--- a/MediaBrowser.Controller/Lyrics/ILyricManager.cs+++ b/MediaBrowser.Controller/Lyrics/ILyricManager.cs@@ -1,37 +1,23 @@-#nullable disable-#pragma warning disable CS1591-using System;-using System.Collections.Generic;-using System.Threading;-using System.Threading.Tasks;using MediaBrowser.Controller.Entities;-using MediaBrowser.Model.Configuration;-using MediaBrowser.Model.Providers;namespace MediaBrowser.Controller.Lyrics{public interface ILyricManager{- /// <summary>- /// Adds the parts.- /// </summary>- /// <param name="lyricProviders">The lyric providers.</param>- void AddParts(IEnumerable<ILyricProvider> lyricProviders);-/// <summary>/// Gets the lyrics./// </summary>/// <param name="item">The media item.</param>/// <returns>Lyrics for passed item.</returns>- LyricResponse GetLyric(BaseItem item);+ LyricResponse GetLyrics(BaseItem item);/// <summary>/// Checks if requested item has a matching local lyric file./// </summary>/// <param name="item">The media item.</param>- /// <returns>True if item has a matching lyrics file; otherwise false.</returns>+ /// <returns>True if item has a matching lyric file; otherwise false.</returns>bool HasLyricFile(BaseItem item);}}diff --git a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricProvider.csindex 691fed1fd2..5e677ab26f 100644--- a/MediaBrowser.Controller/Lyrics/ILyricProvider.cs+++ b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs@@ -22,8 +22,8 @@ namespace MediaBrowser.Controller.Lyrics/// <summary>/// Gets the lyrics./// </summary>- /// <param name="item">The item to to process.</param>- /// <returns>Task{LyricResponse}.</returns>+ /// <param name="item">The media item.</param>+ /// <returns>If found, returns lyrics for passed item; otherwise, null.</returns>LyricResponse? GetLyrics(BaseItem item);}}diff --git a/MediaBrowser.Controller/Lyrics/Lyric.cs b/MediaBrowser.Controller/Lyrics/Lyric.csindex d44546dd39..56a0a8a72d 100644--- a/MediaBrowser.Controller/Lyrics/Lyric.cs+++ b/MediaBrowser.Controller/Lyrics/Lyric.cs@@ -1,12 +1,12 @@namespace MediaBrowser.Controller.Lyrics{/// <summary>- /// Lyric dto.+ /// Lyric model./// </summary>public class Lyric{/// <summary>- /// Gets or sets the start time (ticks).+ /// Gets or sets the start time in ticks./// </summary>public double? Start { get; set; }diff --git a/MediaBrowser.Controller/Lyrics/LyricInfo.cs b/MediaBrowser.Controller/Lyrics/LyricInfo.csindex d44e14237a..018f296b1a 100644--- a/MediaBrowser.Controller/Lyrics/LyricInfo.cs+++ b/MediaBrowser.Controller/Lyrics/LyricInfo.cs@@ -11,16 +11,16 @@ using Microsoft.AspNetCore.Mvc;namespace MediaBrowser.Controller.Lyrics{/// <summary>- /// Item helper.+ /// Lyric helper methods./// </summary>public static class LyricInfo{/// <summary>- /// Checks if requested item has a matching lyric file.+ /// Gets matching lyric file for a requested item./// </summary>- /// <param name="lyricProvider">The current lyricProvider interface.</param>+ /// <param name="lyricProvider">The lyricProvider interface to use.</param>/// <param name="itemPath">Path of requested item.</param>- /// <returns>True if item has a matching lyrics file.</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){if (lyricProvider.SupportedMediaTypes.Any())diff --git a/MediaBrowser.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.csindex e312638ecc..498eb873c7 100644--- a/MediaBrowser.Controller/Lyrics/LyricResponse.cs+++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs@@ -6,10 +6,19 @@ using System.Collections.Generic;namespace MediaBrowser.Controller.Lyrics{+ /// <summary>+ /// LyricResponse model.+ /// </summary>public class LyricResponse{+ /// <summary>+ /// Gets or sets MetaData.+ /// </summary>public IDictionary<string, object> MetaData { get; set; }+ /// <summary>+ /// Gets or sets Lyrics.+ /// </summary>public IEnumerable<Lyric> Lyrics { get; set; }}}diff --git a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.csindex 18a85c93ac..10db10ac6f 100644--- a/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs+++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs@@ -14,7 +14,7 @@ using MediaBrowser.Controller.Lyrics;namespace MediaBrowser.Providers.Lyric{/// <summary>- /// LRC File Lyric Provider.+ /// LRC Lyric Provider./// </summary>public class LrcLyricProvider : ILyricProvider{@@ -37,21 +37,15 @@ namespace MediaBrowser.Providers.Lyricpublic string Name { get; }/// <summary>- /// Gets a value indicating the File Extenstions this provider works with.+ /// Gets a value indicating the File Extenstions this provider supports./// </summary>public IEnumerable<string> SupportedMediaTypes { get; }/// <summary>- /// Gets or Sets Data object generated by Process() method.- /// </summary>- /// <returns><c>Object</c> with data if no error occured; otherwise, <c>null</c>.</returns>- public object? Data { get; set; }-- /// <summary>- /// Opens lyric file for [the specified item], and processes it for API return.+ /// Opens lyric file for the requested item, and processes it for API return./// </summary>/// <param name="item">The item to to process.</param>- /// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>+ /// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/> with or without metadata; otherwise, null.</returns>public LyricResponse? GetLyrics(BaseItem item){string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);@@ -61,9 +55,9 @@ namespace MediaBrowser.Providers.Lyricreturn null;}- List<MediaBrowser.Controller.Lyrics.Lyric> lyricsList = new List<MediaBrowser.Controller.Lyrics.Lyric>();-+ List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();+var metaData = new ExpandoObject() as IDictionary<string, object>;string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);@@ -105,15 +99,15 @@ namespace MediaBrowser.Providers.Lyric{var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;- lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });+ lyricList.Add(new Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });}if (metaData.Any()){- return new LyricResponse { MetaData = metaData, Lyrics = lyricsList };+ return new LyricResponse { MetaData = metaData, Lyrics = lyricList };}- return new LyricResponse { Lyrics = lyricsList };+ return new LyricResponse { Lyrics = lyricList };}}}diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.csindex 48572c63e4..698da46867 100644--- a/MediaBrowser.Providers/Lyric/LyricManager.cs+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs@@ -36,32 +36,26 @@ namespace MediaBrowser.Providers.Lyricprivate readonly IMediaSourceManager _mediaSourceManager;private readonly ILocalizationManager _localization;- private ILyricProvider[] _lyricProviders;+ private IEnumerable<ILyricProvider> _lyricProviders;public LyricManager(ILogger<LyricManager> logger,IFileSystem fileSystem,ILibraryMonitor monitor,IMediaSourceManager mediaSourceManager,- ILocalizationManager localizationManager)+ ILocalizationManager localizationManager,+ IEnumerable<ILyricProvider> lyricProviders){_logger = logger;_fileSystem = fileSystem;_monitor = monitor;_mediaSourceManager = mediaSourceManager;_localization = localizationManager;+ _lyricProviders = lyricProviders;}/// <inheritdoc />- public void AddParts(IEnumerable<ILyricProvider> lyricProviders)- {- _lyricProviders = lyricProviders- .OrderBy(i => i is IHasOrder hasOrder ? hasOrder.Order : 0)- .ToArray();- }-- /// <inheritdoc />- public LyricResponse GetLyric(BaseItem item)+ public LyricResponse GetLyrics(BaseItem item){foreach (ILyricProvider provider in _lyricProviders){diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.csindex 939d8708b2..aa222ed97b 100644--- a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs+++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs@@ -11,7 +11,7 @@ using MediaBrowser.Controller.Lyrics;namespace MediaBrowser.Providers.Lyric{/// <summary>- /// TXT File Lyric Provider.+ /// TXT Lyric Provider./// </summary>public class TxtLyricProvider : ILyricProvider{@@ -34,21 +34,15 @@ namespace MediaBrowser.Providers.Lyricpublic string Name { get; }/// <summary>- /// Gets a value indicating the File Extenstions this provider works with.+ /// Gets a value indicating the File Extenstions this provider supports./// </summary>public IEnumerable<string> SupportedMediaTypes { get; }/// <summary>- /// Gets or Sets Data object generated by Process() method.- /// </summary>- /// <returns><c>Object</c> with data if no error occured; otherwise, <c>null</c>.</returns>- public object? Data { get; set; }-- /// <summary>- /// Opens lyric file for [the specified item], and processes it for API return.+ /// Opens lyric file for the requested item, and processes it for API return./// </summary>/// <param name="item">The item to to process.</param>- /// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>+ /// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/>; otherwise, null.</returns>public LyricResponse? GetLyrics(BaseItem item){string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);@@ -58,25 +52,25 @@ namespace MediaBrowser.Providers.Lyricreturn null;}- List<MediaBrowser.Controller.Lyrics.Lyric> lyricsList = new List<MediaBrowser.Controller.Lyrics.Lyric>();+ 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);+ char[] newLineDelims = new[] { '\r', '\n' };+ string[] lyricTextLines = lyricData.Split(newLineDelims, StringSplitOptions.RemoveEmptyEntries);if (!lyricTextLines.Any()){return null;}- foreach (string lyricLine in lyricTextLines)+ foreach (string lyricTextLine in lyricTextLines){- lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Text = lyricLine });+ lyricList.Add(new Controller.Lyrics.Lyric { Text = lyricTextLine });}- return new LyricResponse { Lyrics = lyricsList };+ return new LyricResponse { Lyrics = lyricList };}}}