Skip to content

Instantly share code, notes, and snippets.

@Klepvink
Created December 5, 2019 17:58
Show Gist options
  • Save Klepvink/14d6639cd5d0cefc1fe2f0f4a5548f08 to your computer and use it in GitHub Desktop.
Save Klepvink/14d6639cd5d0cefc1fe2f0f4a5548f08 to your computer and use it in GitHub Desktop.
[Spotify] Automagically add (bulk) music to a playlist using a textfile. This requires a token from spotify.
#!/bin/bash
## This script was made for my own projects, and might not work as expected for your projects.
## ██████╗██╗ ██╗ █████╗ ███╗ ██╗ ██████╗ ███████╗ ████████╗██╗ ██╗██╗███████╗██╗
## ██╔════╝██║ ██║██╔══██╗████╗ ██║██╔════╝ ██╔════╝ ╚══██╔══╝██║ ██║██║██╔════╝██║
## ██║ ███████║███████║██╔██╗ ██║██║ ███╗█████╗ ██║ ███████║██║███████╗██║
## ██║ ██╔══██║██╔══██║██║╚██╗██║██║ ██║██╔══╝ ██║ ██╔══██║██║╚════██║╚═╝
## ╚██████╗██║ ██║██║ ██║██║ ╚████║╚██████╔╝███████╗ ██║ ██║ ██║██║███████║██╗
## ╚═════╝╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝╚═╝╚══════╝╚═╝
## Enter your bearer OAuth token here. For more information, go to https://developer.spotify.com/console/post-playlist-tracks/
bearer="<ENTER BEARER API KEY HERE>"
##=== Script begins here===###
echo ""
echo -e " |~~~~~~~~|"
echo -e " |~~~~~~~~|"
echo -e " | |"
echo -e "/~~\| /~~\|"
echo -e "\__/ \__/"
echo ""
echo -e "Spotify automatic music adder"
echo -e "Klepvink 2019"
echo ""
read -p "[?] Enter file name here > " file
## This count can be incorrect. I noticed problems when importing a list from a windows machine.
## If the script doesn't work, try to run dos2unix on the given textfile. This will not change the information in the document.
lines=$(wc -l < $file)
read -p "[?] Enter playlist ID here > " playlistID
echo -e "\e[31m[!]\e[0m File contains $lines lines. Script will start in 3 seconds..."
sleep 3
for f in $(cat $file);
do
curl -X "POST" "https://api.spotify.com/v1/playlists/$playlistID/tracks?uris=$f" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $bearer"
echo ""
count=$(($lines-1))
lines=$count
echo -e "\e[32m[+]\e[0m Song added, $lines more to go!"
done
echo -e "\e[32m[+]\e[0m All done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment