瀏覽代碼

Remove use of AddParts. Cleanup use of Lyric vs Lyrics.

1hitsong 2 年之前
父節點
當前提交
f740d1b9f0

+ 1 - 1
Emby.Server.Implementations/ApplicationHost.cs

@@ -789,7 +789,7 @@ namespace Emby.Server.Implementations
             Resolve<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>());
 

+ 3 - 3
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.Controllers
                 return NotFound();
             }
 
-            var result = _lyricManager.GetLyric(item);
+            var result = _lyricManager.GetLyrics(item);
             if (result is not null)
             {
                 return Ok(result);

+ 6 - 0
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.Server
 
             serviceCollection.AddScoped<IAuthenticationManager, AuthenticationManager>();
 
+            foreach (var type in GetExportTypes<ILyricProvider>())
+            {
+                serviceCollection.AddSingleton(typeof(ILyricProvider), type);
+            }
+
             base.RegisterServices(serviceCollection);
         }
 

+ 2 - 16
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);
     }
 }

+ 2 - 2
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);
     }
 }

+ 2 - 2
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; }
 

+ 4 - 4
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())

+ 9 - 0
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; }
     }
 }

+ 9 - 15
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.Lyric
         public 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.Lyric
                 return 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 };
         }
     }
 }

+ 5 - 11
MediaBrowser.Providers/Lyric/LyricManager.cs

@@ -36,32 +36,26 @@ namespace MediaBrowser.Providers.Lyric
         private 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)
             {

+ 10 - 16
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.Lyric
         public 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.Lyric
                 return 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 };
         }
     }
 }