Skip to content

Instantly share code, notes, and snippets.

@romdim
Last active February 8, 2018 15:36
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 romdim/5a265af69b747e172f7a6949d4e788ed to your computer and use it in GitHub Desktop.
Save romdim/5a265af69b747e172f7a6949d4e788ed to your computer and use it in GitHub Desktop.
8tracks playlist songs downloader using youtube-dl and bash script magic
#!/bin/bash
# Curl the url, get 1-line that contains the mix id, keep only that, remove prefixes and suffixes, add the json url we need for getting the tracklist
url=$(curl https://8tracks.com/$1 | grep embedUrl | awk {'print $3'} | sed -e 's#content="##g' -e 's#player_v3_universal/autoplay"##g' | sed 's/$/tracks_for_international.jsonh/')
# Curl the url that contains tracklist
tracks=$(curl $url)
# Get number of tracks
count=$(echo $tracks | jq '.tracks | length - 1')
# For all tracks download each one
for i in $(seq 0 $count)
do
# Get performer - title in order to search for it
track=$(echo $tracks | jq '(.tracks['"$i"'].performer + " - " + .tracks['"$i"'].name)' | sed "s/\"/'/g")
# Name of the track to save
unquoted_track=$(echo $track | sed "s/'//g")
# If track number less than 10, then make it 01, 02, ..
if [ $i -lt 9 ]
then
number=$(echo "0$((i+1))")
else
number=$(echo $((i+1)))
fi
# Actually download the song by using best available audio (extension), only 1, without playlist, by using string search and output into our folder using correct track number-name.extension
youtube-dl -q -f bestaudio --max-downloads 1 --no-playlist --default-search ${2:-ytsearch} -o "~/Music/8tracks/$1/$number-$unquoted_track.%(ext)s" "${track}"
done

Just did it for experimentation. Not encouraging piracy.

The command to run would be: sh 8tracks-dl.sh username/playlist-title

Cheers!

PS: you need youtube-dl and jq to make it work..

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