diff options
| author | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-15 20:49:25 -0400 |
|---|---|---|
| committer | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-15 20:49:25 -0400 |
| commit | f4fd908f8d7ffcdea6acaf75928f6c2960ed6338 (patch) | |
| tree | 25d932b8f5734491380b5305ae2f7810e3c5a165 /MediaBrowser.Providers/Lyric | |
| parent | d9be3874ba3842d5888c5cbbe583614ed990849e (diff) | |
Create ILyricManager
Diffstat (limited to 'MediaBrowser.Providers/Lyric')
| -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 |
3 files changed, 118 insertions, 6 deletions
diff --git a/MediaBrowser.Providers/Lyric/LrcLyricsProvider.cs b/MediaBrowser.Providers/Lyric/LrcLyricProvider.cs index e30d563087..18a85c93ac 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 0000000000..48572c63e4 --- /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 2a5da4e4d8..939d8708b2 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; } |
