Library that provides an interface to query metadata of SoundCloud tracks and playlists, as well as to resolve and download audio.
$ dotnet add package SoundCloudExplodeSoundCloudExplode is a library that provides an interface to query metadata of SoundCloud tracks and playlists, as well as to resolve and download streams.
dotnet add package SoundCloudExplode (main package)SoundCloudExplode exposes its functionality through a single entry point — the SoundCloudClient class.
Create an instance of this class and use the provided operations to send requests.
To retrieve the metadata associated with a Soundcloud track, call Tracks.GetAsync(...):
using SoundCloudExplode;
var soundcloud = new SoundCloudClient();
var track = await soundcloud.Tracks.GetAsync("https://soundcloud.com/purityy79/dororo-op-piano-sheet-in-description");
var title = track.Title;
var duration = track.Duration;
You can get the metadata associated with a Soundcloud playlist by calling Playlists.GetAsync(...) method:
using SoundCloudExplode;
var soundcloud = new SoundCloudClient();
//Get playlist info with all tracks
var playlist = await soundcloud.Playlists.GetAsync(
"https://soundcloud.com/tommy-enjoy/sets/aimer"
);
//Or Get only the playlist basic info without loading all tracks info
var playlist = await soundcloud.Playlists.GetAsync(
"https://soundcloud.com/tommy-enjoy/sets/aimer",
false
);
var title = playlist.Title;
var artworkUrl = playlist.ArtworkUrl;
var tracks = playlist.Tracks;
...To get the tracks included in a playlist, call Playlists.GetTracksAsync(...):
using SoundCloudExplode;
var soundcloud = new SoundCloudClient();
// Get all tracks in a playlist
var tracks = await soundcloud.Playlists.GetTracksAsync(
"https://soundcloud.com/tommy-enjoy/sets/aimer"
);
// Get only the first 20 playlist tracks
var tracksSubset = await soundcloud.Playlists
.GetTracksAsync(
"https://soundcloud.com/tommy-enjoy/sets/aimer",
limit: 20
);
//Setting offset
var tracksSubset = await soundcloud.Playlists
.GetTracksAsync(
"https://soundcloud.com/tommy-enjoy/sets/aimer",
offset: 10,
limit: 5
);Note: Use the same method as retrieving playlists to get albums because they are the same.
You can execute a search query and get its results by calling Search.GetResultsAsync(...). Each result may represent either a track, a playlist, an album, or a user, so you need to apply pattern matching to handle the corresponding cases:
using SoundCloudExplode;
var soundcloud = new SoundCloudClient();
var results = await soundcloud.Search.GetResultsAsync("banda neira");
foreach (var result in results)
{
// Use pattern matching to handle different results (tracks, playlists, users)
switch (result)
{
case TrackSearchResult track:
{
var id = track.Id;
var title = track.Title;
var duration = track.Duration;
break;
}
//NOTE: Soundcloud handles playlist and albums the same way.
case PlaylistSearchResult playlist:
{
var id = playlist.Id;
var title = playlist.Title;
break;
}
case UserSearchResult user:
{
var id = user.Id;
var title = user.Title;
var userName = user.Username;
var fullName = user.FullName;
break;
}
}
}using System;
using System.IO;
using SoundCloudExplode;
var soundcloud = new SoundCloudClient();
var track = await soundcloud.Tracks.GetAsync("https://soundcloud.com/purityy79/dororo-op-piano-sheet-in-description");
var trackName = string.Join("_", track.Title.Split(Path.GetInvalidFileNameChars()));
await soundcloud.DownloadAsync(track, $@"{Environment.CurrentDirectory}\Download\{trackName}.mp3");You can request the download url for a particular track by calling Tracks.GetDownloadUrlAsync(...):
using SoundCloudExplode;
var soundcloud = new SoundCloudClient();
var track = await soundcloud.Tracks.GetAsync("https://soundcloud.com/purityy79/dororo-op-piano-sheet-in-description");
var downloadUrl = await soundcloud.Tracks.GetDownloadUrlAsync(
track
);