Skip to content

Instantly share code, notes, and snippets.

@calebccff
Last active May 19, 2020 13:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save calebccff/e4320f0d3a4577f1a9819d901d43fc93 to your computer and use it in GitHub Desktop.
Save calebccff/e4320f0d3a4577f1a9819d901d43fc93 to your computer and use it in GitHub Desktop.
Download all albums for an artist from bandcamp using bandcamp-dl
#!/bin/bash
# bandcamp-multidl.sh URL [DESTINATION]
if [ -z $1 ]; then
echo "No URL specified"
exit 1
fi
if [ ! which bandcamp-dl ]; then
echo "Can't find bandcamp-dl in PATH, please install it"
exit 1
fi
die() {
echo "Something went wrong"
exit 1
}
FULL_URL=$1
ARTIST_NAME=$(echo $FULL_URL | cut -d"/" -f3 | cut -d "." -f1)
BASE_URL="https://$(echo $FULL_URL | cut -d"/" -f3)"
echo "Artist URL: $BASE_URL"
echo "Artist name: $ARTIST_NAME"
if [ ! -z $2 ]; then
DOWNLOAD_DIR=$2
else
DOWNLOAD_DIR="$(pwd)/$ARTIST_NAME"
fi
mkdir $DOWNLOAD_DIR || die
pushd $DOWNLOAD_DIR
echo "Downloading to $(pwd)/$ARTIST_NAME"
ALBUMS=$(curl -s "$FULL_URL/music" | grep "href=\"/album" | cut -d"\"" -f2)
echo "Albums found:"
echo -e $ALBUMS | tr " " "\n"
# $ALBUMS:
# /album/xys
# /track/abc
# For each line in ALBUMS
while IFS= read -r album; do
ALBUM=$BASE_URL$album
echo
echo "Downloading: $album with bandcamp-dl"
echo "$ALBUM"
bandcamp-dl $ALBUM || die
done <<< "$ALBUMS"
popd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment