Skip to content

Instantly share code, notes, and snippets.

@univrsal
Created October 21, 2016 18:00
Show Gist options
  • Save univrsal/aa9e08208c720058eae62062e2489dcf to your computer and use it in GitHub Desktop.
Save univrsal/aa9e08208c720058eae62062e2489dcf to your computer and use it in GitHub Desktop.
Grab songs from bandcamp
#!/bin/bash
if (( "$#" < 2 )); then
echo "Missing arguments!"
echo "args: [bandcamp album url] [save folder]"
fi
folder=$2
band_camp=( $(curl $1 | grep .mp3) )
title="$(wget $1 -O - | grep \<title\>|sed "s/\<title\>\([^<]*\).*/\1/")"
page_title=""
track_name="" # Copy unformated info over
track_link=""
album="$(echo $title | sed 's/^.\{2\}//')"
album="$(cutUntil $album \" \|\")"
artist="${title#*\|\ }"
entire_site=""
for item in "${band_camp[@]}"
do
entire_site="$entire_site $item" # Stitch the HTTP response back together to one string
done
delimter="\""
title_del="title\":\""
mp3_del="mp3-128\":\"//"
songs_left=true
while [[ $songs_left = true ]]; do
entire_site="${entire_site#*$title_del}"
track_name="${entire_site%%$delimter*}"
track_link="${entire_site#*$mp3_del}"
track_link="${track_link%%$delimter*}"
echo "Song: $artist - $album - $track_name"
echo "MP3 : $track_link"
echo "---"
wget $track_link -O "$folder/$artist - $album - $track_name.mp3"
if [[ $entire_site != *"title"* ]]; then
songs_left=false
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment