Create ILyricManager

This commit is contained in:
1hitsong
2022-09-15 20:49:25 -04:00
parent d9be3874ba
commit f4fd908f8d
9 changed files with 175 additions and 71 deletions

View File

@@ -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);
}
}

View File

@@ -6,8 +6,13 @@ 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>

View File

@@ -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;
}
}
}