Automated Bandcamp Downloads

Automated Bandcamp Downloads
Photo by blocks / Unsplash

I almost exclusively use Bandcamp to buy music. And yes, I buy my music. I use BlackPlayer EX on Android to listen to my music.

The biggest challenge with Bandcamp is that there is friction between purchasing the digital album and then getting it loaded onto my Android. The only real supported path to downloading the .zip file of mp3's is to use Bandcamp's desktop site, and involves a mildly infuriating process:

1. Open up your Bandcamp collection

2. Click the download link of your chosen album

3. Click the download link on the download page

4. Wait for the slow Bandcamp download

5. Extract the contents of the .zip archive

6. Copy the files to smartphone

To add insult to injury, I use MacOS as my desktop OS, and for the life of me I cannot figure out how to copy files over USB from MacOS to Android. Yes, I know about the Android File Transfer app, but it doesn't seem to recognize my device.

So I'm left with Windows, which is where our technical fun begins.

My goal is to automate steps 1 through 5 above.

Automating the downloads

Steps 1 through 4 can be easily automated with the bandcamp-downloader that you can get from github.

On Windows, I wanted to create a simple .bat script so that I didn't have to remember the specific bandcamp-downloader.py command to run every time. Here's my script:

python c:\Users\mike\code\bandcamp-downloader\bandcamp-downloader.py ^
  kindohm ^  
  --download-since 2020-01-01 ^  
  --directory c:\Users\mike\bandcamp-downloaded ^  
  --filename-format "{artist}.{title}"

EASY.

Unzipping the archives

Then things got a little trickier. I don't know Windows batch file scripting very well. Anyway, this script will then loop through all .zip files in the download directory, create a new directory for each individual archive, and unzip the archive to the new directory:

for /R "C:\Users\mike\bandcamp-downloaded" %%I in ("*.zip") do (
  mkdir "%%~dpnI"
  "tar" -xf "%%~fI" -C "%%~dpnI"
)


I was pleasantly surprised to find that tar ships on Windows 11.

I had to do some digging to figure out how to come up with the right arguments to mkdir to create the directory before unzipping:

mkdir "%%~dpnI"
  • d == drive letter
  • p == parent directory
  • n == file name without extension

🤷‍♂️

Future Enhancements

  • delete the .zip files upon successful archive extraction
  • automatically copy to phone

Conclusion

So now I can just run these scripts whenever I want to refresh my local Bandcamp library.

Unfortunately I still have to manually copy the unzipped files to my smartphone by hand, but that ain't so bad.