diff options
| author | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-15 19:45:26 -0400 |
|---|---|---|
| committer | 1hitsong <3330318+1hitsong@users.noreply.github.com> | 2022-09-15 19:45:26 -0400 |
| commit | d9be3874ba3842d5888c5cbbe583614ed990849e (patch) | |
| tree | f9a5264a402548f531e83891a70dd0a2bd7fc35d /MediaBrowser.Controller/Lyrics | |
| parent | 7520a1998569f0ba58008016c10de21d66b6b836 (diff) | |
Auto stash before merge of "lyric-lrc-file-support" and "origin/lyric-lrc-file-support"
Diffstat (limited to 'MediaBrowser.Controller/Lyrics')
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/ILyricsProvider.cs | 24 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/Lyric.cs | 18 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/LyricInfo.cs | 87 | ||||
| -rw-r--r-- | MediaBrowser.Controller/Lyrics/LyricResponse.cs | 15 |
4 files changed, 144 insertions, 0 deletions
diff --git a/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs b/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs new file mode 100644 index 000000000..bac32a398 --- /dev/null +++ b/MediaBrowser.Controller/Lyrics/ILyricsProvider.cs @@ -0,0 +1,24 @@ +using System.Collections.Generic; +using MediaBrowser.Controller.Entities; + +namespace MediaBrowser.Controller.Lyrics +{ + /// <summary> + /// Interface ILyricsProvider. + /// </summary> + public interface ILyricsProvider + { + /// <summary> + /// Gets the supported media types for this provider. + /// </summary> + /// <value>The supported media types.</value> + IEnumerable<string> SupportedMediaTypes { get; } + + /// <summary> + /// Gets the lyrics. + /// </summary> + /// <param name="item">The item to to process.</param> + /// <returns>Task{LyricResponse}.</returns> + LyricResponse? GetLyrics(BaseItem item); + } +} diff --git a/MediaBrowser.Controller/Lyrics/Lyric.cs b/MediaBrowser.Controller/Lyrics/Lyric.cs new file mode 100644 index 000000000..d44546dd3 --- /dev/null +++ b/MediaBrowser.Controller/Lyrics/Lyric.cs @@ -0,0 +1,18 @@ +namespace MediaBrowser.Controller.Lyrics +{ + /// <summary> + /// Lyric dto. + /// </summary> + public class Lyric + { + /// <summary> + /// Gets or sets the start time (ticks). + /// </summary> + public double? Start { get; set; } + + /// <summary> + /// Gets or sets the text. + /// </summary> + public string Text { get; set; } = string.Empty; + } +} diff --git a/MediaBrowser.Controller/Lyrics/LyricInfo.cs b/MediaBrowser.Controller/Lyrics/LyricInfo.cs new file mode 100644 index 000000000..83a10701a --- /dev/null +++ b/MediaBrowser.Controller/Lyrics/LyricInfo.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Lyrics; +using MediaBrowser.Controller.Net; +using Microsoft.AspNetCore.Mvc; + +namespace MediaBrowser.Controller.Lyrics +{ + /// <summary> + /// Item helper. + /// </summary> + public 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) + { + if (lyricProvider.SupportedMediaTypes.Any()) + { + foreach (string lyricFileExtension in lyricProvider.SupportedMediaTypes) + { + string lyricFilePath = @Path.ChangeExtension(itemPath, lyricFileExtension); + if (System.IO.File.Exists(lyricFilePath)) + { + return lyricFilePath; + } + } + } + + 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.Controller/Lyrics/LyricResponse.cs b/MediaBrowser.Controller/Lyrics/LyricResponse.cs new file mode 100644 index 000000000..e312638ec --- /dev/null +++ b/MediaBrowser.Controller/Lyrics/LyricResponse.cs @@ -0,0 +1,15 @@ +#nullable disable + +#pragma warning disable CS1591 + +using System.Collections.Generic; + +namespace MediaBrowser.Controller.Lyrics +{ + public class LyricResponse + { + public IDictionary<string, object> MetaData { get; set; } + + public IEnumerable<Lyric> Lyrics { get; set; } + } +} |
