SpotifyExplode is a library that provides an interface to query metadata of Spotify tracks, playlists, albums, artists and users as well as to download audio.
dotnet add package SpotifyExplode
SpotifyExplode exposes its functionality through a single entry point — the SpotifyClient
class.
Create an instance of this class and use the provided operations to send requests.
To retrieve the metadata associated with a Spotify track, call Tracks.GetAsync(...)
:
using SpotifyExplode;
var spotify = new SpotifyClient();
var track = await spotify.Tracks.GetAsync(
"https://open.spotify.com/track/0VjIjW4GlUZAMYd2vXMi3b"
);
var title = track.Title;
var duration = track.DurationMs;
You can get the metadata associated with a Spotify playlist by calling Playlists.GetAsync(...)
method:
using SpotifyExplode;
var spotify = new SpotifyClient();
//Get playlist info
var playlist = await spotify.Playlists.GetAsync(
"https://open.spotify.com/playlist/0tSYjDUflcozy78WwUFe6y"
);
var title = playlist.Name;
var artworkUrl = playlist.Followers;
var tracks = playlist.Tracks;
...
To get the tracks included in a playlist, call Playlists.GetTracksAsync(...)
:
using SpotifyExplode;
var spotify = new SpotifyClient();
// Get all tracks in a playlist
var tracks = await spotify.Playlists.GetAllTracksAsync(
"https://open.spotify.com/playlist/0tSYjDUflcozy78WwUFe6y"
);
// Get only the first 20 playlist tracks
var tracksSubset = await spotify.Playlists.GetTracksAsync(
"https://open.spotify.com/playlist/0tSYjDUflcozy78WwUFe6y",
limit: 20
);
//Setting offset
var tracksSubset = await spotify.Playlists.GetTracksAsync(
"https://open.spotify.com/playlist/0tSYjDUflcozy78WwUFe6y",
offset: 3,
limit: 20
);
You can get the metadata associated with a Spotify album by calling Albums.GetAsync(...)
method:
using SpotifyExplode;
var spotify = new SpotifyClient();
//Get album info with all tracks
var album = await spotify.Albums.GetAsync(
"https://open.spotify.com/album/336m0kejdM5Fkw2HUX46Bw?si=549f3fdb0cfd46e6"
);
var title = album.Name;
var artists = album.Artists;
var tracks = album.Tracks;
...
To get the tracks included in a album, call Albums.GetTracksAsync(...)
:
using SpotifyExplode;
var spotify = new SpotifyClient();
// Get all tracks in a album
var tracks = await spotify.Albums.GetAllTracksAsync(
"https://open.spotify.com/album/336m0kejdM5Fkw2HUX46Bw?si=549f3fdb0cfd46e6"
);
// Get only the first 20 album tracks
var tracksSubset = await spotify.Albums.GetTracksAsync(
"https://open.spotify.com/album/336m0kejdM5Fkw2HUX46Bw?si=549f3fdb0cfd46e6",
limit: 20
);
//Setting offset
var tracksSubset = await spotify.Albums.GetTracksAsync(
"https://open.spotify.com/album/336m0kejdM5Fkw2HUX46Bw?si=549f3fdb0cfd46e6",
offset: 3,
limit: 20
);
You can get the metadata associated with a Spotify artist by calling Artists.GetAsync(...)
method:
using SpotifyExplode;
var spotify = new SpotifyClient();
//Get artist info
var artist = await spotify.Artists.GetAsync(
"https://open.spotify.com/artist/0bAsR2unSRpn6BQPEnNlZm?si=d3b6e78f96ce45b9"
);
var title = artist.Name;
var albums = artist.Albums;
To get the tracks included in an artist, call Artists.GetAlbumsAsync(...)
:
using SpotifyExplode;
var spotify = new SpotifyClient();
// Get all albums in an artist
var albums = await spotify.Artists.GetAllAlbumsAsync(
"https://open.spotify.com/artist/0bAsR2unSRpn6BQPEnNlZm?si=d3b6e78f96ce45b9"
);
// Get only the first 20 artist albums
var albumsSubset = await spotify.Artists.GetAlbumsAsync(
"https://open.spotify.com/artist/0bAsR2unSRpn6BQPEnNlZm?si=d3b6e78f96ce45b9",
limit: 20
);
//Setting offset
var albumsSubset = await spotify.Artists.GetAlbumsAsync(
"https://open.spotify.com/artist/0bAsR2unSRpn6BQPEnNlZm?si=d3b6e78f96ce45b9",
offset: 3,
limit: 20
);
You can get the metadata associated with a Spotify user by calling Users.GetAsync(...)
method:
using SpotifyExplode;
var spotify = new SpotifyClient();
//Get user info
var user = await spotify.Users.GetAsync(
"https://open.spotify.com/user/xxu0yww90v07gbh9veqta7ze0"
);
var name = user.DisplayName;
var followers = user.Followers;
var images = user.Images;
You can execute a search query and get its results by calling Search.GetResultsAsync(...)
. Each result may represent either an album, artist, track or playlist, so you need to apply pattern matching to handle the corresponding cases:
using SpotifyExplode;
var spotify = new SpotifyClient();
foreach (var result in await spotify.Search.GetResultsAsync("banda neira"))
{
// Use pattern matching to handle different results (albums, artists, tracks, playlists)
switch (result)
{
case TrackSearchResult track:
{
var id = track.Id;
var title = track.Title;
var duration = track.DurationMs;
break;
}
case PlaylistSearchResult playlist:
{
var id = playlist.Id;
var title = playlist.Name;
break;
}
case AlbumSearchResult album:
{
var id = album.Id;
var title = album.Name;
var artists = album.Artists;
var tracks = album.Tracks;
break;
}
case ArtistSearchResult artist:
{
var id = artist.Id;
var title = artist.Name;
break;
}
}
}
You can get the download url from a track by calling Tracks.GetDownloadUrlAsync(...)
.
using SpotifyExplode;
var spotify = new SpotifyClient();
var downloadUrl = await spotify.Tracks.GetDownloadUrlAsync(
"https://open.spotify.com/track/0VjIjW4GlUZAMYd2vXMi3b"
);
// Start download from the url provided...
You can get a Youtube ID from a track by calling Tracks.GetYoutubeIdAsync(...)
.
using SpotifyExplode;
var spotify = new SpotifyClient();
var youtubeId = await spotify.Tracks.GetYoutubeIdAsync(
"https://open.spotify.com/track/0VjIjW4GlUZAMYd2vXMi3b"
);
var youtubeUrl = "https://youtube.com/watch?v=" + youtubeId;