#!/usr/bin/env bash function spotify() { # Copyright (c) 2012--2023 Harish Narayanan # # Contains numerous helpful contributions from Jorge Colindres, Thomas # Pritchard, iLan Epstein, Gabriele Bonetti, Sean Heller, Eric Martin # and Peter Fonseca. # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. USER_CONFIG_DEFAULTS="CLIENT_ID=\"\"\nCLIENT_SECRET=\"\""; USER_CONFIG_FILE="${HOME}/.shpotify.cfg"; if ! [[ -f "${USER_CONFIG_FILE}" ]]; then touch "${USER_CONFIG_FILE}"; echo -e "${USER_CONFIG_DEFAULTS}" > "${USER_CONFIG_FILE}"; fi source "${USER_CONFIG_FILE}"; # Set the percent change in volume for vol up and vol down VOL_INCREMENT=10 showAPIHelp() { echo; echo "Connecting to Spotify's API:"; echo; echo " This command line application needs to connect to Spotify's API in order to"; echo " find music by name. It is very likely you want this feature!"; echo; echo " To get this to work, you need to sign up (or in) and create an 'Application' at:"; echo " https://developer.spotify.com/dashboard/create"; echo; echo " Once you've created an application, find the 'Client ID' and 'Client Secret'"; echo " values, and enter them into your shpotify config file at '${USER_CONFIG_FILE}'"; echo; echo " Be sure to quote your values and don't add any extra spaces!"; echo " When done, it should look like this (but with your own values):"; echo ' CLIENT_ID="abc01de2fghijk345lmnop"'; echo ' CLIENT_SECRET="qr6stu789vwxyz"'; } showHelp () { echo "Usage:"; echo; echo " `basename $0` "; echo; echo "Commands:"; echo; echo " play # Resumes playback where Spotify last left off."; echo " play # Finds a song by name and plays it."; echo " play album # Finds an album by name and plays it."; echo " play artist # Finds an artist by name and plays it."; echo " play list # Finds a playlist by name and plays it."; echo " play uri # Play songs from specific uri."; echo; echo " next # Skips to the next song in a playlist."; echo " prev # Returns to the previous song in a playlist."; echo " replay # Replays the current track from the beginning."; echo " pos