Skip to content

Commit

Permalink
feat: Implement extended playlist information type
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Aug 15, 2023
1 parent 8e2f473 commit 119e1f4
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
namespace Lavalink4NET.Integrations.Lavasrc;

using System.Collections.Immutable;
using System.Text.Json.Nodes;
using Lavalink4NET.Rest.Entities.Tracks;

public readonly record struct ExtendedPlaylistInformation(PlaylistInformation Playlist)
{
public string Name => Playlist.Name;

public ExtendedLavalinkTrack? SelectedTrack
{
get
{
return Playlist.SelectedTrack is null
? null
: new ExtendedLavalinkTrack(Playlist.SelectedTrack);
}
}

public IImmutableDictionary<string, JsonNode> AdditionalInformation => Playlist.AdditionalInformation;

public PlaylistType? Type
{
get
{
var playlistType = AdditionalInformation["type"]?.ToString();

return playlistType switch
{
"album" => PlaylistType.Album,
"playlist" => PlaylistType.Playlist,
"artist" => PlaylistType.Artist,
"recommendations" => PlaylistType.Recommendations,
_ => null
};
}
}

public Uri? Uri
{
get
{
var uri = AdditionalInformation["url"]?.ToString();
return uri is null ? null : new Uri(uri);
}
}

public Uri? ArtworkUri
{
get
{
var artworkUri = AdditionalInformation["artworkUrl"]?.ToString();
return artworkUri is null ? null : new Uri(artworkUri);
}
}

public string? Author => AdditionalInformation["author"]?.ToString();

public int? TotalTracks => AdditionalInformation["totalTracks"]?.GetValue<int>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Lavalink4NET.Abstractions\Lavalink4NET.Abstractions.csproj" />
<ProjectReference Include="..\Lavalink4NET\Lavalink4NET.csproj" />
</ItemGroup>

</Project>
9 changes: 9 additions & 0 deletions src/Lavalink4NET.Integrations.Lavasrc/PlaylistType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Lavalink4NET.Integrations.Lavasrc;

public enum PlaylistType : byte
{
Album,
Playlist,
Artist,
Recommendations,
}

0 comments on commit 119e1f4

Please sign in to comment.