Skip to content

Instantly share code, notes, and snippets.

@companje
Created November 30, 2014 20:29
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 companje/3b229c4eb22a4d8199a5 to your computer and use it in GitHub Desktop.
Save companje/3b229c4eb22a4d8199a5 to your computer and use it in GitHub Desktop.
shell script to request Spotify track ID for a song or a whole playlist
function spotify() {
count=$[$count+1]
id=`curl --silent -G --data-urlencode "q=$1" "https://api.spotify.com/v1/search?&type=artist,track" -H "Accept: application/json" |
grep "spotify:track:" |
head -n 1 |
cut -c 16-51`
if [ -z "$id" ] ; then
>&2 echo -e "\033[0;31m$1\033[0m"
else
>&2 echo -e "\033[0;92m$1\033[0m"
echo $id
fi
}
if [ $# -eq 0 ] ; then
echo ""
echo "┌─┐┌─┐┌─┐┌┬┐┬┌─┐┬ ┬";
echo "└─┐├─┘│ │ │ │├┤ └┬┘";
echo "└─┘┴ └─┘ ┴ ┴└ ┴ ";
echo ""
echo "usage:"
echo " spotify songs.txt > output.txt"
echo " spotify Artist - Song > output.txt"
echo ""
echo ""
echo "when the script is finished:"
echo " 1. copy output to clipboard."
echo " 2. paste in a Spotify playlist"
echo ""
exit
fi
count=0
if [ -f "$1" ]
then
while read line
do
spotify "$line"
done < $1
else
spotify "${*:1}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment