Shoegaze.LastFM
1.1.0
dotnet add package Shoegaze.LastFM --version 1.1.0
NuGet\Install-Package Shoegaze.LastFM -Version 1.1.0
<PackageReference Include="Shoegaze.LastFM" Version="1.1.0" />
<PackageVersion Include="Shoegaze.LastFM" Version="1.1.0" />
<PackageReference Include="Shoegaze.LastFM" />
paket add Shoegaze.LastFM --version 1.1.0
#r "nuget: Shoegaze.LastFM, 1.1.0"
#:package Shoegaze.LastFM@1.1.0
#addin nuget:?package=Shoegaze.LastFM&version=1.1.0
#tool nuget:?package=Shoegaze.LastFM&version=1.1.0
Shoegaze.LastFM
A modern C# wrapper for the LastFM API.
API Implementation Status
| Category | Progress |
|---|---|
| Album | |
| Artist | |
| Chart | |
| Geo | |
| Library | |
| Tag | |
| Track | |
| User |
Quickstart
Creating a Client
To do any API requests at all you need to instanciate a LastfmClient. You will need to supply your API key and your API secret that you can obtain by creating an API account.
var client = new LastfmClient(apiKey, apiSecret, httpClient);
// you can then call any method that does not require user authentication
var response = await client.user.GetRecentTracksAsync("testUser");
var tracks = response.Data.Items;
All API responses contain error information in case something went wrong.
Getting a Session Key
To be able to do authenticated requests (like scrobbling or adding tracks) you will need a session key granted by the user.
There are two ways to obtain a session key:
1. Automatic Desktop Flow
Use AuthenticateAsync(). This opens the user’s default browser, listens on a temporary http://localhost:{port}/ URL, and automatically exchanges the returned token for a session key.
var auth = new LastfmAuthService(apiKey, apiSecret, httpClient);
var session = await auth.AuthenticateAsync();
Console.WriteLine($"Logged in as {session.User} with key {session.Key}");
2. Manual Flow
Use GetAuthorizationUrlAsync(callbackUrl) with your own callback URL (e.g. a webserver endpoint or custom URI scheme). Redirect the user there, capture the token from Last.fm’s redirect, and then call GetSessionAsync(token) to complete authentication and get a session key.
var auth = new LastfmAuthService(http, apiKey, apiSecret);
var authUrl = await auth.GetAuthorizationUrlAsync("https://myapp.com/callback");
// redirect the user to authUrl and receive the ?token=... in your callback handler
var token = "...";
var session = await auth.GetSessionAsync(token);
Console.WriteLine($"Logged in as {session.User} with key {session.Key}");
Authenticated Requests
After creating a LastfmClient and getting your session key, you can 'authenticate' the client.
var auth = new LastfmAuthService(apiKey, apiSecret, httpClient);
var session = await auth.AuthenticateAsync();
var client = new LastfmClient(apiKey, apiSecret, httpClient);
client.SetSessionKey(session.Key);
// you can then call any method on the client that requires authentication
var response = await client.Artist.AddTagsAsync("My Bloody Valentine", "shoegaze");
Scrobbling
You can scrobble batches of up to 50 scrobbles at once. Scrobbling requires an authenticated client.
var scrobble = new ScrobbleData(artistName: "My Bloody Valentine", trackName: "Loomer", playedAt: DateTime.UtcNow);
var response = await client.Track.ScrobbleAsync(scrobble);
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.1)
- Microsoft.Extensions.Http (>= 10.0.1)
- System.Text.Json (>= 10.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Shoegaze.LastFM:
| Package | Downloads |
|---|---|
|
Scrubbler.MediaPlayerScrobblerBase
Base abstractions for Scrubbler media player plugins. |
GitHub repositories
This package is not used by any popular GitHub repositories.