Skip to content

Instantly share code, notes, and snippets.

@leif
Created August 25, 2013 11:37
Show Gist options
  • Save leif/6333406 to your computer and use it in GitHub Desktop.
Save leif/6333406 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""
This is a quick hack for downloading albums from Bandcamp.
This functionality should really be added to youtube-dl, but I'm lazy and just
wanted to listen to an album on a computer without flash so I wrote this. Somone,
please add bandcamp support to youtube-dl!
Instructions: give this a bandcamp album's HTML on stdin, and it gives you a
bash script on stdout which will download it. There is no sanitization of the
downloaded data, so you should probably read the bash script before running it
to ensure there isn't anything bad in there! For example:
curl http://bandcamp... | python bandcamp-dl.py > download.sh
cat download.sh # read it to make sure it looks sane
bash download.sh
I'd like to add a note here thanking bandcamp for intentionally making this
pretty easy, and having a FAQ entry for artists about how it would be pointless
to make it slightly more difficult by obfuscating it. I do wish the FAQ entry
didn't use the word "steal", and I wish bandcamp would offer an HTML5 player in
additon to the Flash player - I really just wanted to *listen* to something!
But anyway, thank you Bandcamp for not excessively obfuscating your mp3 URLs.
"""
import sys, json, re
data = sys.stdin.read()
artist = re.search( 'artist: "([^"]+)"', data ).groups()[0]
albumdata = json.loads(re.search( 'current: ({.+?})', data).groups()[0])
trackdata = json.loads(re.search( 'trackinfo : (\[.+?\])', data).groups()[0])
print 'set -ex'
print "mkdir -p '%s/%s'" % (artist, albumdata["title"])
for track in trackdata:
print "wget -O '%s/%s/%.2d. %s.mp3' '%s'" % (artist, albumdata["title"], track["track_num"], track["title"].replace("'","\\'"), track["file"]["mp3-128"])
@leif
Copy link
Author

leif commented May 12, 2014

Note: youtube-dl has bandcamp support now, you should use it instead of this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment