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;
using SoundCloudExplode.Common;
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")
.CollectAsync(20);
// OR
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
);You can also enumerate the tracks iteratively without waiting for the whole list to load:
using SoundCloudExplode;
var soundcloud = new SoundCloudClient();
await foreach (var track in soundcloud.Playlists.GetTracksAsync(
"https://soundcloud.com/tommy-enjoy/sets/aimer"
))
{
var title = track.Title;
var duration = track.Duration;
}If you need precise control over how many requests you send to Soundcloud, use Playlists.GetTrackBatchesAsync(...) which returns tracks wrapped in batches:
using SoundCloudExplode;
var soundcloud = new SoundCloudClient();
// Each batch corresponds to one request
await foreach (var batch in soundcloud.Playlists.GetTrackBatchesAsync(
"https://soundcloud.com/tommy-enjoy/sets/aimer"
))
{
foreach (var track in batch.Items)
{
var title = track.Title;
var duration = track.Duration;
}
}using System;
using System.IO;
using SoundCloudExplode;
var soundcloud = new SoundCloudClient();
var track = await soundcloud.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
);