Skip to content

Instantly share code, notes, and snippets.

@jessetane
Last active December 18, 2015 14:39
Show Gist options
  • Save jessetane/5799054 to your computer and use it in GitHub Desktop.
Save jessetane/5799054 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
# infos
artist="Kanye West"
album="Yeezus"
tracks=(
"On Sight"
"Black Skinhead"
"I Am A God"
"New Slaves"
"Hold My Liquor"
"I'm In It"
"Blood On The Leaves"
"Guilt Trip"
"Send It Up"
"Bound"
)
urls=(
"http://rockdizfile.com/mp3embed-trjddcu5q599.mp3"
"http://rockdizfile.com/mp3embed-mpa09iwlew1n.mp3"
"http://rockdizfile.com/mp3embed-mkghsf0whgdf.mp3"
"http://rockdizfile.com/mp3embed-ezr2pe7341r7.mp3"
"http://rockdizfile.com/mp3embed-38u68vypqrjl.mp3"
"http://rockdizfile.com/mp3embed-6hnm7xk4hhcx.mp3"
"http://rockdizfile.com/mp3embed-cxh8oyxm48he.mp3"
"http://rockdizfile.com/mp3embed-li69nww7u8p9.mp3"
"http://rockdizfile.com/mp3embed-sij1ow9h9on9.mp3"
"http://rockdizfile.com/mp3embed-xss9zucsymps.mp3"
)
# vars
ua="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_3) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.65 Safari/537.31"
folder=~/Desktop/"$album"
i=0
main() {
greet
make_folder
get_tracks
dismiss
}
greet() {
echo "this program will download ${artist}'s $album to: $folder"
echo -n "proceed? [Y/n]: "
{
read proceed < /dev/tty
test "$proceed" = "" ||
test "$proceed" = "y" ||
test "$proceed" = "Y"
}
}
make_folder() {
if [ ! -d "$folder" ]; then
echo "creating folder: $folder"
mkdir -p "$folder"
fi
cd "$folder"
}
get_tracks() {
for url in ${urls[@]}; do
num="$((i+1))"
[ "${#num}" = 1 ] && num="0$num"
filename="${artist}-${album}-${num}-${tracks[((i++))]}.mp3"
dest="$folder"/"$filename"
if [ ! -f "$dest" ]; then
echo "downloading: $filename"
curl -fL# --user-agent "$ua" "$url" -o "$dest"
fi
done
}
dismiss() {
echo "all done: $i files downloaded"
open .
}
# do it
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment