mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 22:17:25 -04:00
Remove use of AddParts. Cleanup use of Lyric vs Lyrics.
This commit is contained in:
parent
f4fd908f8d
commit
f740d1b9f0
11 changed files with 53 additions and 70 deletions
|
@ -789,7 +789,7 @@ namespace Emby.Server.Implementations
|
||||||
Resolve<ILiveTvManager>().AddParts(GetExports<ILiveTvService>(), GetExports<ITunerHost>(), GetExports<IListingsProvider>());
|
Resolve<ILiveTvManager>().AddParts(GetExports<ILiveTvService>(), GetExports<ITunerHost>(), GetExports<IListingsProvider>());
|
||||||
|
|
||||||
Resolve<ISubtitleManager>().AddParts(GetExports<ISubtitleProvider>());
|
Resolve<ISubtitleManager>().AddParts(GetExports<ISubtitleProvider>());
|
||||||
Resolve<ILyricManager>().AddParts(GetExports<ILyricProvider>());
|
//Resolve<ILyricManager>().AddParts(GetExports<ILyricProvider>());
|
||||||
|
|
||||||
Resolve<IChannelManager>().AddParts(GetExports<IChannel>());
|
Resolve<IChannelManager>().AddParts(GetExports<IChannel>());
|
||||||
|
|
||||||
|
|
|
@ -394,10 +394,10 @@ namespace Jellyfin.Api.Controllers
|
||||||
/// <param name="itemId">Item id.</param>
|
/// <param name="itemId">Item id.</param>
|
||||||
/// <response code="200">Lyrics returned.</response>
|
/// <response code="200">Lyrics returned.</response>
|
||||||
/// <response code="404">Something went wrong. No Lyrics will be returned.</response>
|
/// <response code="404">Something went wrong. No Lyrics will be returned.</response>
|
||||||
/// <returns>An <see cref="OkResult"/> containing the intros to play.</returns>
|
/// <returns>An <see cref="OkResult"/> containing the item's lyrics.</returns>
|
||||||
[HttpGet("Users/{userId}/Items/{itemId}/Lyrics")]
|
[HttpGet("Users/{userId}/Items/{itemId}/Lyrics")]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||||
public ActionResult<QueryResult<BaseItemDto>> GetLyrics([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
public ActionResult<QueryResult<LyricResponse>> GetLyrics([FromRoute, Required] Guid userId, [FromRoute, Required] Guid itemId)
|
||||||
{
|
{
|
||||||
var user = _userManager.GetUserById(userId);
|
var user = _userManager.GetUserById(userId);
|
||||||
|
|
||||||
|
@ -415,7 +415,7 @@ namespace Jellyfin.Api.Controllers
|
||||||
return NotFound();
|
return NotFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
var result = _lyricManager.GetLyric(item);
|
var result = _lyricManager.GetLyrics(item);
|
||||||
if (result is not null)
|
if (result is not null)
|
||||||
{
|
{
|
||||||
return Ok(result);
|
return Ok(result);
|
||||||
|
|
|
@ -19,6 +19,7 @@ using MediaBrowser.Controller.Devices;
|
||||||
using MediaBrowser.Controller.Drawing;
|
using MediaBrowser.Controller.Drawing;
|
||||||
using MediaBrowser.Controller.Events;
|
using MediaBrowser.Controller.Events;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
|
using MediaBrowser.Controller.Lyrics;
|
||||||
using MediaBrowser.Controller.Net;
|
using MediaBrowser.Controller.Net;
|
||||||
using MediaBrowser.Controller.Security;
|
using MediaBrowser.Controller.Security;
|
||||||
using MediaBrowser.Model.Activity;
|
using MediaBrowser.Model.Activity;
|
||||||
|
@ -95,6 +96,11 @@ namespace Jellyfin.Server
|
||||||
|
|
||||||
serviceCollection.AddScoped<IAuthenticationManager, AuthenticationManager>();
|
serviceCollection.AddScoped<IAuthenticationManager, AuthenticationManager>();
|
||||||
|
|
||||||
|
foreach (var type in GetExportTypes<ILyricProvider>())
|
||||||
|
{
|
||||||
|
serviceCollection.AddSingleton(typeof(ILyricProvider), type);
|
||||||
|
}
|
||||||
|
|
||||||
base.RegisterServices(serviceCollection);
|
base.RegisterServices(serviceCollection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,37 +1,23 @@
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
#pragma warning disable CS1591
|
#pragma warning disable CS1591
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Model.Configuration;
|
|
||||||
using MediaBrowser.Model.Providers;
|
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Lyrics
|
namespace MediaBrowser.Controller.Lyrics
|
||||||
{
|
{
|
||||||
public interface ILyricManager
|
public interface ILyricManager
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Adds the parts.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="lyricProviders">The lyric providers.</param>
|
|
||||||
void AddParts(IEnumerable<ILyricProvider> lyricProviders);
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the lyrics.
|
/// Gets the lyrics.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">The media item.</param>
|
/// <param name="item">The media item.</param>
|
||||||
/// <returns>Lyrics for passed item.</returns>
|
/// <returns>Lyrics for passed item.</returns>
|
||||||
LyricResponse GetLyric(BaseItem item);
|
LyricResponse GetLyrics(BaseItem item);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if requested item has a matching local lyric file.
|
/// Checks if requested item has a matching local lyric file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">The media item.</param>
|
/// <param name="item">The media item.</param>
|
||||||
/// <returns>True if item has a matching lyrics file; otherwise false.</returns>
|
/// <returns>True if item has a matching lyric file; otherwise false.</returns>
|
||||||
bool HasLyricFile(BaseItem item);
|
bool HasLyricFile(BaseItem item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,8 @@ namespace MediaBrowser.Controller.Lyrics
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the lyrics.
|
/// Gets the lyrics.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">The item to to process.</param>
|
/// <param name="item">The media item.</param>
|
||||||
/// <returns>Task{LyricResponse}.</returns>
|
/// <returns>If found, returns lyrics for passed item; otherwise, null.</returns>
|
||||||
LyricResponse? GetLyrics(BaseItem item);
|
LyricResponse? GetLyrics(BaseItem item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
namespace MediaBrowser.Controller.Lyrics
|
namespace MediaBrowser.Controller.Lyrics
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Lyric dto.
|
/// Lyric model.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class Lyric
|
public class Lyric
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the start time (ticks).
|
/// Gets or sets the start time in ticks.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public double? Start { get; set; }
|
public double? Start { get; set; }
|
||||||
|
|
||||||
|
|
|
@ -11,16 +11,16 @@ using Microsoft.AspNetCore.Mvc;
|
||||||
namespace MediaBrowser.Controller.Lyrics
|
namespace MediaBrowser.Controller.Lyrics
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Item helper.
|
/// Lyric helper methods.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class LyricInfo
|
public static class LyricInfo
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if requested item has a matching lyric file.
|
/// Gets matching lyric file for a requested item.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="lyricProvider">The current lyricProvider interface.</param>
|
/// <param name="lyricProvider">The lyricProvider interface to use.</param>
|
||||||
/// <param name="itemPath">Path of requested item.</param>
|
/// <param name="itemPath">Path of requested item.</param>
|
||||||
/// <returns>True if item has a matching lyrics file.</returns>
|
/// <returns>Lyric file path if passed lyric provider's supported media type is found; otherwise, null.</returns>
|
||||||
public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
|
public static string? GetLyricFilePath(ILyricProvider lyricProvider, string itemPath)
|
||||||
{
|
{
|
||||||
if (lyricProvider.SupportedMediaTypes.Any())
|
if (lyricProvider.SupportedMediaTypes.Any())
|
||||||
|
|
|
@ -6,10 +6,19 @@ using System.Collections.Generic;
|
||||||
|
|
||||||
namespace MediaBrowser.Controller.Lyrics
|
namespace MediaBrowser.Controller.Lyrics
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// LyricResponse model.
|
||||||
|
/// </summary>
|
||||||
public class LyricResponse
|
public class LyricResponse
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets MetaData.
|
||||||
|
/// </summary>
|
||||||
public IDictionary<string, object> MetaData { get; set; }
|
public IDictionary<string, object> MetaData { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets Lyrics.
|
||||||
|
/// </summary>
|
||||||
public IEnumerable<Lyric> Lyrics { get; set; }
|
public IEnumerable<Lyric> Lyrics { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ using MediaBrowser.Controller.Lyrics;
|
||||||
namespace MediaBrowser.Providers.Lyric
|
namespace MediaBrowser.Providers.Lyric
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// LRC File Lyric Provider.
|
/// LRC Lyric Provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LrcLyricProvider : ILyricProvider
|
public class LrcLyricProvider : ILyricProvider
|
||||||
{
|
{
|
||||||
|
@ -37,21 +37,15 @@ namespace MediaBrowser.Providers.Lyric
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating the File Extenstions this provider works with.
|
/// Gets a value indicating the File Extenstions this provider supports.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<string> SupportedMediaTypes { get; }
|
public IEnumerable<string> SupportedMediaTypes { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Data object generated by Process() method.
|
/// Opens lyric file for the requested item, and processes it for API return.
|
||||||
/// </summary>
|
|
||||||
/// <returns><c>Object</c> with data if no error occured; otherwise, <c>null</c>.</returns>
|
|
||||||
public object? Data { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Opens lyric file for [the specified item], and processes it for API return.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">The item to to process.</param>
|
/// <param name="item">The item to to process.</param>
|
||||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
|
/// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/> with or without metadata; otherwise, null.</returns>
|
||||||
public LyricResponse? GetLyrics(BaseItem item)
|
public LyricResponse? GetLyrics(BaseItem item)
|
||||||
{
|
{
|
||||||
string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
|
string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
|
||||||
|
@ -61,9 +55,9 @@ namespace MediaBrowser.Providers.Lyric
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MediaBrowser.Controller.Lyrics.Lyric> lyricsList = new List<MediaBrowser.Controller.Lyrics.Lyric>();
|
List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
|
||||||
|
|
||||||
List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();
|
List<LrcParser.Model.Lyric> sortedLyricData = new List<LrcParser.Model.Lyric>();
|
||||||
|
|
||||||
var metaData = new ExpandoObject() as IDictionary<string, object>;
|
var metaData = new ExpandoObject() as IDictionary<string, object>;
|
||||||
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
|
string lrcFileContent = System.IO.File.ReadAllText(lyricFilePath);
|
||||||
|
|
||||||
|
@ -105,15 +99,15 @@ namespace MediaBrowser.Providers.Lyric
|
||||||
{
|
{
|
||||||
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
|
var timeData = sortedLyricData[i].TimeTags.ToArray()[0].Value;
|
||||||
double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
|
double ticks = Convert.ToDouble(timeData, new NumberFormatInfo()) * 10000;
|
||||||
lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
|
lyricList.Add(new Controller.Lyrics.Lyric { Start = Math.Ceiling(ticks), Text = sortedLyricData[i].Text });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (metaData.Any())
|
if (metaData.Any())
|
||||||
{
|
{
|
||||||
return new LyricResponse { MetaData = metaData, Lyrics = lyricsList };
|
return new LyricResponse { MetaData = metaData, Lyrics = lyricList };
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LyricResponse { Lyrics = lyricsList };
|
return new LyricResponse { Lyrics = lyricList };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,32 +36,26 @@ namespace MediaBrowser.Providers.Lyric
|
||||||
private readonly IMediaSourceManager _mediaSourceManager;
|
private readonly IMediaSourceManager _mediaSourceManager;
|
||||||
private readonly ILocalizationManager _localization;
|
private readonly ILocalizationManager _localization;
|
||||||
|
|
||||||
private ILyricProvider[] _lyricProviders;
|
private IEnumerable<ILyricProvider> _lyricProviders;
|
||||||
|
|
||||||
public LyricManager(
|
public LyricManager(
|
||||||
ILogger<LyricManager> logger,
|
ILogger<LyricManager> logger,
|
||||||
IFileSystem fileSystem,
|
IFileSystem fileSystem,
|
||||||
ILibraryMonitor monitor,
|
ILibraryMonitor monitor,
|
||||||
IMediaSourceManager mediaSourceManager,
|
IMediaSourceManager mediaSourceManager,
|
||||||
ILocalizationManager localizationManager)
|
ILocalizationManager localizationManager,
|
||||||
|
IEnumerable<ILyricProvider> lyricProviders)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
_monitor = monitor;
|
_monitor = monitor;
|
||||||
_mediaSourceManager = mediaSourceManager;
|
_mediaSourceManager = mediaSourceManager;
|
||||||
_localization = localizationManager;
|
_localization = localizationManager;
|
||||||
|
_lyricProviders = lyricProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void AddParts(IEnumerable<ILyricProvider> lyricProviders)
|
public LyricResponse GetLyrics(BaseItem item)
|
||||||
{
|
|
||||||
_lyricProviders = lyricProviders
|
|
||||||
.OrderBy(i => i is IHasOrder hasOrder ? hasOrder.Order : 0)
|
|
||||||
.ToArray();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public LyricResponse GetLyric(BaseItem item)
|
|
||||||
{
|
{
|
||||||
foreach (ILyricProvider provider in _lyricProviders)
|
foreach (ILyricProvider provider in _lyricProviders)
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,7 @@ using MediaBrowser.Controller.Lyrics;
|
||||||
namespace MediaBrowser.Providers.Lyric
|
namespace MediaBrowser.Providers.Lyric
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// TXT File Lyric Provider.
|
/// TXT Lyric Provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TxtLyricProvider : ILyricProvider
|
public class TxtLyricProvider : ILyricProvider
|
||||||
{
|
{
|
||||||
|
@ -34,21 +34,15 @@ namespace MediaBrowser.Providers.Lyric
|
||||||
public string Name { get; }
|
public string Name { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a value indicating the File Extenstions this provider works with.
|
/// Gets a value indicating the File Extenstions this provider supports.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IEnumerable<string> SupportedMediaTypes { get; }
|
public IEnumerable<string> SupportedMediaTypes { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or Sets Data object generated by Process() method.
|
/// Opens lyric file for the requested item, and processes it for API return.
|
||||||
/// </summary>
|
|
||||||
/// <returns><c>Object</c> with data if no error occured; otherwise, <c>null</c>.</returns>
|
|
||||||
public object? Data { get; set; }
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Opens lyric file for [the specified item], and processes it for API return.
|
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">The item to to process.</param>
|
/// <param name="item">The item to to process.</param>
|
||||||
/// <returns><placeholder>A <see cref="Task"/> representing the asynchronous operation.</placeholder></returns>
|
/// <returns>If provider can determine lyrics, returns a <see cref="LyricResponse"/>; otherwise, null.</returns>
|
||||||
public LyricResponse? GetLyrics(BaseItem item)
|
public LyricResponse? GetLyrics(BaseItem item)
|
||||||
{
|
{
|
||||||
string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
|
string? lyricFilePath = LyricInfo.GetLyricFilePath(this, item.Path);
|
||||||
|
@ -58,25 +52,25 @@ namespace MediaBrowser.Providers.Lyric
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MediaBrowser.Controller.Lyrics.Lyric> lyricsList = new List<MediaBrowser.Controller.Lyrics.Lyric>();
|
List<Controller.Lyrics.Lyric> lyricList = new List<Controller.Lyrics.Lyric>();
|
||||||
|
|
||||||
string lyricData = System.IO.File.ReadAllText(lyricFilePath);
|
string lyricData = System.IO.File.ReadAllText(lyricFilePath);
|
||||||
|
|
||||||
// Splitting on Environment.NewLine caused some new lines to be missed in Windows.
|
// Splitting on Environment.NewLine caused some new lines to be missed in Windows.
|
||||||
char[] newLinedelims = new[] { '\r', '\n' };
|
char[] newLineDelims = new[] { '\r', '\n' };
|
||||||
string[] lyricTextLines = lyricData.Split(newLinedelims, StringSplitOptions.RemoveEmptyEntries);
|
string[] lyricTextLines = lyricData.Split(newLineDelims, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
if (!lyricTextLines.Any())
|
if (!lyricTextLines.Any())
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (string lyricLine in lyricTextLines)
|
foreach (string lyricTextLine in lyricTextLines)
|
||||||
{
|
{
|
||||||
lyricsList.Add(new MediaBrowser.Controller.Lyrics.Lyric { Text = lyricLine });
|
lyricList.Add(new Controller.Lyrics.Lyric { Text = lyricTextLine });
|
||||||
}
|
}
|
||||||
|
|
||||||
return new LyricResponse { Lyrics = lyricsList };
|
return new LyricResponse { Lyrics = lyricList };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue