1
1
Rebol [
2
- Title: "Test Spotify module"
3
- Date: 02-Jul-2020
4
- Author: "Oldes"
5
- File: %test-spotify.r3
6
- Version: 0.1.1
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
- spotify: system/modules/spotify/authorize [
18
- client-id: {8a01eb3b22ee4ba3b310e5e4fe10fd68}
19
- ; optional client-secret may be used for classic "Authorization Code Flow"
20
- ; if not used, the authentication will use PKCE extension, which is recommended
21
- ;client-secret: {00000000000000000000000000000000}
22
- scope: [
23
- ;@@ In real app not all scopes may be required!
24
- ;@@ https://developer.spotify.com/documentation/general/guides/scopes/
25
- ;- Images
26
- ;@ugc-image-upload ; Write access to user-provided images.
27
- ;- Spotify Connect
28
- @user-read-playback-state ; Read access to a user’s player state.
29
- @user-modify-playback-state ; Write access to a user’s playback state
30
- @user-read-currently-playing ; Read access to a user’s currently playing content.
31
- ;- Playback
32
- @streaming ; Control playback of a Spotify track. (Web Playback SDK and Premium only)
33
- @app-remote-control ; Remote control playback of Spotify. (iOS and Android SDK only)
34
- ;- Users
35
- @user-read-email ; Read access to user’s email address.
36
- @user-read-private ; Read access to user’s subscription details (type of user account).
37
- ;- Playlists
38
- @playlist-read-collaborative ; Include collaborative playlists when requesting a user's playlists.
39
- @playlist-modify-public ; Write access to a user's public playlists.
40
- @playlist-read-private ; Read access to user's private playlists.
41
- @playlist-modify-private ; Write access to a user's private playlists.
42
- ;- Library
43
- @user-library-modify ; Write/delete access to a user's "Your Music" library.
44
- @user-library-read ; Read access to a user's "Your Music" library.
45
- ;- Listening History
46
- @user-top-read ; Read access to a user's top artists and tracks.
47
- @user-read-playback-position ; Read access to a user’s playback position in a content.
48
- @user-read-recently-played ; Read access to a user’s recently played tracks.
49
- ;- Follow
50
- @user-follow-read ; Read access to the list of artists and other users that the user follows.
51
- @user-follow-modify ; Write/delete access to the list of artists and other users that the user follows.
52
- ]
2
+ Title: "Test Spotify module"
3
+ Version: 0.2.0
4
+ Author: @Oldes
5
+ Date: 20-Jul-2023
6
+ File: %test-spotify.r3
7
+ Needs: 3.11.0
53
8
]
54
9
55
- unless spotify [
56
- print "*** Access to Spotify API failed!"
57
- halt
10
+ system/options/quiet: false ;; allow Spotify traces
11
+ system/options/log/spotify: 4 ;; verbose
12
+ system/options/log/http: 0 ;; no HTTP traces
13
+
14
+ ;; make sure that we load a fresh extension
15
+ try [system/modules/spotify: none]
16
+ spotify: import %spotify.reb
17
+
18
+ test-all?: false ;; I don't want CI tests to stop my real playback
19
+
20
+ do-test : func [ title code] [
21
+ print-horizontal-line
22
+ print as-yellow title
23
+ probe code
24
+ try /with code :print
25
+ ]
26
+
27
+
28
+ [ ;@@ By default, the authorize is called when needed, but it can be forced using this code
29
+ remove/key system/user/data 'spotify-api
30
+ spotify/authorize [
31
+ client-id: {8a01eb3b22ee4ba3b310e5e4fe10fd68}
32
+ ; optional client-secret may be used for classic "Authorization Code Flow"
33
+ ; if not used, the authentication will use PKCE extension.
34
+ ; But!
35
+ ; A refresh token that has been obtained through PKCE can be exchanged for
36
+ ; an access token only once, after which it becomes invalid!
37
+ ;client-secret: {00000000000000000000000000000000}
38
+ ; Both values can be found for an app in: https://developer.spotify.com/dashboard
39
+ scopes: [
40
+ ;@@ In real app not all scopes may be required!
41
+ ;@@ https://developer.spotify.com/documentation/general/guides/scopes/
42
+ ;- Images
43
+ ;@ugc-image-upload ; Write access to user-provided images.
44
+ ;- Spotify Connect
45
+ @user-read-playback-state ; Read access to a user’s player state.
46
+ @user-modify-playback-state ; Write access to a user’s playback state
47
+ @user-read-currently-playing ; Read access to a user’s currently playing content.
48
+ ;- Playback
49
+ @streaming ; Control playback of a Spotify track. (Web Playback SDK and Premium only)
50
+ @app-remote-control ; Remote control playback of Spotify. (iOS and Android SDK only)
51
+ ;- Users
52
+ @user-read-email ; Read access to user’s email address.
53
+ @user-read-private ; Read access to user’s subscription details (type of user account).
54
+ ;- Playlists
55
+ @playlist-read-collaborative ; Include collaborative playlists when requesting a user's playlists.
56
+ @playlist-modify-public ; Write access to a user's public playlists.
57
+ @playlist-read-private ; Read access to user's private playlists.
58
+ @playlist-modify-private ; Write access to a user's private playlists.
59
+ ;- Library
60
+ @user-library-modify ; Write/delete access to a user's "Your Music" library.
61
+ @user-library-read ; Read access to a user's "Your Music" library.
62
+ ;- Listening History
63
+ @user-top-read ; Read access to a user's top artists and tracks.
64
+ @user-read-playback-position ; Read access to a user’s playback position in a content.
65
+ @user-read-recently-played ; Read access to a user’s recently played tracks.
66
+ ;- Follow
67
+ @user-follow-read ; Read access to the list of artists and other users that the user follows.
68
+ @user-follow-modify ; Write/delete access to the list of artists and other users that the user follows.
69
+ ]
70
+ ]
58
71
]
59
72
60
73
spot? : function [
@@ -67,7 +80,6 @@ spot?: function [
67
80
print "No device!"
68
81
exit
69
82
]
70
- track: load-json track
71
83
print ["Song: " track/item/name ]
72
84
print ["Album: " track/item/album/name ]
73
85
foreach artist track/item/artists [
@@ -79,55 +91,94 @@ spot?: function [
79
91
()
80
92
]
81
93
82
- print {^/ Get Current User's Profile:}
83
- print spotify/get %me
94
+ do-test {Get Current User's Profile} [
95
+ probe spotify/get %me
96
+ ]
84
97
85
- print {^/ Get Information About The User's Current Playback:}
86
- print spotify/get %me/player
98
+ do-test {Get Information About The User's Current Playback} [
99
+ probe spotify/get %me/player
100
+ ]
87
101
88
- print {^/ Get a User's Available Devices:}
89
- print spotify/get %me/player/devices
102
+ do-test {Get a User's Available Devices} [
103
+ probe spotify/get %me/player/devices
104
+ ]
90
105
91
- print {^/ Get the User's Currently Playing Track:}
92
- print spotify/get %me/player/currently-playing
93
106
;@@ https://developer.spotify.com/documentation/web-api/reference/player/get-the-users-currently-playing-track/
107
+ do-test {Get the User's Currently Playing Track} [
108
+ probe spotify/get %me/player/currently-playing
109
+ ]
94
110
95
- print {^/ Get a List of Current User's Playlists:}
96
- print spotify/get %me/playlists
97
- ; optionaly for example with %me/playlists?limit=1&offset=2 to get just second playlist
98
111
;@@ https://developer.spotify.com/documentation/web-api/reference/playlists/get-a-list-of-current-users-playlists/
112
+ do-test {Get a List of Current User's Playlists} [
113
+ probe spotify/get %me/playlists
114
+ ; optionaly for example with %me/playlists?limit=1&offset=2 to get just second playlist
115
+ ]
99
116
100
- print {^/ Get a List of a User's Playlists:}
101
- print spotify/get %users/01vv226r3fsej509cp2yuozb8/playlists
102
117
;@@ https://developer.spotify.com/documentation/web-api/reference/playlists/get-list-users-playlists/
118
+ do-test {Get a List of a User's Playlists} [
119
+ probe spotify/get %users/01vv226r3fsej509cp2yuozb8/playlists
120
+ ]
103
121
104
- print {^/ Pause/Play/Seek a User's Playback:}
105
- print spotify/put %me/player/pause
106
- print spotify/put %me/player/play
107
- print spotify/put %me/player/seek?position_ms=0
108
- ;@@ https://github.com/spotify/web-api/issues/1594
109
-
110
- print {^/ Search for an Item:}
111
- print spotify/get %search?type=artist&q=ixieindamix
112
122
;@@ https://developer.spotify.com/documentation/web-api/reference/search/search/
123
+ do-test {Search for an Item} [
124
+ probe spotify/get %search?type=artist&q=ixieindamix
125
+ ]
113
126
114
- print {^/ Check if Current User Follows Artists or Users:}
115
- print spotify/get %me/following/contains?type=artist&ids=2IpvlHMrM6rBvDY7dAAg7D,74ASZWbe4lXaubB36ztrGX
116
- print {^/ Get User's Followed Artists:}
117
- print spotify/get %me/following?type=artist&limit=2
118
- print {^/ Start following Artists:}
119
- print spotify/put %me/following?type=artist&ids=74ASZWbe4lXaubB36ztrGX
120
- print {^/ Stop following Artists:}
121
- print spotify/del %me/following?type=artist&ids=74ASZWbe4lXaubB36ztrGX
122
127
;@@ https://developer.spotify.com/documentation/web-api/reference/follow/
128
+ do-test {Get User's Followed Artists} [
129
+ probe spotify/get %me/following?type=artist&limit=2
130
+ ]
131
+ do-test {Check if Current User Follows Artists or Users} [
132
+ probe spotify/get %me/following/contains?type=artist&ids=2IpvlHMrM6rBvDY7dAAg7D,74ASZWbe4lXaubB36ztrGX
133
+ ]
134
+ do-test {Start following Artists} [
135
+ probe spotify/put %me/following?type=artist&ids=74ASZWbe4lXaubB36ztrGX
136
+ probe spotify/get %me/following/contains?type=artist&ids=74ASZWbe4lXaubB36ztrGX
137
+ ]
138
+ do-test {Stop following Artists} [
139
+ probe spotify/del %me/following?type=artist&ids=74ASZWbe4lXaubB36ztrGX
140
+ probe spotify/get %me/following/contains?type=artist&ids=74ASZWbe4lXaubB36ztrGX
141
+ ]
123
142
124
-
125
- print {^/ Get Audio Features for a Track:}
126
- print spotify/get %audio-features/0uq0ibSGT4AwiVLLZGs9Qm
127
143
;@@ https://developer.spotify.com/documentation/web-api/reference/tracks/get-audio-features/
144
+ do-test {Get Audio Features for a Track} [
145
+ probe spotify/get %audio-features/0uq0ibSGT4AwiVLLZGs9Qm
146
+ ]
128
147
129
- print {^/ Save Tracks for Current User:}
130
- print spotify/put %me/tracks?ids=0uq0ibSGT4AwiVLLZGs9Qm
131
- ;@@ https://developer.spotify.com/documentation/web-api/reference/library/save-tracks-user/
148
+ do-test {Tracks} [
149
+ ;@@ https://developer.spotify.com/documentation/web-api/reference/get-track
150
+ print "Get the track"
151
+ probe spotify/get %me/tracks/0uq0ibSGT4AwiVLLZGs9Qm
152
+
153
+ ;@@ https://developer.spotify.com/documentation/web-api/reference/get-audio-features
154
+ print "Get Track's Audio Features"
155
+ probe spotify/get %audio-features/0uq0ibSGT4AwiVLLZGs9Qm
156
+ ;probe spotify/get %audio-features?ids=3U7TesefC7piVH8SUqQz9L,0uq0ibSGT4AwiVLLZGs9Qm
157
+
158
+ ;@@ https://developer.spotify.com/documentation/web-api/reference/get-audio-analysis
159
+ ;; Get a low-level audio analysis for a track in the Spotify catalog. The audio analysis
160
+ ;; describes the track’s structure and musical content, including rhythm, pitch, and timbre.
161
+ print "Get Track's Audio Analysis"
162
+ probe spotify/get %audio-analysis/0uq0ibSGT4AwiVLLZGs9Qm
163
+
164
+ ;@@ https://developer.spotify.com/documentation/web-api/reference/check-users-saved-tracks
165
+ print "Check User's Saved Tracks"
166
+ probe spotify/get %me/tracks/contains?ids=0uq0ibSGT4AwiVLLZGs9Qm
167
+
168
+ ;@@ https://developer.spotify.com/documentation/web-api/reference/remove-tracks-user
169
+ print "Remove one or more tracks to the current user's 'Your Music' library. Maximum: 50 IDs."
170
+ probe spotify/del %me/tracks?ids=0uq0ibSGT4AwiVLLZGs9Qm
171
+
172
+ ;@@ https://developer.spotify.com/documentation/web-api/reference/save-tracks-user
173
+ print "Save one or more tracks to the current user's 'Your Music' library. Maximum: 50 IDs."
174
+ probe spotify/put %me/tracks?ids=0uq0ibSGT4AwiVLLZGs9Qm
175
+ ]
132
176
133
- halt
177
+ if test-all? [
178
+ do-test {Pause/Play/Seek a User's Playback} [
179
+ ;@@ https://github.com/spotify/web-api/issues/1594
180
+ probe spotify/put %me/player/pause
181
+ probe spotify/put %me/player/play
182
+ probe spotify/put %me/player/seek?position_ms=0
183
+ ]
184
+ ]
0 commit comments