Skip to content

Instantly share code, notes, and snippets.

@companje companje/spotify.sh
Created Nov 30, 2014

Embed
What would you like to do?
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
You can’t perform that action at this time.