SHARE
TWEET

Untitled

a guest Apr 18th, 2019 401 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. TOKEN=$(cat $HOME/.spottoken | jq '.access_token' | tr -d '"')
  2.  
  3. SP_VERSION="0.1"
  4. SP_DEST="org.mpris.MediaPlayer2.spotifyd"
  5. SP_PATH="/org/mpris/MediaPlayer2"
  6. SP_MEMB="org.mpris.MediaPlayer2.Player"
  7.  
  8. function spotsend(){
  9.     dbus-send --print-reply --dest=$SP_DEST $SP_PATH $SP_MEMB.$1 ${*:2} > /dev/null
  10. }
  11.  
  12. function openuri(){
  13.     spotsend OpenUri string:$1
  14. }
  15.  
  16.  
  17. function pause(){
  18.     curl -X "PUT" "https://api.spotify.com/v1/me/player/pause" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN"
  19. }
  20. function play(){
  21.     curl -X "PUT" "https://api.spotify.com/v1/me/player/play" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN"
  22. }
  23.  
  24. function next(){
  25.     curl -X "POST" "https://api.spotify.com/v1/me/player/next" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN"
  26. }
  27.  
  28. function prev(){
  29.     curl -X "POST" "https://api.spotify.com/v1/me/player/previous" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN"
  30. }
  31. function chvol(){
  32.     curl -X "PUT" "https://api.spotify.com/v1/me/player/volume?volume_percent=$1" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN"
  33. }
  34.  
  35. function help(){
  36.     echo "pause - pauses"
  37.     echo "play - resumes playback"
  38.     echo "next - moves to next song"
  39.     echo "prev - moves to previous song (or seek to beginning)"
  40.     echo "search <query> - grabs first song matching query"
  41.     echo "chvol % - changes volume to %"
  42. }
  43.  
  44. function search(){
  45.   #type=$1
  46.   #shift
  47.   Q="$@"
  48.   SPTFY_URI=$(
  49.         curl -s -G --data-urlencode "q=$Q" https://api.spotify.com/v1/search\?type=track\&market=US\&limit=10 -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" | jq '.tracks.items[].uri' | tr -d '"' | shuf | head -n1
  50.   )
  51.   echo $SPTFY_URI
  52.   openuri $SPTFY_URI
  53. }
  54.  
  55. function rlib(){
  56.     SPTFY_URI=$(
  57.     curl -X "GET" "https://api.spotify.com/v1/me/tracks?market=US&limit=50" -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" | jq '.items[].track.uri' | shuf | tr -d '"' | head -n1
  58.     )
  59.     echo $SPTFY_URI
  60.     openuri $SPTFY_URI
  61. }
  62.  
  63. $@
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top