-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from KMen1/dev
Add Lyrics.Java support
- Loading branch information
Showing
36 changed files
with
1,159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Lyrics.Java | ||
|
||
The Lyrics.Java plugin for Lavalink allows you to fetch lyrics from YouTube or genius. The plugin will automatically fetch lyrics for the current track. | ||
|
||
Lavalink4NET provides an integration for the Lyrics.Java plugin with the [`Lavalink4NET.Integrations.LyricsJava`](https://www.nuget.org/packages/Lavalink4NET.Integrations.LyricsJava) package. | ||
|
||
## Installation | ||
|
||
For using Lyrics.Java, you need to install the [`Lavalink4NET.Integrations.LyricsJava`](https://www.nuget.org/packages/Lavalink4NET.Integrations.LyricsJava) package. | ||
|
||
:::caution | ||
You need to have the [LyricsJava](https://github.com/DuncteBot/java-timed-lyrics) plugin installed on your Lavalink server. | ||
::: | ||
|
||
## Usage | ||
|
||
First, you need to integrate the LyricsJava plugin with Lavalink4NET. You can do this by calling `UseLyricsJava` on either the host or the audio service: | ||
|
||
```csharp | ||
var app = builder.Build(); | ||
|
||
app.UseLyricsJava(); | ||
|
||
app.Run(); | ||
``` | ||
|
||
That's it! The LyricsJava plugin is now integrated with Lavalink4NET. | ||
|
||
### Getting lyrics for the current track | ||
|
||
For getting the lyrics of the current track, you can use the `GetCurrentTrackLyricsAsync` method. This method will return the lyrics of the current track. The method requires the session id and the guild id both of which you can get from player properties. | ||
|
||
```csharp | ||
var player = await audioService.Players | ||
.GetPlayerAsync(guildId) | ||
.ConfigureAwait(false); | ||
|
||
var lyrics = await audioService.Tracks | ||
.GetCurrentTrackLyricsAsync(player) | ||
.ConfigureAwait(false); | ||
``` | ||
|
||
### Getting lyrics from youtube | ||
|
||
For getting the lyrics of a youtube video, you can use the `GetYoutubeLyricsAsync` method. This method will return the lyrics of the youtube video. The method requires a youtube video id, which can be acquired by using the `SearchAsync` method if using a different provider (e.g. Spotify). | ||
|
||
```csharp | ||
var results = await AudioService.Tracks | ||
.SearchLyricsAsync("Queen - Bohemian Rhapsody") | ||
.ConfigureAwait(false); | ||
|
||
var videoId = results.First().VideoId; | ||
|
||
var lyrics = await AudioService.Tracks | ||
.GetYouTubeLyricsAsync(videoId) // Youtube Video Id (e.g. dQw4w9WgXcQ) | ||
.ConfigureAwait(false); | ||
``` | ||
|
||
### Getting lyrics from genius | ||
|
||
For getting the lyrics of a song from genius, you can use the `GetGeniusLyricsAsync` method. This method will return the lyrics of the song. The method requires the song name and the artist name. | ||
|
||
```csharp | ||
var lyrics = await AudioService.Tracks | ||
.GetGeniusLyricsAsync("Queen - Bohemian Rhapsody") | ||
.ConfigureAwait(false); | ||
``` | ||
|
||
## Player listener | ||
|
||
Similar to the inactivity tracking service, the LyricsJava integration also implements a player listener for receiving event notifications. The player listener can be used to receive notifications for when the lyrics of the current track has been loaded. | ||
|
||
```csharp | ||
public interface ILavaLyricsPlayerListener : ILavalinkPlayerListener | ||
{ | ||
ValueTask NotifyLyricsLoadedAsync(Lyrics lyrics, CancellationToken cancellationToken = default); | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
77 changes: 77 additions & 0 deletions
77
src/Lavalink4NET.Integrations.LyricsJava.Tests/HttpClientFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
namespace Lavalink4NET.Rest.Tests; | ||
|
||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.TestHost; | ||
using Microsoft.AspNetCore.WebSockets; | ||
|
||
[ExcludeFromCodeCoverage] | ||
internal sealed class HttpClientFactory : IHttpClientFactory, IAsyncDisposable | ||
{ | ||
private int _state; // 0 = build, 1 = run, 2 = disposed | ||
private readonly WebApplication _application; | ||
|
||
public HttpClientFactory() | ||
{ | ||
var builder = WebApplication.CreateBuilder(); | ||
builder.WebHost.UseTestServer(); | ||
builder.Services.AddWebSockets(x => { }); | ||
|
||
_application = builder.Build(); | ||
} | ||
|
||
public void Start() | ||
{ | ||
var state = Interlocked.CompareExchange(ref _state, 1, 0); | ||
ObjectDisposedException.ThrowIf(state is 2, this); | ||
|
||
if (state is 1) | ||
{ | ||
throw new InvalidOperationException("The application is already running."); | ||
} | ||
|
||
Debug.Assert(state is 0); | ||
_ = _application.RunAsync(); | ||
} | ||
|
||
public WebApplication Application | ||
{ | ||
get | ||
{ | ||
ObjectDisposedException.ThrowIf(_state is 2, this); | ||
|
||
if (_state is not 0) | ||
{ | ||
throw new InvalidOperationException("The application can not be accessed after starting it."); | ||
} | ||
|
||
return _application; | ||
} | ||
} | ||
|
||
public HttpClient CreateClient(string name) | ||
{ | ||
ObjectDisposedException.ThrowIf(_state is 2, this); | ||
|
||
if (_state is not 1) | ||
{ | ||
throw new InvalidOperationException("The application must be started before creating a client."); | ||
} | ||
|
||
return _application.GetTestServer().CreateClient(); | ||
} | ||
|
||
public ValueTask DisposeAsync() | ||
{ | ||
var state = Interlocked.CompareExchange(ref _state, 2, 1); | ||
|
||
if (state is not 1) | ||
{ | ||
return default; | ||
} | ||
|
||
return _application.DisposeAsync(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...alink4NET.Integrations.LyricsJava.Tests/Lavalink4NET.Integrations.LyricsJava.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.7" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0" /> | ||
<PackageReference Include="Moq" Version="4.18.4" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Lavalink4NET.Integrations.LyricsJava\Lavalink4NET.Integrations.LyricsJava.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.