Skip to content

Commit 1b74d4d

Browse files
committed
FEAT: updated Spotify module to version 0.2.0
1 parent 05b7004 commit 1b74d4d

File tree

2 files changed

+345
-169
lines changed

2 files changed

+345
-169
lines changed

src/modules/spotify-test.r3

+142-91
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,73 @@
11
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
538
]
549

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+
]
5871
]
5972

6073
spot?: function [
@@ -67,7 +80,6 @@ spot?: function [
6780
print "No device!"
6881
exit
6982
]
70-
track: load-json track
7183
print ["Song: " track/item/name]
7284
print ["Album: " track/item/album/name]
7385
foreach artist track/item/artists [
@@ -79,55 +91,94 @@ spot?: function [
7991
()
8092
]
8193

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+
]
8497

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+
]
87101

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+
]
90105

91-
print {^/Get the User's Currently Playing Track:}
92-
print spotify/get %me/player/currently-playing
93106
;@@ 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+
]
94110

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
98111
;@@ 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+
]
99116

100-
print {^/Get a List of a User's Playlists:}
101-
print spotify/get %users/01vv226r3fsej509cp2yuozb8/playlists
102117
;@@ 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+
]
103121

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
112122
;@@ 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+
]
113126

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
122127
;@@ 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+
]
123142

124-
125-
print {^/Get Audio Features for a Track:}
126-
print spotify/get %audio-features/0uq0ibSGT4AwiVLLZGs9Qm
127143
;@@ 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+
]
128147

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+
]
132176

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

Comments
 (0)