Adds lyric providers to DI pipeline

This is adding those lyric providers to the DI pipeline along with a super simple implementation of how to use them in the controller method. Probably should be refactored into a lyric service of some sort that would have the providers injected into it.
pull/8381/head
Jamie Introcaso 2 years ago
parent 31ec521f5e
commit c0dae0fef5

@ -46,6 +46,7 @@ using Emby.Server.Implementations.SyncPlay;
using Emby.Server.Implementations.TV; using Emby.Server.Implementations.TV;
using Emby.Server.Implementations.Updates; using Emby.Server.Implementations.Updates;
using Jellyfin.Api.Helpers; using Jellyfin.Api.Helpers;
using Jellyfin.Api.Models.UserDtos;
using Jellyfin.MediaEncoding.Hls.Playlist; using Jellyfin.MediaEncoding.Hls.Playlist;
using Jellyfin.Networking.Configuration; using Jellyfin.Networking.Configuration;
using Jellyfin.Networking.Manager; using Jellyfin.Networking.Manager;
@ -580,6 +581,8 @@ namespace Emby.Server.Implementations
serviceCollection.AddTransient(provider => new Lazy<ILibraryMonitor>(provider.GetRequiredService<ILibraryMonitor>)); serviceCollection.AddTransient(provider => new Lazy<ILibraryMonitor>(provider.GetRequiredService<ILibraryMonitor>));
serviceCollection.AddTransient(provider => new Lazy<IProviderManager>(provider.GetRequiredService<IProviderManager>)); serviceCollection.AddTransient(provider => new Lazy<IProviderManager>(provider.GetRequiredService<IProviderManager>));
serviceCollection.AddTransient(provider => new Lazy<IUserViewManager>(provider.GetRequiredService<IUserViewManager>)); serviceCollection.AddTransient(provider => new Lazy<IUserViewManager>(provider.GetRequiredService<IUserViewManager>));
serviceCollection.AddTransient<ILyricsProvider, TxtLyricsProvider>();
serviceCollection.AddTransient<ILyricsProvider, LrcLyricsProvider>();
serviceCollection.AddSingleton<ILibraryManager, LibraryManager>(); serviceCollection.AddSingleton<ILibraryManager, LibraryManager>();
serviceCollection.AddSingleton<NamingOptions>(); serviceCollection.AddSingleton<NamingOptions>();

@ -1,17 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Jellyfin.Api.Constants; using Jellyfin.Api.Constants;
using Jellyfin.Api.Extensions; using Jellyfin.Api.Extensions;
using Jellyfin.Api.Helpers;
using Jellyfin.Api.ModelBinders; using Jellyfin.Api.ModelBinders;
using Jellyfin.Api.Models.UserDtos; using Jellyfin.Api.Models.UserDtos;
using Jellyfin.Data.Enums; using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Controller.Dto; using MediaBrowser.Controller.Dto;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Controller.Entities.Audio;
@ -40,6 +37,7 @@ namespace Jellyfin.Api.Controllers
private readonly IDtoService _dtoService; private readonly IDtoService _dtoService;
private readonly IUserViewManager _userViewManager; private readonly IUserViewManager _userViewManager;
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
private readonly IEnumerable<ILyricsProvider> _lyricProviders;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="UserLibraryController"/> class. /// Initializes a new instance of the <see cref="UserLibraryController"/> class.
@ -50,13 +48,15 @@ namespace Jellyfin.Api.Controllers
/// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param> /// <param name="dtoService">Instance of the <see cref="IDtoService"/> interface.</param>
/// <param name="userViewManager">Instance of the <see cref="IUserViewManager"/> interface.</param> /// <param name="userViewManager">Instance of the <see cref="IUserViewManager"/> interface.</param>
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param> /// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
/// <param name="lyricProviders">Collection of all registered <see cref="ILyricsProvider"/> interfaces.</param>
public UserLibraryController( public UserLibraryController(
IUserManager userManager, IUserManager userManager,
IUserDataManager userDataRepository, IUserDataManager userDataRepository,
ILibraryManager libraryManager, ILibraryManager libraryManager,
IDtoService dtoService, IDtoService dtoService,
IUserViewManager userViewManager, IUserViewManager userViewManager,
IFileSystem fileSystem) IFileSystem fileSystem,
IEnumerable<ILyricsProvider> lyricProviders)
{ {
_userManager = userManager; _userManager = userManager;
_userDataRepository = userDataRepository; _userDataRepository = userDataRepository;
@ -64,6 +64,7 @@ namespace Jellyfin.Api.Controllers
_dtoService = dtoService; _dtoService = dtoService;
_userViewManager = userViewManager; _userViewManager = userViewManager;
_fileSystem = fileSystem; _fileSystem = fileSystem;
_lyricProviders = lyricProviders;
} }
/// <summary> /// <summary>
@ -413,10 +414,14 @@ namespace Jellyfin.Api.Controllers
return NotFound(); return NotFound();
} }
var result = ItemHelper.GetLyricData(item); // Super nieve implementation. I would suggest building a lyric service of some sort and doing this there.
if (result is not null) foreach (var provider in _lyricProviders)
{ {
return Ok(result); provider.Process(item);
if (provider.HasData)
{
return Ok(provider.Data);
}
} }
return NotFound(); return NotFound();

Loading…
Cancel
Save