diff options
| author | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-16 20:52:40 -0400 |
|---|---|---|
| committer | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-16 20:52:40 -0400 |
| commit | f740d1b9f00d91bfad970f56abed67d8c8c16c9c (patch) | |
| tree | 1e82a195e7e3f74406765dfb64b6d6c30e843d2a | |
| parent | f4fd908f8d7ffcdea6acaf75928f6c2960ed6338 (diff) | |
Remove use of AddParts. Cleanup use of Lyric vs Lyrics.
| -rw-r--r-- | Emby.Server.Implementations/ApplicationHost.cs | 2 | ||||
| -rw-r--r-- | Jellyfin.Api/Controllers/UserLibraryController.cs | 6 | ||||
| -rw-r--r-- | Jellyfin.Server/CoreAppHost.cs | 6 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/ILyricManager.cs | 18 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/ILyricProvider.cs | 4 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/Lyric.cs | 4 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/LyricInfo.cs | 8 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/LyricResponse.cs | 9 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Lyric/LrcLyricProvider.cs | 24 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Lyric/LyricManager.cs | 16 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Lyric/TxtLyricProvider.cs | 26 |
11 files changed, 53 insertions, 70 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 409fc04b1..5edc25952 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/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>()); diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs index 1421ab444..2cb2e9328 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.Controllers return 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.cs index 67e50b92d..984711dc2 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.Server serviceCollection.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.cs index 4fd11b9e0..c0f78d177 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.cs index 691fed1fd..5e677ab26 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.cs index d44546dd3..56a0a8a72 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.cs index d44e14237..018f296b1 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.cs index e312638ec..498eb873c 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.cs index 18a85c93a..10db10ac6 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.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 }; } } } diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs index 48572c63e..698da4686 100644 --- a/MediaBrowser.Providers/Lyric/LyricManager.cs +++ b/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) { diff --git a/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs index 939d8708b..aa222ed97 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.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 }; } } } |
