Auto stash before merge of "lyric-lrc-file-support" and "origin/lyric-lrc-file-support"

This commit is contained in:
1hitsong
2022-09-15 19:45:26 -04:00
parent 7520a19985
commit d9be3874ba
14 changed files with 173 additions and 190 deletions

View File

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

View File

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

View File

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

View File

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