Skip to content
MrCakeSlayer edited this page Sep 24, 2022 · 1 revision

Lavalink4NET has the option to retrieve lyrics from the Lyrics.ovh API.

Initializing the service

Before you can retrieve lyrics from the API you have to create an instance of the LyricsService class as following:

Using the constructor

LyricsService(LyricsOptions options, ILavalinkCache cache = null)

using Lavalink4NET.Lyrics;

// Create an instance with the default options and without caching
var service = new LyricsService(new LyricsOptions());

Using Dependency Injection / IoC
using Lavalink4NET.Lyrics;
using Microsoft.Extensions.DependencyInjection;

// Setup service provider
var serviceProvider = new ServiceCollection()
    .AddSingleton<LyricsOptions>()
    .AddSingleton<LyricsService>()
    .BuildServiceProvider();

// Get the lyrics service
var lyricsService = serviceProvider.GetRequiredService<LyricsService>();

Options

Name Description Default
RestUri The RESTful HTTP API endpoint URI of the Lavalink node(see your application.yml) https://api.lyrics.ovh/v1/
SuppressExceptions A value indicating whether exceptions should be suppressed and requests where an exception occurs should return default. true
CacheTime The time how long the request should be cached. Only takes effect when a cache is specified in the constructor. 5 minutes
Decompression A value indicating whether the HTTP client should accept compressed HTTP payloads. true
UserAgent The user agent header value; or null to disable the addition of the header. Lavalink4NET

Caching

The LyricsService supports request caching which speeds up requesting. You have to specify a cache implementation (ILavalinkCache) in the constructor of the LyricsService.

See also: Request Caching Wiki Page.

Getting lyrics

You can get the lyrics for a track using the following method.

GetLyricsAsync(string artist, string title, CancellationToken cancellationToken = default)

Example
// Get lyrics from the lyrics.ovh API service
var lyrics = await lyricsService.GetLyricsAsync("Coldplay", "Adventure of a Lifetime");

// Print out lyrics in console
Console.WriteLine(lyrics);

Result
Turn your magic on
Umi she'd say
Everything you want's a dream away
And we are legends every day
That's what she told me

Turn your magic on
To me she'd say
[...]