diff options
| -rw-r--r-- | Emby.Server.Implementations/ApplicationHost.cs | 4 | ||||
| -rw-r--r-- | Emby.Server.Implementations/Dto/DtoService.cs | 8 | ||||
| -rw-r--r-- | Jellyfin.Api/Controllers/UserLibraryController.cs | 16 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/ILyricManager.cs | 37 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/ILyricProvider.cs (renamed from MediaBrowser.Controller/Lyrics/ILyricsProvider.cs) | 7 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/LyricInfo.cs | 50 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Lyric/LrcLyricProvider.cs (renamed from MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs) | 13 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Lyric/LyricManager.cs | 97 | ||||
| -rw-r--r-- | MediaBrowser.Providers/Lyric/TxtLyricProvider.cs (renamed from MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs) | 14 |
9 files changed, 175 insertions, 71 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 5487e5e02..409fc04b1 100644 --- a/Emby.Server.Implementations/ApplicationHost.cs +++ b/Emby.Server.Implementations/ApplicationHost.cs @@ -583,8 +583,6 @@ namespace Emby.Server.Implementations serviceCollection.AddTransient(provider => new Lazy<ILibraryMonitor>(provider.GetRequiredService<ILibraryMonitor>)); serviceCollection.AddTransient(provider => new Lazy<IProviderManager>(provider.GetRequiredService<IProviderManager>)); serviceCollection.AddTransient(provider => new Lazy<IUserViewManager>(provider.GetRequiredService<IUserViewManager>)); - serviceCollection.AddTransient<ILyricsProvider, TxtLyricsProvider>(); - serviceCollection.AddTransient<ILyricsProvider, LrcLyricsProvider>(); serviceCollection.AddSingleton<ILibraryManager, LibraryManager>(); serviceCollection.AddSingleton<NamingOptions>(); @@ -603,6 +601,7 @@ namespace Emby.Server.Implementations serviceCollection.AddSingleton<IMediaSourceManager, MediaSourceManager>(); serviceCollection.AddSingleton<ISubtitleManager, SubtitleManager>(); + serviceCollection.AddSingleton<ILyricManager, LyricManager>(); serviceCollection.AddSingleton<IProviderManager, ProviderManager>(); @@ -790,6 +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<IChannelManager>().AddParts(GetExports<IChannel>()); diff --git a/Emby.Server.Implementations/Dto/DtoService.cs b/Emby.Server.Implementations/Dto/DtoService.cs index bed82a4bb..6ab574c5c 100644 --- a/Emby.Server.Implementations/Dto/DtoService.cs +++ b/Emby.Server.Implementations/Dto/DtoService.cs @@ -52,7 +52,7 @@ namespace Emby.Server.Implementations.Dto private readonly IMediaSourceManager _mediaSourceManager; private readonly Lazy<ILiveTvManager> _livetvManagerFactory; - private readonly IEnumerable<ILyricsProvider> _lyricProviders; + private readonly ILyricManager _lyricManager; public DtoService( ILogger<DtoService> logger, @@ -64,7 +64,7 @@ namespace Emby.Server.Implementations.Dto IApplicationHost appHost, IMediaSourceManager mediaSourceManager, Lazy<ILiveTvManager> livetvManagerFactory, - IEnumerable<ILyricsProvider> lyricProviders) + ILyricManager lyricManager) { _logger = logger; _libraryManager = libraryManager; @@ -75,7 +75,7 @@ namespace Emby.Server.Implementations.Dto _appHost = appHost; _mediaSourceManager = mediaSourceManager; _livetvManagerFactory = livetvManagerFactory; - _lyricProviders = lyricProviders; + _lyricManager = lyricManager; } private ILiveTvManager LivetvManager => _livetvManagerFactory.Value; @@ -147,7 +147,7 @@ namespace Emby.Server.Implementations.Dto } else if (item is Audio) { - dto.HasLyrics = MediaBrowser.Controller.Lyrics.LyricInfo.HasLyricFile(_lyricProviders, item.Path); + dto.HasLyrics = _lyricManager.HasLyricFile(item); } if (item is IItemByName itemByName diff --git a/Jellyfin.Api/Controllers/UserLibraryController.cs b/Jellyfin.Api/Controllers/UserLibraryController.cs index 3da78c116..1421ab444 100644 --- a/Jellyfin.Api/Controllers/UserLibraryController.cs +++ b/Jellyfin.Api/Controllers/UserLibraryController.cs @@ -38,7 +38,7 @@ namespace Jellyfin.Api.Controllers private readonly IDtoService _dtoService; private readonly IUserViewManager _userViewManager; private readonly IFileSystem _fileSystem; - private readonly IEnumerable<ILyricsProvider> _lyricProviders; + private readonly ILyricManager _lyricManager; /// <summary> /// Initializes a new instance of the <see cref="UserLibraryController"/> class. @@ -49,7 +49,7 @@ namespace Jellyfin.Api.Controllers /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param> /// <param name="userViewManager">Instance of the <see cref="IUserViewManager"/> interface.</param> /// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param> - /// <param name="lyricProviders">Collection of all registered <see cref="ILyricsProvider"/> interfaces.</param> + /// <param name="lyricManager">Instance of the <see cref="ILyricManager"/> interface.</param> public UserLibraryController( IUserManager userManager, IUserDataManager userDataRepository, @@ -57,7 +57,7 @@ namespace Jellyfin.Api.Controllers IDtoService dtoService, IUserViewManager userViewManager, IFileSystem fileSystem, - IEnumerable<ILyricsProvider> lyricProviders) + ILyricManager lyricManager) { _userManager = userManager; _userDataRepository = userDataRepository; @@ -65,7 +65,7 @@ namespace Jellyfin.Api.Controllers _dtoService = dtoService; _userViewManager = userViewManager; _fileSystem = fileSystem; - _lyricProviders = lyricProviders; + _lyricManager = lyricManager; } /// <summary> @@ -415,14 +415,10 @@ namespace Jellyfin.Api.Controllers return NotFound(); } - var result = MediaBrowser.Controller.Lyrics.LyricInfo.GetLyricData(_lyricProviders, item); + var result = _lyricManager.GetLyric(item); if (result is not null) { - provider.Process(item); - if (provider.HasData) - { - return Ok(provider.Data); - } + return Ok(result); } return NotFound(); diff --git a/MediaBrowser.Controller/Lyrics/ILyricManager.cs b/MediaBrowser.Controller/Lyrics/ILyricManager.cs new file mode 100644 index 000000000..4fd11b9e0 --- /dev/null +++ b/MediaBrowser.Controller/Lyrics/ILyricManager.cs @@ -0,0 +1,37 @@ +#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); + + /// <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> + bool HasLyricFile(BaseItem item); + } +} diff --git a/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs index bac32a398..691fed1fd 100644 --- a/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs +++ b/MediaBrowser.Controller/Lyrics/ILyricProvider.cs @@ -6,9 +6,14 @@ namespace MediaBrowser.Controller.Lyrics /// <summary> /// Interface ILyricsProvider. /// </summary> - public interface ILyricsProvider + public interface ILyricProvider { /// <summary> + /// Gets a value indicating the provider name. + /// </summary> + string Name { get; } + + /// <summary> /// Gets the supported media types for this provider. /// </summary> /// <value>The supported media types.</value> diff --git a/MediaBrowser.Controller/Lyrics/LyricInfo.cs b/MediaBrowser.Controller/Lyrics/LyricInfo.cs index 83a10701a..d44e14237 100644 --- a/MediaBrowser.Controller/Lyrics/LyricInfo.cs +++ b/MediaBrowser.Controller/Lyrics/LyricInfo.cs @@ -13,42 +13,15 @@ namespace MediaBrowser.Controller.Lyrics /// <summary> /// Item helper. /// </summary> - public class LyricInfo + public static class LyricInfo { /// <summary> - /// Opens lyrics file, converts to a List of Lyrics, and returns it. - /// </summary> - /// <param name="lyricProviders">Collection of all registered <see cref="ILyricsProvider"/> interfaces.</param> - /// <param name="item">Requested Item.</param> - /// <returns>Collection of Lyrics.</returns> - public static LyricResponse? GetLyricData(IEnumerable<ILyricsProvider> lyricProviders, BaseItem item) - { - - foreach (var provider in lyricProviders) - { - var result = provider.GetLyrics(item); - if (result is not null) - { - return result; - } - } - - return new LyricResponse - { - Lyrics = new List<Lyric> - { - new Lyric { Start = 0, Text = "Test" } - } - }; - } - - /// <summary> /// Checks if requested item has a matching lyric file. /// </summary> /// <param name="lyricProvider">The current lyricProvider interface.</param> /// <param name="itemPath">Path of requested item.</param> /// <returns>True if item has a matching lyrics file.</returns> - public static string? GetLyricFilePath(ILyricsProvider lyricProvider, string itemPath) + public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath) { if (lyricProvider.SupportedMediaTypes.Any()) { @@ -64,24 +37,5 @@ namespace MediaBrowser.Controller.Lyrics return null; } - - /// <summary> - /// Checks if requested item has a matching local lyric file. - /// </summary> - /// <param name="lyricProviders">Collection of all registered <see cref="ILyricsProvider"/> interfaces.</param> - /// <param name="itemPath">Path of requested item.</param> - /// <returns>True if item has a matching lyrics file; otherwise false.</returns> - public static bool HasLyricFile(IEnumerable<ILyricsProvider> lyricProviders, string itemPath) - { - foreach (var provider in lyricProviders) - { - if (GetLyricFilePath(provider, itemPath) is not null) - { - return true; - } - } - - return false; - } } } diff --git a/MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs index e30d56308..18a85c93a 100644 --- a/MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs +++ b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs @@ -16,13 +16,15 @@ namespace MediaBrowser.Providers.Lyric /// <summary> /// LRC File Lyric Provider. /// </summary> - public class LrcLyricsProvider : ILyricsProvider + public class LrcLyricProvider : ILyricProvider { /// <summary> - /// Initializes a new instance of the <see cref="LrcLyricsProvider"/> class. + /// Initializes a new instance of the <see cref="LrcLyricProvider"/> class. /// </summary> - public LrcLyricsProvider() + public LrcLyricProvider() { + Name = "LrcLyricProvider"; + SupportedMediaTypes = new Collection<string> { "lrc" @@ -30,6 +32,11 @@ namespace MediaBrowser.Providers.Lyric } /// <summary> + /// Gets a value indicating the provider name. + /// </summary> + public string Name { get; } + + /// <summary> /// Gets a value indicating the File Extenstions this provider works with. /// </summary> public IEnumerable<string> SupportedMediaTypes { get; } diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.cs new file mode 100644 index 000000000..48572c63e --- /dev/null +++ b/MediaBrowser.Providers/Lyric/LyricManager.cs @@ -0,0 +1,97 @@ +#nullable disable + +#pragma warning disable CS1591 + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.IO; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using Jellyfin.Extensions; +using MediaBrowser.Common.Extensions; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Entities.Movies; +using MediaBrowser.Controller.Entities.TV; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Lyrics; +using MediaBrowser.Controller.Persistence; +using MediaBrowser.Controller.Providers; +using MediaBrowser.Controller.Subtitles; +using MediaBrowser.Model.Configuration; +using MediaBrowser.Model.Entities; +using MediaBrowser.Model.Globalization; +using MediaBrowser.Model.IO; +using MediaBrowser.Model.Providers; +using Microsoft.Extensions.Logging; + +namespace MediaBrowser.Providers.Lyric +{ + public class LyricManager : ILyricManager + { + private readonly ILogger<LyricManager> _logger; + private readonly IFileSystem _fileSystem; + private readonly ILibraryMonitor _monitor; + private readonly IMediaSourceManager _mediaSourceManager; + private readonly ILocalizationManager _localization; + + private ILyricProvider[] _lyricProviders; + + public LyricManager( + ILogger<LyricManager> logger, + IFileSystem fileSystem, + ILibraryMonitor monitor, + IMediaSourceManager mediaSourceManager, + ILocalizationManager localizationManager) + { + _logger = logger; + _fileSystem = fileSystem; + _monitor = monitor; + _mediaSourceManager = mediaSourceManager; + _localization = localizationManager; + } + + /// <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) + { + foreach (ILyricProvider provider in _lyricProviders) + { + var results = provider.GetLyrics(item); + if (results is not null) + { + return results; + } + } + + return null; + } + + /// <inheritdoc /> + public bool HasLyricFile(BaseItem item) + { + foreach (ILyricProvider provider in _lyricProviders) + { + if (item is null) + { + continue; + } + + if (LyricInfo.GetLyricFilePath(provider, item.Path) is not null) + { + return true; + } + } + + return false; + } + } +} diff --git a/MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs index 2a5da4e4d..939d8708b 100644 --- a/MediaBrowser.Providers/Lyric/TxtLyricsProvider.cs +++ b/MediaBrowser.Providers/Lyric/TxtLyricProvider.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Threading.Tasks; +using System.Xml.Linq; using Jellyfin.Api.Helpers; using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Lyrics; @@ -12,13 +13,15 @@ namespace MediaBrowser.Providers.Lyric /// <summary> /// TXT File Lyric Provider. /// </summary> - public class TxtLyricsProvider : ILyricsProvider + public class TxtLyricProvider : ILyricProvider { /// <summary> - /// Initializes a new instance of the <see cref="TxtLyricsProvider"/> class. + /// Initializes a new instance of the <see cref="TxtLyricProvider"/> class. /// </summary> - public TxtLyricsProvider() + public TxtLyricProvider() { + Name = "TxtLyricProvider"; + SupportedMediaTypes = new Collection<string> { "lrc", "txt" @@ -26,6 +29,11 @@ namespace MediaBrowser.Providers.Lyric } /// <summary> + /// Gets a value indicating the provider name. + /// </summary> + public string Name { get; } + + /// <summary> /// Gets a value indicating the File Extenstions this provider works with. /// </summary> public IEnumerable<string> SupportedMediaTypes { get; } |
