Closed chepe263 closed 2 months ago
soundcloud.ts downloads the transcoded stream instead of the original downloadable file. Album art and other metadata are only available if the author adds metadata. So I don't recommend using it, just use SoundCloud data (artwork_url,...) if you need them.
If you still want to download it, you can use this following code:
import { Soundcloud } from "soundcloud.ts"
const sc = new Soundcloud()
const trackUrl = "your track url"
const track = await sc.tracks.getV2(trackUrl)
if (track.downloadable) {
const trackId = track.id
const { redirectUri: downloadUrl } = await sc.api.getV2(`/tracks/${trackId}/download`)
console.log(downloadUrl) // Or download it
}
It originally downloaded the original file if it was available, but a contributor removed it. I will reopen this to plan to revert that functionality.
Added in 0.5.5
you have to provide oauth token or it won't work and default to the mp3 stream
If you go to a track page, and click the three dots, there is a download button.
It makes a request to
https://api-v2.soundcloud.com/tracks/{trackId}/download?client_id={clientID}app_version={Some number}&app_locale=en
and it responds with
Is there a method in this library to do the same?
I tried with your example
But the files are different. The "download button" file is about 292mb mp3 with album art, quite similar to the download episode in podcast rss; and using the library I obtain a 116mb mp3 without album art, probably the soundcloud streaming file.
Podcast feed item example