Skip to content

Downloading Music

har-nick edited this page Oct 27, 2025 · 3 revisions

Preface

This would normally go under Usage, however this is more involved affair so I figured it deserved its own page.

Download links returned by Bandcamp aren't direct. They link to a sort of "gateway", where the user can pick their desired format before downloading. BandKit gets around this by scraping this gateway page's HTML for direct links contained within.

Getting Your Download Links

BandKit provides links to download data at OwnedLibraryItemsResponse.downloadUrls as a Map.

Each key is the purchase ID of the item, prefixed with p, e.g: p123456789. Typically, this prefix is reserved for "Package" items, which are purchases that include physical items, like merchandise or records, however this isn't the case here. All items, regardless of their "type" are prefixed with p.

You can filter the results to get the gateway for the item you want like so:

val downloadUrlKey = "p${it.saleId}"
val downloadUrl = downloadUrls[downloadUrlKey] ?: throw Exception("Could not find download link at key: $downloadUrlKey")

Once done, you can use BandKit.fetchItemDownloadLinks to return a collection of supported codecs as keys, with their associated direct links as values.

Caveats on Writing Data to Disk

Bandcamp provides albums as a zip archive, which is simple enough to handle, but Track-type items (purchases which consist of a single track) are returned as their associated file type.

For ease of use, BandKit includes the relevant extension for each codec in BandKit.Encoding for you to reference when writing data to a file.

Clone this wiki locally