mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 01:24:44 +01:00
Merge pull request #8381 from 1hitsong/lyric-lrc-file-support
This commit is contained in:
24
MediaBrowser.Controller/Lyrics/ILyricManager.cs
Normal file
24
MediaBrowser.Controller/Lyrics/ILyricManager.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
|
||||
namespace MediaBrowser.Controller.Lyrics;
|
||||
|
||||
/// <summary>
|
||||
/// Interface ILyricManager.
|
||||
/// </summary>
|
||||
public interface ILyricManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the lyrics.
|
||||
/// </summary>
|
||||
/// <param name="item">The media item.</param>
|
||||
/// <returns>A task representing found lyrics the passed item.</returns>
|
||||
Task<LyricResponse?> GetLyrics(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 lyric file; otherwise false.</returns>
|
||||
bool HasLyricFile(BaseItem item);
|
||||
}
|
||||
36
MediaBrowser.Controller/Lyrics/ILyricProvider.cs
Normal file
36
MediaBrowser.Controller/Lyrics/ILyricProvider.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Resolvers;
|
||||
|
||||
namespace MediaBrowser.Controller.Lyrics;
|
||||
|
||||
/// <summary>
|
||||
/// Interface ILyricsProvider.
|
||||
/// </summary>
|
||||
public interface ILyricProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets a value indicating the provider name.
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the priority.
|
||||
/// </summary>
|
||||
/// <value>The priority.</value>
|
||||
ResolverPriority Priority { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the supported media types for this provider.
|
||||
/// </summary>
|
||||
/// <value>The supported media types.</value>
|
||||
IReadOnlyCollection<string> SupportedMediaTypes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the lyrics.
|
||||
/// </summary>
|
||||
/// <param name="item">The media item.</param>
|
||||
/// <returns>A task representing found lyrics.</returns>
|
||||
Task<LyricResponse?> GetLyrics(BaseItem item);
|
||||
}
|
||||
49
MediaBrowser.Controller/Lyrics/LyricInfo.cs
Normal file
49
MediaBrowser.Controller/Lyrics/LyricInfo.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Jellyfin.Extensions;
|
||||
|
||||
namespace MediaBrowser.Controller.Lyrics;
|
||||
|
||||
/// <summary>
|
||||
/// Lyric helper methods.
|
||||
/// </summary>
|
||||
public static class LyricInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets matching lyric file for a requested item.
|
||||
/// </summary>
|
||||
/// <param name="lyricProvider">The lyricProvider interface to use.</param>
|
||||
/// <param name="itemPath">Path of requested item.</param>
|
||||
/// <returns>Lyric file path if passed lyric provider's supported media type is found; otherwise, null.</returns>
|
||||
public static string? GetLyricFilePath(this ILyricProvider lyricProvider, string itemPath)
|
||||
{
|
||||
// Ensure we have a provider
|
||||
if (lyricProvider is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ensure the path to the item is not null
|
||||
string? itemDirectoryPath = Path.GetDirectoryName(itemPath);
|
||||
if (itemDirectoryPath is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ensure the directory path exists
|
||||
if (!Directory.Exists(itemDirectoryPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var lyricFilePath in Directory.GetFiles(itemDirectoryPath, $"{Path.GetFileNameWithoutExtension(itemPath)}.*"))
|
||||
{
|
||||
if (lyricProvider.SupportedMediaTypes.Contains(Path.GetExtension(lyricFilePath.AsSpan())[1..], StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return lyricFilePath;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
28
MediaBrowser.Controller/Lyrics/LyricLine.cs
Normal file
28
MediaBrowser.Controller/Lyrics/LyricLine.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace MediaBrowser.Controller.Lyrics;
|
||||
|
||||
/// <summary>
|
||||
/// Lyric model.
|
||||
/// </summary>
|
||||
public class LyricLine
|
||||
{
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LyricLine"/> class.
|
||||
/// </summary>
|
||||
/// <param name="text">The lyric text.</param>
|
||||
/// <param name="start">The lyric start time in ticks.</param>
|
||||
public LyricLine(string text, long? start = null)
|
||||
{
|
||||
Text = text;
|
||||
Start = start;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the text of this lyric line.
|
||||
/// </summary>
|
||||
public string Text { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the start time in ticks.
|
||||
/// </summary>
|
||||
public long? Start { get; }
|
||||
}
|
||||
54
MediaBrowser.Controller/Lyrics/LyricMetadata.cs
Normal file
54
MediaBrowser.Controller/Lyrics/LyricMetadata.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
|
||||
namespace MediaBrowser.Controller.Lyrics;
|
||||
|
||||
/// <summary>
|
||||
/// LyricMetadata model.
|
||||
/// </summary>
|
||||
public class LyricMetadata
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the song artist.
|
||||
/// </summary>
|
||||
public string? Artist { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the album this song is on.
|
||||
/// </summary>
|
||||
public string? Album { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title of the song.
|
||||
/// </summary>
|
||||
public string? Title { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the author of the lyric data.
|
||||
/// </summary>
|
||||
public string? Author { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the length of the song in ticks.
|
||||
/// </summary>
|
||||
public long? Length { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets who the LRC file was created by.
|
||||
/// </summary>
|
||||
public string? By { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the lyric offset compared to audio in ticks.
|
||||
/// </summary>
|
||||
public long? Offset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the software used to create the LRC file.
|
||||
/// </summary>
|
||||
public string? Creator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the version of the creator used.
|
||||
/// </summary>
|
||||
public string? Version { get; set; }
|
||||
}
|
||||
20
MediaBrowser.Controller/Lyrics/LyricResponse.cs
Normal file
20
MediaBrowser.Controller/Lyrics/LyricResponse.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MediaBrowser.Controller.Lyrics;
|
||||
|
||||
/// <summary>
|
||||
/// LyricResponse model.
|
||||
/// </summary>
|
||||
public class LyricResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets Metadata for the lyrics.
|
||||
/// </summary>
|
||||
public LyricMetadata Metadata { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a collection of individual lyric lines.
|
||||
/// </summary>
|
||||
public IReadOnlyList<LyricLine> Lyrics { get; set; } = Array.Empty<LyricLine>();
|
||||
}
|
||||
Reference in New Issue
Block a user