|
| 1 | +Rebol [ |
| 2 | + Title: "Test Spotify module" |
| 3 | + Date: 02-Jul-2020 |
| 4 | + Author: "Oldes" |
| 5 | + File: %test-spotify.r3 |
| 6 | + Version: 0.1.0 |
| 7 | + Require: 3.1.2 |
| 8 | + Note: { |
| 9 | + Spotify API is still in Beta, and some bugs still happens... |
| 10 | + like this one: https://github.com/spotify/web-api/issues/1594 |
| 11 | + } |
| 12 | +] |
| 13 | + |
| 14 | +do %spotify.reb |
| 15 | + |
| 16 | +system/options/log/http: 1 ; for verbose output |
| 17 | +try/except [ |
| 18 | +spotify: system/modules/spotify/authorize [ |
| 19 | + client-id: {8a01eb3b22ee4ba3b310e5e4fe10fd68} |
| 20 | + ; optional client-secret may be used for classic "Authorization Code Flow" |
| 21 | + ; if not used, the authentication will use PKCE extension, which is recommended |
| 22 | + ;client-secret: {00000000000000000000000000000000} |
| 23 | + scope: [ |
| 24 | + ;@@ In real app not all scopes may be required! |
| 25 | + ;@@ https://developer.spotify.com/documentation/general/guides/scopes/ |
| 26 | + ;- Images |
| 27 | + ;@ugc-image-upload ; Write access to user-provided images. |
| 28 | + ;- Spotify Connect |
| 29 | + @user-read-playback-state ; Read access to a user’s player state. |
| 30 | + @user-modify-playback-state ; Write access to a user’s playback state |
| 31 | + @user-read-currently-playing ; Read access to a user’s currently playing content. |
| 32 | + ;- Playback |
| 33 | + @streaming ; Control playback of a Spotify track. (Web Playback SDK and Premium only) |
| 34 | + @app-remote-control ; Remote control playback of Spotify. (iOS and Android SDK only) |
| 35 | + ;- Users |
| 36 | + @user-read-email ; Read access to user’s email address. |
| 37 | + @user-read-private ; Read access to user’s subscription details (type of user account). |
| 38 | + ;- Playlists |
| 39 | + @playlist-read-collaborative ; Include collaborative playlists when requesting a user's playlists. |
| 40 | + @playlist-modify-public ; Write access to a user's public playlists. |
| 41 | + @playlist-read-private ; Read access to user's private playlists. |
| 42 | + @playlist-modify-private ; Write access to a user's private playlists. |
| 43 | + ;- Library |
| 44 | + @user-library-modify ; Write/delete access to a user's "Your Music" library. |
| 45 | + @user-library-read ; Read access to a user's "Your Music" library. |
| 46 | + ;- Listening History |
| 47 | + @user-top-read ; Read access to a user's top artists and tracks. |
| 48 | + @user-read-playback-position ; Read access to a user’s playback position in a content. |
| 49 | + @user-read-recently-played ; Read access to a user’s recently played tracks. |
| 50 | + ;- Follow |
| 51 | + @user-follow-read ; Read access to the list of artists and other users that the user follows. |
| 52 | + @user-follow-modify ; Write/delete access to the list of artists and other users that the user follows. |
| 53 | + ] |
| 54 | +] |
| 55 | +][ probe system/state/last-error ] |
| 56 | + |
| 57 | +unless spotify [ |
| 58 | + print "*** Access to Spotify API failed!" |
| 59 | + halt |
| 60 | +] |
| 61 | + |
| 62 | + |
| 63 | +spot?: function [ |
| 64 | + "Prints information what is currently playin thru Spotify" |
| 65 | +][ |
| 66 | + log: system/options/log/http |
| 67 | + system/options/log/http: 0 |
| 68 | + track: spotify/get %me/player/currently-playing |
| 69 | + unless track [ |
| 70 | + print "No device!" |
| 71 | + exit |
| 72 | + ] |
| 73 | + track: load-json track |
| 74 | + print ["Song: " track/item/name] |
| 75 | + print ["Album: " track/item/album/name] |
| 76 | + foreach artist track/item/artists [ |
| 77 | + print ["Artist:" artist/name ] |
| 78 | + ] |
| 79 | + print ["ID: " track/item/id] |
| 80 | + print ["Pop: " track/item/popularity] |
| 81 | + system/options/log/http: log |
| 82 | + () |
| 83 | +] |
| 84 | + |
| 85 | +print {^/Get Current User's Profile:} |
| 86 | +print spotify/get %me |
| 87 | + |
| 88 | +halt |
| 89 | + |
| 90 | +print {^/Get Information About The User's Current Playback:} |
| 91 | +print spotify/get %me/player |
| 92 | + |
| 93 | +print {^/Get a User's Available Devices:} |
| 94 | +print spotify/get %me/player/devices |
| 95 | + |
| 96 | +print {^/Get the User's Currently Playing Track:} |
| 97 | +print spotify/get %me/player/currently-playing |
| 98 | +;@@ https://developer.spotify.com/documentation/web-api/reference/player/get-the-users-currently-playing-track/ |
| 99 | + |
| 100 | +print {^/Get a List of Current User's Playlists:} |
| 101 | +print spotify/get %me/playlists |
| 102 | +; optionaly for example with %me/playlists?limit=1&offset=2 to get just second playlist |
| 103 | +;@@ https://developer.spotify.com/documentation/web-api/reference/playlists/get-a-list-of-current-users-playlists/ |
| 104 | + |
| 105 | +print {^/Get a List of a User's Playlists:} |
| 106 | +print spotify/get %users/01vv226r3fsej509cp2yuozb8/playlists |
| 107 | +;@@ https://developer.spotify.com/documentation/web-api/reference/playlists/get-list-users-playlists/ |
| 108 | + |
| 109 | +print {^/Pause/Play/Seek a User's Playback:} |
| 110 | +print spotify/put %me/player/pause |
| 111 | +print spotify/put %me/player/play |
| 112 | +print spotify/put %me/player/seek?position_ms=0 |
| 113 | +;@@ https://github.com/spotify/web-api/issues/1594 |
| 114 | + |
| 115 | +print {^/Search for an Item:} |
| 116 | +print spotify/get %search?type=artist&q=ixieindamix |
| 117 | +;@@ https://developer.spotify.com/documentation/web-api/reference/search/search/ |
| 118 | + |
| 119 | +print {^/Check if Current User Follows Artists or Users:} |
| 120 | +print spotify/get %me/following/contains?type=artist&ids=2IpvlHMrM6rBvDY7dAAg7D,74ASZWbe4lXaubB36ztrGX |
| 121 | +print {^/Get User's Followed Artists:} |
| 122 | +print spotify/get %me/following?type=artist&limit=2 |
| 123 | +print {^/Start following Artists:} |
| 124 | +print spotify/put %me/following?type=artist&ids=74ASZWbe4lXaubB36ztrGX |
| 125 | +print {^/Stop following Artists:} |
| 126 | +print spotify/del %me/following?type=artist&ids=74ASZWbe4lXaubB36ztrGX |
| 127 | +;@@ https://developer.spotify.com/documentation/web-api/reference/follow/ |
| 128 | + |
| 129 | + |
| 130 | +print {^/Get Audio Features for a Track:} |
| 131 | +print spotify/get %audio-features/0uq0ibSGT4AwiVLLZGs9Qm |
| 132 | +;@@ https://developer.spotify.com/documentation/web-api/reference/tracks/get-audio-features/ |
| 133 | + |
| 134 | +print {^/Save Tracks for Current User:} |
| 135 | +print spotify/put %me/tracks?ids=0uq0ibSGT4AwiVLLZGs9Qm |
| 136 | +;@@ https://developer.spotify.com/documentation/web-api/reference/library/save-tracks-user/ |
| 137 | + |
| 138 | +halt |
0 commit comments