universal-mcp 0.1.12__py3-none-any.whl → 0.1.13rc2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. universal_mcp/applications/__init__.py +51 -7
  2. universal_mcp/cli.py +109 -17
  3. universal_mcp/integrations/__init__.py +1 -1
  4. universal_mcp/integrations/integration.py +79 -0
  5. universal_mcp/servers/README.md +79 -0
  6. universal_mcp/servers/server.py +17 -29
  7. universal_mcp/stores/README.md +74 -0
  8. universal_mcp/stores/store.py +0 -2
  9. universal_mcp/templates/README.md.j2 +93 -0
  10. universal_mcp/templates/api_client.py.j2 +27 -0
  11. universal_mcp/tools/README.md +86 -0
  12. universal_mcp/tools/tools.py +1 -1
  13. universal_mcp/utils/agentr.py +90 -0
  14. universal_mcp/utils/api_generator.py +166 -208
  15. universal_mcp/utils/openapi.py +221 -321
  16. universal_mcp/utils/singleton.py +23 -0
  17. {universal_mcp-0.1.12.dist-info → universal_mcp-0.1.13rc2.dist-info}/METADATA +16 -41
  18. universal_mcp-0.1.13rc2.dist-info/RECORD +38 -0
  19. universal_mcp/applications/ahrefs/README.md +0 -76
  20. universal_mcp/applications/ahrefs/__init__.py +0 -0
  21. universal_mcp/applications/ahrefs/app.py +0 -2291
  22. universal_mcp/applications/cal_com_v2/README.md +0 -175
  23. universal_mcp/applications/cal_com_v2/__init__.py +0 -0
  24. universal_mcp/applications/cal_com_v2/app.py +0 -5390
  25. universal_mcp/applications/calendly/README.md +0 -78
  26. universal_mcp/applications/calendly/__init__.py +0 -0
  27. universal_mcp/applications/calendly/app.py +0 -1195
  28. universal_mcp/applications/clickup/README.md +0 -160
  29. universal_mcp/applications/clickup/__init__.py +0 -0
  30. universal_mcp/applications/clickup/app.py +0 -5009
  31. universal_mcp/applications/coda/README.md +0 -133
  32. universal_mcp/applications/coda/__init__.py +0 -0
  33. universal_mcp/applications/coda/app.py +0 -3671
  34. universal_mcp/applications/e2b/README.md +0 -37
  35. universal_mcp/applications/e2b/app.py +0 -65
  36. universal_mcp/applications/elevenlabs/README.md +0 -84
  37. universal_mcp/applications/elevenlabs/__init__.py +0 -0
  38. universal_mcp/applications/elevenlabs/app.py +0 -1402
  39. universal_mcp/applications/falai/README.md +0 -42
  40. universal_mcp/applications/falai/__init__.py +0 -0
  41. universal_mcp/applications/falai/app.py +0 -332
  42. universal_mcp/applications/figma/README.md +0 -74
  43. universal_mcp/applications/figma/__init__.py +0 -0
  44. universal_mcp/applications/figma/app.py +0 -1261
  45. universal_mcp/applications/firecrawl/README.md +0 -45
  46. universal_mcp/applications/firecrawl/app.py +0 -268
  47. universal_mcp/applications/github/README.md +0 -47
  48. universal_mcp/applications/github/app.py +0 -429
  49. universal_mcp/applications/gong/README.md +0 -88
  50. universal_mcp/applications/gong/__init__.py +0 -0
  51. universal_mcp/applications/gong/app.py +0 -2297
  52. universal_mcp/applications/google_calendar/app.py +0 -442
  53. universal_mcp/applications/google_docs/README.md +0 -40
  54. universal_mcp/applications/google_docs/app.py +0 -88
  55. universal_mcp/applications/google_drive/README.md +0 -44
  56. universal_mcp/applications/google_drive/app.py +0 -286
  57. universal_mcp/applications/google_mail/README.md +0 -47
  58. universal_mcp/applications/google_mail/app.py +0 -664
  59. universal_mcp/applications/google_sheet/README.md +0 -42
  60. universal_mcp/applications/google_sheet/app.py +0 -150
  61. universal_mcp/applications/hashnode/app.py +0 -81
  62. universal_mcp/applications/hashnode/prompt.md +0 -23
  63. universal_mcp/applications/heygen/README.md +0 -69
  64. universal_mcp/applications/heygen/__init__.py +0 -0
  65. universal_mcp/applications/heygen/app.py +0 -956
  66. universal_mcp/applications/mailchimp/README.md +0 -306
  67. universal_mcp/applications/mailchimp/__init__.py +0 -0
  68. universal_mcp/applications/mailchimp/app.py +0 -10937
  69. universal_mcp/applications/markitdown/app.py +0 -44
  70. universal_mcp/applications/notion/README.md +0 -55
  71. universal_mcp/applications/notion/__init__.py +0 -0
  72. universal_mcp/applications/notion/app.py +0 -527
  73. universal_mcp/applications/perplexity/README.md +0 -37
  74. universal_mcp/applications/perplexity/app.py +0 -65
  75. universal_mcp/applications/reddit/README.md +0 -45
  76. universal_mcp/applications/reddit/app.py +0 -379
  77. universal_mcp/applications/replicate/README.md +0 -65
  78. universal_mcp/applications/replicate/__init__.py +0 -0
  79. universal_mcp/applications/replicate/app.py +0 -980
  80. universal_mcp/applications/resend/README.md +0 -38
  81. universal_mcp/applications/resend/app.py +0 -37
  82. universal_mcp/applications/retell_ai/README.md +0 -46
  83. universal_mcp/applications/retell_ai/__init__.py +0 -0
  84. universal_mcp/applications/retell_ai/app.py +0 -333
  85. universal_mcp/applications/rocketlane/README.md +0 -42
  86. universal_mcp/applications/rocketlane/__init__.py +0 -0
  87. universal_mcp/applications/rocketlane/app.py +0 -194
  88. universal_mcp/applications/serpapi/README.md +0 -37
  89. universal_mcp/applications/serpapi/app.py +0 -73
  90. universal_mcp/applications/spotify/README.md +0 -116
  91. universal_mcp/applications/spotify/__init__.py +0 -0
  92. universal_mcp/applications/spotify/app.py +0 -2526
  93. universal_mcp/applications/supabase/README.md +0 -112
  94. universal_mcp/applications/supabase/__init__.py +0 -0
  95. universal_mcp/applications/supabase/app.py +0 -2970
  96. universal_mcp/applications/tavily/README.md +0 -38
  97. universal_mcp/applications/tavily/app.py +0 -51
  98. universal_mcp/applications/wrike/README.md +0 -71
  99. universal_mcp/applications/wrike/__init__.py +0 -0
  100. universal_mcp/applications/wrike/app.py +0 -1372
  101. universal_mcp/applications/youtube/README.md +0 -82
  102. universal_mcp/applications/youtube/__init__.py +0 -0
  103. universal_mcp/applications/youtube/app.py +0 -1428
  104. universal_mcp/applications/zenquotes/README.md +0 -37
  105. universal_mcp/applications/zenquotes/app.py +0 -31
  106. universal_mcp/integrations/agentr.py +0 -112
  107. universal_mcp-0.1.12.dist-info/RECORD +0 -119
  108. {universal_mcp-0.1.12.dist-info → universal_mcp-0.1.13rc2.dist-info}/WHEEL +0 -0
  109. {universal_mcp-0.1.12.dist-info → universal_mcp-0.1.13rc2.dist-info}/entry_points.txt +0 -0
@@ -1,2526 +0,0 @@
1
- from typing import Any
2
-
3
- from universal_mcp.applications import APIApplication
4
- from universal_mcp.integrations import Integration
5
-
6
-
7
- class SpotifyApp(APIApplication):
8
- def __init__(self, integration: Integration = None, **kwargs) -> None:
9
- super().__init__(name="spotify", integration=integration, **kwargs)
10
- self.base_url = "https://api.spotify.com/v1"
11
-
12
- def get_an_album(self, id, market=None) -> Any:
13
- """
14
- Retrieves detailed information about a specific album by its ID from the API.
15
-
16
- Args:
17
- id: str. The unique identifier for the album to retrieve. Must not be None.
18
- market: Optional[str]. An ISO 3166-1 alpha-2 country code to filter the album's availability. Defaults to None.
19
-
20
- Returns:
21
- dict. A JSON-decoded dictionary containing album details as returned by the API.
22
-
23
- Raises:
24
- ValueError: If the 'id' parameter is None.
25
- HTTPError: If the HTTP request to the API fails or returns an unsuccessful status code.
26
-
27
- Tags:
28
- get, album, api, fetch
29
- """
30
- if id is None:
31
- raise ValueError("Missing required parameter 'id'")
32
- url = f"{self.base_url}/albums/{id}"
33
- query_params = {k: v for k, v in [("market", market)] if v is not None}
34
- response = self._get(url, params=query_params)
35
- response.raise_for_status()
36
- return response.json()
37
-
38
- def get_multiple_albums(self, ids, market=None) -> Any:
39
- """
40
- Retrieves detailed information for multiple albums by their IDs from the API.
41
-
42
- Args:
43
- ids: A comma-separated string or list of album IDs to retrieve.
44
- market: (Optional) An ISO 3166-1 alpha-2 country code to filter the results based on market availability.
45
-
46
- Returns:
47
- A JSON-serializable object containing details of the requested albums.
48
-
49
- Raises:
50
- ValueError: If the 'ids' parameter is not provided.
51
- requests.HTTPError: If the HTTP request to the API fails with a status error.
52
-
53
- Tags:
54
- get, albums, api, list
55
- """
56
- if ids is None:
57
- raise ValueError("Missing required parameter 'ids'")
58
- url = f"{self.base_url}/albums"
59
- query_params = {
60
- k: v for k, v in [("ids", ids), ("market", market)] if v is not None
61
- }
62
- response = self._get(url, params=query_params)
63
- response.raise_for_status()
64
- return response.json()
65
-
66
- def get_an_albums_tracks(self, id, market=None, limit=None, offset=None) -> Any:
67
- """
68
- Retrieves the list of tracks for a specified album from the API, with optional filtering and pagination.
69
-
70
- Args:
71
- id: str. The unique identifier for the album. Required.
72
- market: Optional[str]. An ISO 3166-1 alpha-2 country code to filter track availability. Defaults to None.
73
- limit: Optional[int]. The maximum number of tracks to return. Defaults to None.
74
- offset: Optional[int]. The index of the first track to return. Useful for pagination. Defaults to None.
75
-
76
- Returns:
77
- Any. A JSON object containing the album's tracks and related pagination information as returned by the API.
78
-
79
- Raises:
80
- ValueError: If the 'id' parameter is None.
81
- HTTPError: If the HTTP request to the API fails (e.g., due to network issues or an invalid album ID).
82
-
83
- Tags:
84
- get, list, tracks, album, api
85
- """
86
- if id is None:
87
- raise ValueError("Missing required parameter 'id'")
88
- url = f"{self.base_url}/albums/{id}/tracks"
89
- query_params = {
90
- k: v
91
- for k, v in [("market", market), ("limit", limit), ("offset", offset)]
92
- if v is not None
93
- }
94
- response = self._get(url, params=query_params)
95
- response.raise_for_status()
96
- return response.json()
97
-
98
- def get_an_artist(self, id) -> Any:
99
- """
100
- Retrieve detailed information about a specific artist by their unique identifier.
101
-
102
- Args:
103
- id: The unique identifier of the artist to retrieve. Must not be None.
104
-
105
- Returns:
106
- A JSON object containing the artist's details as returned by the API.
107
-
108
- Raises:
109
- ValueError: Raised if the 'id' parameter is None.
110
- requests.exceptions.HTTPError: Raised if the HTTP request to fetch the artist fails (e.g., non-2xx status code).
111
-
112
- Tags:
113
- get, artist, api, fetch
114
- """
115
- if id is None:
116
- raise ValueError("Missing required parameter 'id'")
117
- url = f"{self.base_url}/artists/{id}"
118
- query_params = {}
119
- response = self._get(url, params=query_params)
120
- response.raise_for_status()
121
- return response.json()
122
-
123
- def get_multiple_artists(self, ids) -> Any:
124
- """
125
- Retrieves information for multiple artists using their IDs.
126
-
127
- Args:
128
- ids: A comma-separated string or list of artist IDs to retrieve information for.
129
-
130
- Returns:
131
- A JSON object containing details for the specified artists.
132
-
133
- Raises:
134
- ValueError: Raised if the 'ids' parameter is None.
135
- requests.HTTPError: Raised if the HTTP request to the artists endpoint fails.
136
-
137
- Tags:
138
- get, artists, api, list
139
- """
140
- if ids is None:
141
- raise ValueError("Missing required parameter 'ids'")
142
- url = f"{self.base_url}/artists"
143
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
144
- response = self._get(url, params=query_params)
145
- response.raise_for_status()
146
- return response.json()
147
-
148
- def get_an_artists_albums(
149
- self, id, include_groups=None, market=None, limit=None, offset=None
150
- ) -> Any:
151
- """
152
- Retrieves a list of albums for the specified artist from the API.
153
-
154
- Args:
155
- id: str. The unique identifier of the artist whose albums are to be retrieved.
156
- include_groups: Optional[str]. A comma-separated list of keywords to filter the album types (e.g., 'album', 'single', 'appears_on', 'compilation').
157
- market: Optional[str]. An ISO 3166-1 alpha-2 country code to filter the albums for a specific market.
158
- limit: Optional[int]. The maximum number of album objects to return. Default is determined by the API.
159
- offset: Optional[int]. The index of the first album to return. Useful for pagination.
160
-
161
- Returns:
162
- dict. A JSON object containing the artist's albums, as returned by the API.
163
-
164
- Raises:
165
- ValueError: If the 'id' parameter is not provided.
166
- requests.HTTPError: If the HTTP request to the API fails or returns an error status code.
167
-
168
- Tags:
169
- get, list, albums, artist, api
170
- """
171
- if id is None:
172
- raise ValueError("Missing required parameter 'id'")
173
- url = f"{self.base_url}/artists/{id}/albums"
174
- query_params = {
175
- k: v
176
- for k, v in [
177
- ("include_groups", include_groups),
178
- ("market", market),
179
- ("limit", limit),
180
- ("offset", offset),
181
- ]
182
- if v is not None
183
- }
184
- response = self._get(url, params=query_params)
185
- response.raise_for_status()
186
- return response.json()
187
-
188
- def get_an_artists_top_tracks(self, id, market=None) -> Any:
189
- """
190
- Retrieves the top tracks for a specified artist from the API.
191
-
192
- Args:
193
- id: str. The Spotify ID of the artist whose top tracks are to be retrieved.
194
- market: Optional[str]. An ISO 3166-1 alpha-2 country code to filter the top tracks for a specific market. Defaults to None.
195
-
196
- Returns:
197
- dict. A JSON object containing the artist's top tracks data as returned by the API.
198
-
199
- Raises:
200
- ValueError: Raised if the required 'id' parameter is not provided.
201
- requests.HTTPError: Raised if the HTTP request to the API is unsuccessful.
202
-
203
- Tags:
204
- get, artist, top-tracks, api, music
205
- """
206
- if id is None:
207
- raise ValueError("Missing required parameter 'id'")
208
- url = f"{self.base_url}/artists/{id}/top-tracks"
209
- query_params = {k: v for k, v in [("market", market)] if v is not None}
210
- response = self._get(url, params=query_params)
211
- response.raise_for_status()
212
- return response.json()
213
-
214
- def get_an_artists_related_artists(self, id) -> Any:
215
- """
216
- Retrieves a list of artists related to the specified artist by their unique ID.
217
-
218
- Args:
219
- id: str. The unique identifier of the artist for whom related artists are to be fetched.
220
-
221
- Returns:
222
- dict. A JSON-decoded dictionary containing data about artists related to the specified artist.
223
-
224
- Raises:
225
- ValueError: Raised if the required 'id' parameter is missing or None.
226
- HTTPError: Raised if the HTTP request to fetch related artists fails (non-success response).
227
-
228
- Tags:
229
- fetch, related-artists, ai, api
230
- """
231
- if id is None:
232
- raise ValueError("Missing required parameter 'id'")
233
- url = f"{self.base_url}/artists/{id}/related-artists"
234
- query_params = {}
235
- response = self._get(url, params=query_params)
236
- response.raise_for_status()
237
- return response.json()
238
-
239
- def get_a_show(self, id, market=None) -> Any:
240
- """
241
- Retrieve detailed information about a show by its unique identifier.
242
-
243
- Args:
244
- id: str. The unique identifier of the show to retrieve. Must not be None.
245
- market: Optional[str]. An ISO 3166-1 alpha-2 country code. If provided, restricts the show details to the specified market.
246
-
247
- Returns:
248
- dict. A dictionary containing the show's information as returned by the API.
249
-
250
- Raises:
251
- ValueError: Raised if the 'id' parameter is None.
252
- requests.HTTPError: Raised if the HTTP request for the show details fails.
253
-
254
- Tags:
255
- get, show, api, fetch
256
- """
257
- if id is None:
258
- raise ValueError("Missing required parameter 'id'")
259
- url = f"{self.base_url}/shows/{id}"
260
- query_params = {k: v for k, v in [("market", market)] if v is not None}
261
- response = self._get(url, params=query_params)
262
- response.raise_for_status()
263
- return response.json()
264
-
265
- def get_multiple_shows(self, ids, market=None) -> Any:
266
- """
267
- Retrieves information for multiple shows by their IDs, with optional market filtering.
268
-
269
- Args:
270
- ids: str or list of str. A comma-separated list or sequence of show IDs to retrieve information for. This parameter is required.
271
- market: Optional[str]. An optional ISO 3166-1 alpha-2 country code to filter show availability.
272
-
273
- Returns:
274
- dict. The JSON response containing show details for the specified IDs.
275
-
276
- Raises:
277
- ValueError: Raised if the 'ids' parameter is not provided.
278
- requests.HTTPError: Raised if an HTTP error occurs during the API request.
279
-
280
- Tags:
281
- get, list, shows, api, batch
282
- """
283
- if ids is None:
284
- raise ValueError("Missing required parameter 'ids'")
285
- url = f"{self.base_url}/shows"
286
- query_params = {
287
- k: v for k, v in [("market", market), ("ids", ids)] if v is not None
288
- }
289
- response = self._get(url, params=query_params)
290
- response.raise_for_status()
291
- return response.json()
292
-
293
- def get_a_shows_episodes(self, id, market=None, limit=None, offset=None) -> Any:
294
- """
295
- Retrieves episodes for a specific show from the API with optional market, limit, and offset parameters.
296
-
297
- Args:
298
- id: str. The unique identifier of the show whose episodes are to be retrieved.
299
- market: Optional[str]. An ISO 3166-1 alpha-2 country code to filter episodes available in a particular market.
300
- limit: Optional[int]. The maximum number of episodes to return. Optional.
301
- offset: Optional[int]. The index of the first episode to return. Optional.
302
-
303
- Returns:
304
- Any. A JSON-decoded object containing the episodes information for the specified show.
305
-
306
- Raises:
307
- ValueError: If the required 'id' parameter is None.
308
- HTTPError: If the HTTP request to the API fails (non-2xx status code).
309
-
310
- Tags:
311
- get, episodes, api, list, management
312
- """
313
- if id is None:
314
- raise ValueError("Missing required parameter 'id'")
315
- url = f"{self.base_url}/shows/{id}/episodes"
316
- query_params = {
317
- k: v
318
- for k, v in [("market", market), ("limit", limit), ("offset", offset)]
319
- if v is not None
320
- }
321
- response = self._get(url, params=query_params)
322
- response.raise_for_status()
323
- return response.json()
324
-
325
- def get_an_episode(self, id, market=None) -> Any:
326
- """
327
- Retrieves a single podcast episode's details by its unique identifier.
328
-
329
- Args:
330
- id: str. Unique identifier of the episode to retrieve. Required.
331
- market: Optional[str]. An ISO 3166-1 alpha-2 country code to filter the episode for a specific market. Defaults to None.
332
-
333
- Returns:
334
- dict. The JSON-decoded response containing episode details.
335
-
336
- Raises:
337
- ValueError: Raised if the 'id' parameter is None.
338
- requests.exceptions.HTTPError: Raised if the HTTP request to retrieve the episode fails.
339
-
340
- Tags:
341
- get, episode, api, fetch, single-item
342
- """
343
- if id is None:
344
- raise ValueError("Missing required parameter 'id'")
345
- url = f"{self.base_url}/episodes/{id}"
346
- query_params = {k: v for k, v in [("market", market)] if v is not None}
347
- response = self._get(url, params=query_params)
348
- response.raise_for_status()
349
- return response.json()
350
-
351
- def get_multiple_episodes(self, ids, market=None) -> Any:
352
- """
353
- Retrieves details for multiple podcast episodes using their IDs, optionally filtered by market.
354
-
355
- Args:
356
- ids: str. A comma-separated list of episode IDs to retrieve.
357
- market: Optional[str]. An ISO 3166-1 alpha-2 country code to filter the episodes based on market (defaults to None).
358
-
359
- Returns:
360
- Any. The response JSON containing details of the requested episodes.
361
-
362
- Raises:
363
- ValueError: Raised if the required parameter 'ids' is not provided.
364
- requests.HTTPError: Raised if the HTTP request to the API endpoint returns an unsuccessful status code.
365
-
366
- Tags:
367
- get, episodes, batch, podcast, api
368
- """
369
- if ids is None:
370
- raise ValueError("Missing required parameter 'ids'")
371
- url = f"{self.base_url}/episodes"
372
- query_params = {
373
- k: v for k, v in [("ids", ids), ("market", market)] if v is not None
374
- }
375
- response = self._get(url, params=query_params)
376
- response.raise_for_status()
377
- return response.json()
378
-
379
- def get_an_audiobook(self, id, market=None) -> Any:
380
- """
381
- Retrieves detailed information about a specific audiobook by ID, optionally filtered by market.
382
-
383
- Args:
384
- id: str. The unique identifier of the audiobook to retrieve.
385
- market: Optional[str]. An ISO 3166-1 alpha-2 country code to filter audiobook availability. Defaults to None.
386
-
387
- Returns:
388
- dict. A dictionary containing audiobook details as returned from the API.
389
-
390
- Raises:
391
- ValueError: Raised if the 'id' parameter is not provided.
392
- requests.HTTPError: Raised if the HTTP request to the audiobook API fails (non-2xx status code).
393
-
394
- Tags:
395
- get, audiobook, api, details, fetch
396
- """
397
- if id is None:
398
- raise ValueError("Missing required parameter 'id'")
399
- url = f"{self.base_url}/audiobooks/{id}"
400
- query_params = {k: v for k, v in [("market", market)] if v is not None}
401
- response = self._get(url, params=query_params)
402
- response.raise_for_status()
403
- return response.json()
404
-
405
- def get_multiple_audiobooks(self, ids, market=None) -> Any:
406
- """
407
- Fetches details for multiple audiobooks by their IDs, optionally filtered by market.
408
-
409
- Args:
410
- ids: A list or comma-separated string of audiobook IDs to retrieve.
411
- market: Optional; a string specifying the market to filter results by.
412
-
413
- Returns:
414
- A dictionary containing details of the requested audiobooks as parsed from the JSON API response.
415
-
416
- Raises:
417
- ValueError: Raised if 'ids' is not provided.
418
- requests.exceptions.HTTPError: Raised if the API response contains a failed HTTP status.
419
-
420
- Tags:
421
- get, audiobook, batch, api
422
- """
423
- if ids is None:
424
- raise ValueError("Missing required parameter 'ids'")
425
- url = f"{self.base_url}/audiobooks"
426
- query_params = {
427
- k: v for k, v in [("ids", ids), ("market", market)] if v is not None
428
- }
429
- response = self._get(url, params=query_params)
430
- response.raise_for_status()
431
- return response.json()
432
-
433
- def get_audiobook_chapters(self, id, market=None, limit=None, offset=None) -> Any:
434
- """
435
- Retrieves the chapters for a specified audiobook from the API.
436
-
437
- Args:
438
- id: str. The unique identifier of the audiobook whose chapters are to be retrieved.
439
- market: Optional[str]. An ISO 3166-1 alpha-2 country code specifying the market for the chapters. Defaults to None.
440
- limit: Optional[int]. The maximum number of chapters to return. Defaults to None.
441
- offset: Optional[int]. The index of the first chapter to return. Used for pagination. Defaults to None.
442
-
443
- Returns:
444
- dict. A JSON response containing audiobook chapter details as returned by the API.
445
-
446
- Raises:
447
- ValueError: If the 'id' parameter is not provided.
448
- requests.HTTPError: If the API request fails with a non-successful HTTP status code.
449
-
450
- Tags:
451
- get, audiobook, chapters, api, fetch
452
- """
453
- if id is None:
454
- raise ValueError("Missing required parameter 'id'")
455
- url = f"{self.base_url}/audiobooks/{id}/chapters"
456
- query_params = {
457
- k: v
458
- for k, v in [("market", market), ("limit", limit), ("offset", offset)]
459
- if v is not None
460
- }
461
- response = self._get(url, params=query_params)
462
- response.raise_for_status()
463
- return response.json()
464
-
465
- def get_users_saved_audiobooks(self, limit=None, offset=None) -> Any:
466
- """
467
- Retrieves the current user's saved audiobooks from the API with optional pagination.
468
-
469
- Args:
470
- limit: Optional; int or None. The maximum number of audiobooks to return. If None, the API default is used.
471
- offset: Optional; int or None. The index of the first audiobook to retrieve. If None, the API default is used.
472
-
473
- Returns:
474
- dict: A JSON-decoded dictionary containing the user's saved audiobooks.
475
-
476
- Raises:
477
- requests.exceptions.HTTPError: If the HTTP request to the API fails or returns an unsuccessful status code.
478
-
479
- Tags:
480
- get, list, audiobooks, user-data, api
481
- """
482
- url = f"{self.base_url}/me/audiobooks"
483
- query_params = {
484
- k: v for k, v in [("limit", limit), ("offset", offset)] if v is not None
485
- }
486
- response = self._get(url, params=query_params)
487
- response.raise_for_status()
488
- return response.json()
489
-
490
- def save_audiobooks_user(self, ids) -> Any:
491
- """
492
- Saves one or more audiobooks to the current user's library.
493
-
494
- Args:
495
- ids: A comma-separated string or list of audiobook IDs to add to the user's library. Must not be None.
496
-
497
- Returns:
498
- The JSON-decoded response from the API, typically containing the result of the save operation.
499
-
500
- Raises:
501
- ValueError: If 'ids' is None.
502
- HTTPError: If the API request fails due to an unsuccessful HTTP response status.
503
-
504
- Tags:
505
- save, audiobooks, user, management, api
506
- """
507
- if ids is None:
508
- raise ValueError("Missing required parameter 'ids'")
509
- url = f"{self.base_url}/me/audiobooks"
510
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
511
- response = self._put(url, data={}, params=query_params)
512
- response.raise_for_status()
513
- return response.json()
514
-
515
- def remove_audiobooks_user(self, ids) -> Any:
516
- """
517
- Removes one or more audiobooks from the authenticated user's library.
518
-
519
- Args:
520
- ids: The identifier or list of identifiers of the audiobooks to remove.
521
-
522
- Returns:
523
- The API response as a parsed JSON object containing the result of the deletion operation.
524
-
525
- Raises:
526
- ValueError: If the 'ids' parameter is None.
527
- requests.HTTPError: If the HTTP request to delete audiobooks does not succeed.
528
-
529
- Tags:
530
- remove, audiobooks, user-library, management
531
- """
532
- if ids is None:
533
- raise ValueError("Missing required parameter 'ids'")
534
- url = f"{self.base_url}/me/audiobooks"
535
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
536
- response = self._delete(url, params=query_params)
537
- response.raise_for_status()
538
- return response.json()
539
-
540
- def check_users_saved_audiobooks(self, ids) -> Any:
541
- """
542
- Checks if the specified audiobooks are saved in the current user's library.
543
-
544
- Args:
545
- ids: A string or list of audiobook IDs to check. Each ID should correspond to an audiobook in the catalog.
546
-
547
- Returns:
548
- A JSON-serializable object (typically a list of booleans) indicating whether each audiobook is saved by the user.
549
-
550
- Raises:
551
- ValueError: Raised if the 'ids' parameter is None.
552
- HTTPError: Raised if the HTTP request to the API fails with an error status.
553
-
554
- Tags:
555
- check, audiobooks, user-library, api
556
- """
557
- if ids is None:
558
- raise ValueError("Missing required parameter 'ids'")
559
- url = f"{self.base_url}/me/audiobooks/contains"
560
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
561
- response = self._get(url, params=query_params)
562
- response.raise_for_status()
563
- return response.json()
564
-
565
- def get_a_chapter(self, id, market=None) -> Any:
566
- """
567
- Retrieves a specific chapter's details by ID from the API, optionally filtering by market.
568
-
569
- Args:
570
- id: The unique identifier of the chapter to retrieve. Must not be None.
571
- market: Optional; a string specifying a market code to filter the chapter details.
572
-
573
- Returns:
574
- A JSON-decoded object containing the details of the requested chapter.
575
-
576
- Raises:
577
- ValueError: Raised when the required 'id' parameter is missing (None).
578
- HTTPError: Raised if the HTTP request to the API fails or returns an unsuccessful status.
579
-
580
- Tags:
581
- get, chapter, api, data-retrieval
582
- """
583
- if id is None:
584
- raise ValueError("Missing required parameter 'id'")
585
- url = f"{self.base_url}/chapters/{id}"
586
- query_params = {k: v for k, v in [("market", market)] if v is not None}
587
- response = self._get(url, params=query_params)
588
- response.raise_for_status()
589
- return response.json()
590
-
591
- def get_several_chapters(self, ids, market=None) -> Any:
592
- """
593
- Retrieve details for multiple chapters based on their IDs, optionally filtering by market.
594
-
595
- Args:
596
- ids: List or string of chapter IDs to retrieve. This parameter is required.
597
- market: Optional market code to filter the chapters by region or market. Defaults to None.
598
-
599
- Returns:
600
- A JSON-decoded response containing details for the specified chapters.
601
-
602
- Raises:
603
- ValueError: If the 'ids' parameter is None.
604
- HTTPError: If the HTTP request to the chapters endpoint returns an error response.
605
-
606
- Tags:
607
- get, chapters, batch, api
608
- """
609
- if ids is None:
610
- raise ValueError("Missing required parameter 'ids'")
611
- url = f"{self.base_url}/chapters"
612
- query_params = {
613
- k: v for k, v in [("ids", ids), ("market", market)] if v is not None
614
- }
615
- response = self._get(url, params=query_params)
616
- response.raise_for_status()
617
- return response.json()
618
-
619
- def get_track(self, id, market=None) -> Any:
620
- """
621
- Retrieves detailed information about a track by its unique identifier from the external API.
622
-
623
- Args:
624
- id: str. The unique identifier for the track to retrieve. Must not be None.
625
- market: Optional[str]. An ISO 3166-1 alpha-2 country code to filter the track's availability (default is None).
626
-
627
- Returns:
628
- dict. The JSON response containing track details from the API.
629
-
630
- Raises:
631
- ValueError: If the required 'id' parameter is None.
632
- HTTPError: If the API request returns an unsuccessful HTTP status code.
633
-
634
- Tags:
635
- get, track, api, fetch
636
- """
637
- if id is None:
638
- raise ValueError("Missing required parameter 'id'")
639
- url = f"{self.base_url}/tracks/{id}"
640
- query_params = {k: v for k, v in [("market", market)] if v is not None}
641
- response = self._get(url, params=query_params)
642
- response.raise_for_status()
643
- return response.json()
644
-
645
- def get_several_tracks(self, ids, market=None) -> Any:
646
- """
647
- Retrieves metadata for multiple tracks based on their IDs from the API.
648
-
649
- Args:
650
- ids: A comma-separated list or iterable of track IDs to retrieve metadata for. This parameter is required.
651
- market: An optional ISO 3166-1 alpha-2 country code to filter the track data. Defaults to None.
652
-
653
- Returns:
654
- A dictionary containing the metadata of the requested tracks as returned by the API.
655
-
656
- Raises:
657
- ValueError: If 'ids' is not provided (None), indicating that required parameter is missing.
658
- requests.HTTPError: If the HTTP request to the API fails or returns a non-success status code.
659
-
660
- Tags:
661
- get, tracks, api, metadata
662
- """
663
- if ids is None:
664
- raise ValueError("Missing required parameter 'ids'")
665
- url = f"{self.base_url}/tracks"
666
- query_params = {
667
- k: v for k, v in [("market", market), ("ids", ids)] if v is not None
668
- }
669
- response = self._get(url, params=query_params)
670
- response.raise_for_status()
671
- return response.json()
672
-
673
- def search(
674
- self, q, type, market=None, limit=None, offset=None, include_external=None
675
- ) -> Any:
676
- """
677
- Performs a search query against the API and returns the matching results as a JSON object.
678
-
679
- Args:
680
- q: str. The search query string. Required.
681
- type: str or list of str. The type(s) of item to search for (e.g., 'track', 'artist'). Required.
682
- market: Optional[str]. An ISO 3166-1 alpha-2 country code or 'from_token'. Optional.
683
- limit: Optional[int]. Maximum number of results to return. Optional.
684
- offset: Optional[int]. The index of the first result to return. Optional.
685
- include_external: Optional[str]. If 'audio', the response will include any relevant audio content. Optional.
686
-
687
- Returns:
688
- dict. The JSON response containing search results.
689
-
690
- Raises:
691
- ValueError: If the required parameter 'q' or 'type' is missing.
692
- requests.HTTPError: If the HTTP request fails or the server returns an error status.
693
-
694
- Tags:
695
- search, api, query, async-job, important
696
- """
697
- if q is None:
698
- raise ValueError("Missing required parameter 'q'")
699
- if type is None:
700
- raise ValueError("Missing required parameter 'type'")
701
- url = f"{self.base_url}/search"
702
- query_params = {
703
- k: v
704
- for k, v in [
705
- ("q", q),
706
- ("type", type),
707
- ("market", market),
708
- ("limit", limit),
709
- ("offset", offset),
710
- ("include_external", include_external),
711
- ]
712
- if v is not None
713
- }
714
- response = self._get(url, params=query_params)
715
- response.raise_for_status()
716
- return response.json()
717
-
718
- def get_current_users_profile(
719
- self,
720
- ) -> Any:
721
- """
722
- Retrieves the current authenticated user's profile information from the API.
723
-
724
- Args:
725
- None: This function takes no arguments
726
-
727
- Returns:
728
- dict: A dictionary containing the user's profile data as returned by the API.
729
-
730
- Raises:
731
- requests.exceptions.HTTPError: If the HTTP request returned an unsuccessful status code.
732
-
733
- Tags:
734
- get, profile, user, api
735
- """
736
- url = f"{self.base_url}/me"
737
- query_params = {}
738
- response = self._get(url, params=query_params)
739
- response.raise_for_status()
740
- return response.json()
741
-
742
- def get_playlist(
743
- self, playlist_id, market=None, fields=None, additional_types=None
744
- ) -> Any:
745
- """
746
- Retrieves a playlist from the API using the specified playlist ID.
747
-
748
- Args:
749
- playlist_id: The ID of the playlist to retrieve. Required.
750
- market: Optional. An ISO 3166-1 alpha-2 country code or the string 'from_token' to specify the market to get content for.
751
- fields: Optional. Filters for the query: a comma-separated list of the fields to return. If omitted, all fields are returned.
752
- additional_types: Optional. A comma-separated list of item types that your client supports besides the default track type.
753
-
754
- Returns:
755
- A dictionary containing the playlist data in JSON format.
756
-
757
- Raises:
758
- ValueError: If the required playlist_id parameter is None or not provided.
759
- HTTPError: If the API request fails (through raise_for_status()).
760
-
761
- Tags:
762
- retrieve, get, playlist, api, important
763
- """
764
- if playlist_id is None:
765
- raise ValueError("Missing required parameter 'playlist_id'")
766
- url = f"{self.base_url}/playlists/{playlist_id}"
767
- query_params = {
768
- k: v
769
- for k, v in [
770
- ("market", market),
771
- ("fields", fields),
772
- ("additional_types", additional_types),
773
- ]
774
- if v is not None
775
- }
776
- response = self._get(url, params=query_params)
777
- response.raise_for_status()
778
- return response.json()
779
-
780
- def change_playlist_details(
781
- self, playlist_id, name=None, public=None, collaborative=None, description=None
782
- ) -> Any:
783
- """
784
- Update the details of an existing playlist with the specified attributes.
785
-
786
- Args:
787
- playlist_id: str. The unique identifier of the playlist to update. Must not be None.
788
- name: Optional[str]. New name for the playlist. If None, the name is not changed.
789
- public: Optional[bool]. Whether the playlist should be public. If None, the setting is unchanged.
790
- collaborative: Optional[bool]. Whether the playlist should be collaborative. If None, the setting is unchanged.
791
- description: Optional[str]. New description for the playlist. If None, the description is not changed.
792
-
793
- Returns:
794
- dict. The JSON response containing the updated playlist details.
795
-
796
- Raises:
797
- ValueError: Raised if 'playlist_id' is None.
798
- requests.HTTPError: Raised if the API request returns an unsuccessful status code.
799
-
800
- Tags:
801
- change, update, playlist, management, api
802
- """
803
- if playlist_id is None:
804
- raise ValueError("Missing required parameter 'playlist_id'")
805
- request_body = {
806
- "name": name,
807
- "public": public,
808
- "collaborative": collaborative,
809
- "description": description,
810
- }
811
- request_body = {k: v for k, v in request_body.items() if v is not None}
812
- url = f"{self.base_url}/playlists/{playlist_id}"
813
- query_params = {}
814
- response = self._put(url, data=request_body, params=query_params)
815
- response.raise_for_status()
816
- return response.json()
817
-
818
- def get_playlists_tracks(
819
- self,
820
- playlist_id,
821
- market=None,
822
- fields=None,
823
- limit=None,
824
- offset=None,
825
- additional_types=None,
826
- ) -> Any:
827
- """
828
- Retrieves the tracks of a specified playlist from the API, applying optional filters and pagination parameters.
829
-
830
- Args:
831
- playlist_id: str. The unique identifier of the playlist to retrieve tracks from.
832
- market: Optional[str]. An ISO 3166-1 alpha-2 country code, or 'from_token'. Filters the response to a specific market.
833
- fields: Optional[str]. Comma-separated list of Spotify fields to include in the response.
834
- limit: Optional[int]. The maximum number of items to return (default and maximum are API-dependent).
835
- offset: Optional[int]. The index of the first item to return for pagination.
836
- additional_types: Optional[str]. Types of items to return, e.g., 'track', 'episode'.
837
-
838
- Returns:
839
- dict. JSON response containing the playlist's tracks and associated metadata.
840
-
841
- Raises:
842
- ValueError: If 'playlist_id' is None.
843
- requests.HTTPError: If the API request fails due to a client or server error.
844
-
845
- Tags:
846
- get, list, playlist, tracks, api, management, important
847
- """
848
- if playlist_id is None:
849
- raise ValueError("Missing required parameter 'playlist_id'")
850
- url = f"{self.base_url}/playlists/{playlist_id}/tracks"
851
- query_params = {
852
- k: v
853
- for k, v in [
854
- ("market", market),
855
- ("fields", fields),
856
- ("limit", limit),
857
- ("offset", offset),
858
- ("additional_types", additional_types),
859
- ]
860
- if v is not None
861
- }
862
- response = self._get(url, params=query_params)
863
- response.raise_for_status()
864
- return response.json()
865
-
866
- def add_tracks_to_playlist(self, playlist_id, position=None, uris=None) -> Any:
867
- """
868
- Adds one or more tracks to a specified playlist at an optional position.
869
-
870
- Args:
871
- playlist_id: str. The unique identifier of the playlist to which tracks will be added.
872
- position: Optional[int]. The position in the playlist where the tracks should be inserted. If not specified, tracks will be added to the end.
873
- uris: Optional[List[str]]. A list of track URIs to add to the playlist. If not specified, no tracks will be added.
874
-
875
- Returns:
876
- dict: The JSON response from the API containing information about the operation result.
877
-
878
- Raises:
879
- ValueError: If 'playlist_id' is not provided.
880
- requests.HTTPError: If the HTTP request to the external API fails or returns an error status code.
881
-
882
- Tags:
883
- add, playlist-management, tracks, api, important
884
- """
885
- if playlist_id is None:
886
- raise ValueError("Missing required parameter 'playlist_id'")
887
- request_body = {
888
- "uris": uris,
889
- "position": position,
890
- }
891
- request_body = {k: v for k, v in request_body.items() if v is not None}
892
- url = f"{self.base_url}/playlists/{playlist_id}/tracks"
893
- query_params = {
894
- k: v for k, v in [("position", position), ("uris", uris)] if v is not None
895
- }
896
- response = self._post(url, data=request_body, params=query_params)
897
- response.raise_for_status()
898
- return response.json()
899
-
900
- def reorder_or_replace_playlists_tracks(
901
- self,
902
- playlist_id,
903
- uris=None,
904
- range_start=None,
905
- insert_before=None,
906
- range_length=None,
907
- snapshot_id=None,
908
- ) -> Any:
909
- """
910
- Reorders or replaces tracks in a playlist by moving, inserting, or replacing track entries using the specified parameters.
911
-
912
- Args:
913
- playlist_id: str. The Spotify ID of the playlist to be modified. Required.
914
- uris: Optional[list of str]. The new track URIs to replace the playlist's tracks. If provided, replaces tracks instead of reordering.
915
- range_start: Optional[int]. The position of the first track to be reordered. Required for reordering.
916
- insert_before: Optional[int]. The position where the reordered tracks should be inserted. Required for reordering.
917
- range_length: Optional[int]. The number of tracks to be reordered. Defaults to 1 if not specified.
918
- snapshot_id: Optional[str]. The playlist's snapshot ID against which to apply changes, used for concurrency control.
919
-
920
- Returns:
921
- dict. The JSON response from the Spotify API containing the new snapshot ID of the playlist.
922
-
923
- Raises:
924
- ValueError: If 'playlist_id' is None.
925
- requests.HTTPError: If the HTTP request to the API fails (e.g., due to invalid parameters or network issues).
926
-
927
- Tags:
928
- reorder, replace, playlist, tracks, management, api
929
- """
930
- if playlist_id is None:
931
- raise ValueError("Missing required parameter 'playlist_id'")
932
- request_body = {
933
- "uris": uris,
934
- "range_start": range_start,
935
- "insert_before": insert_before,
936
- "range_length": range_length,
937
- "snapshot_id": snapshot_id,
938
- }
939
- request_body = {k: v for k, v in request_body.items() if v is not None}
940
- url = f"{self.base_url}/playlists/{playlist_id}/tracks"
941
- query_params = {k: v for k, v in [("uris", uris)] if v is not None}
942
- response = self._put(url, data=request_body, params=query_params)
943
- response.raise_for_status()
944
- return response.json()
945
-
946
- def get_a_list_of_current_users_playlists(self, limit=None, offset=None) -> Any:
947
- """
948
- Retrieves a list of the current user's playlists with optional pagination controls.
949
-
950
- Args:
951
- limit: int or None. The maximum number of playlists to return. If None, the default set by the API is used.
952
- offset: int or None. The index of the first playlist to return. If None, the default set by the API is used.
953
-
954
- Returns:
955
- dict. A JSON response containing the playlists of the current user.
956
-
957
- Raises:
958
- requests.HTTPError: If the HTTP request to the API fails or returns a non-success status code.
959
-
960
- Tags:
961
- list, playlists, user, api
962
- """
963
- url = f"{self.base_url}/me/playlists"
964
- query_params = {
965
- k: v for k, v in [("limit", limit), ("offset", offset)] if v is not None
966
- }
967
- response = self._get(url, params=query_params)
968
- response.raise_for_status()
969
- return response.json()
970
-
971
- def get_users_saved_albums(self, limit=None, offset=None, market=None) -> Any:
972
- """
973
- Retrieves the current user's saved albums from the Spotify library with optional pagination and market filtering.
974
-
975
- Args:
976
- limit: Optional; maximum number of albums to return. If not specified, the default set by the API is used.
977
- offset: Optional; the index of the first album to return. Used for pagination.
978
- market: Optional; an ISO 3166-1 alpha-2 country code to filter albums by market availability.
979
-
980
- Returns:
981
- A JSON object containing the list of the user's saved albums and related pagination details as returned by the Spotify API.
982
-
983
- Raises:
984
- requests.HTTPError: If the HTTP request to the Spotify API fails or returns an unsuccessful status code.
985
-
986
- Tags:
987
- get, list, albums, user-library, spotify, api
988
- """
989
- url = f"{self.base_url}/me/albums"
990
- query_params = {
991
- k: v
992
- for k, v in [("limit", limit), ("offset", offset), ("market", market)]
993
- if v is not None
994
- }
995
- response = self._get(url, params=query_params)
996
- response.raise_for_status()
997
- return response.json()
998
-
999
- def check_users_saved_albums(self, ids) -> Any:
1000
- """
1001
- Checks if the specified albums are saved in the current user's Spotify library.
1002
-
1003
- Args:
1004
- ids: A comma-separated string or list of Spotify album IDs to check for saved status.
1005
-
1006
- Returns:
1007
- A list of boolean values indicating whether each album specified in 'ids' is saved in the user's library.
1008
-
1009
- Raises:
1010
- ValueError: If the 'ids' parameter is None.
1011
- requests.HTTPError: If the HTTP request to the Spotify API fails.
1012
-
1013
- Tags:
1014
- check, spotify, albums, user-library
1015
- """
1016
- if ids is None:
1017
- raise ValueError("Missing required parameter 'ids'")
1018
- url = f"{self.base_url}/me/albums/contains"
1019
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
1020
- response = self._get(url, params=query_params)
1021
- response.raise_for_status()
1022
- return response.json()
1023
-
1024
- def get_users_saved_tracks(self, market=None, limit=None, offset=None) -> Any:
1025
- """
1026
- Retrieves the current user's saved tracks from the Spotify library with optional filtering and pagination.
1027
-
1028
- Args:
1029
- market: Optional; an ISO 3166-1 alpha-2 country code. Filters the results to tracks available in the specified market.
1030
- limit: Optional; maximum number of items to return (usually between 1 and 50).
1031
- offset: Optional; the index of the first item to return, used for pagination.
1032
-
1033
- Returns:
1034
- A JSON object containing a paginated list of the user's saved tracks and associated metadata.
1035
-
1036
- Raises:
1037
- requests.HTTPError: Raised if the HTTP request to the Spotify API fails or returns a non-success status code.
1038
-
1039
- Tags:
1040
- list, get, user-data, spotify, tracks, batch
1041
- """
1042
- url = f"{self.base_url}/me/tracks"
1043
- query_params = {
1044
- k: v
1045
- for k, v in [("market", market), ("limit", limit), ("offset", offset)]
1046
- if v is not None
1047
- }
1048
- response = self._get(url, params=query_params)
1049
- response.raise_for_status()
1050
- return response.json()
1051
-
1052
- def save_tracks_user(self, ids) -> Any:
1053
- """
1054
- Saves one or more tracks to the current user's music library.
1055
-
1056
- Args:
1057
- ids: A list or comma-separated string of track IDs to save to the user's library. Must not be None.
1058
-
1059
- Returns:
1060
- The JSON response from the API as a Python object, typically confirming the successful saving of tracks.
1061
-
1062
- Raises:
1063
- ValueError: If the 'ids' parameter is None.
1064
- HTTPError: If the HTTP request to save tracks fails (raised by response.raise_for_status()).
1065
-
1066
- Tags:
1067
- save, user-library, tracks, api
1068
- """
1069
- if ids is None:
1070
- raise ValueError("Missing required parameter 'ids'")
1071
- request_body = {
1072
- "ids": ids,
1073
- }
1074
- request_body = {k: v for k, v in request_body.items() if v is not None}
1075
- url = f"{self.base_url}/me/tracks"
1076
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
1077
- response = self._put(url, data=request_body, params=query_params)
1078
- response.raise_for_status()
1079
- return response.json()
1080
-
1081
- def check_users_saved_tracks(self, ids) -> Any:
1082
- """
1083
- Checks if the current user has saved specific tracks in their Spotify library.
1084
-
1085
- Args:
1086
- ids: A comma-separated string of Spotify track IDs to check for saved status.
1087
-
1088
- Returns:
1089
- A list of boolean values indicating whether each track ID is saved by the current user.
1090
-
1091
- Raises:
1092
- ValueError: Raised when the 'ids' parameter is None.
1093
- HTTPError: Raised if the HTTP request to the Spotify API fails.
1094
-
1095
- Tags:
1096
- check, user-library, spotify, status
1097
- """
1098
- if ids is None:
1099
- raise ValueError("Missing required parameter 'ids'")
1100
- url = f"{self.base_url}/me/tracks/contains"
1101
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
1102
- response = self._get(url, params=query_params)
1103
- response.raise_for_status()
1104
- return response.json()
1105
-
1106
- def get_users_saved_episodes(self, market=None, limit=None, offset=None) -> Any:
1107
- """
1108
- Retrieves the current user's saved podcast episodes from the service, with optional support for market, pagination, and result limits.
1109
-
1110
- Args:
1111
- market: Optional; a string specifying the market (country code) to filter episode availability.
1112
- limit: Optional; an integer specifying the maximum number of episodes to return.
1113
- offset: Optional; an integer specifying the index of the first episode to return for pagination.
1114
-
1115
- Returns:
1116
- A JSON-decoded response containing the user's saved episodes and associated metadata.
1117
-
1118
- Raises:
1119
- requests.HTTPError: If the HTTP request fails or the API returns a non-success status code.
1120
-
1121
- Tags:
1122
- get, list, user-content, episodes, ai
1123
- """
1124
- url = f"{self.base_url}/me/episodes"
1125
- query_params = {
1126
- k: v
1127
- for k, v in [("market", market), ("limit", limit), ("offset", offset)]
1128
- if v is not None
1129
- }
1130
- response = self._get(url, params=query_params)
1131
- response.raise_for_status()
1132
- return response.json()
1133
-
1134
- def save_episodes_user(self, ids) -> Any:
1135
- """
1136
- Saves episodes to the user's library using the provided list of episode IDs.
1137
-
1138
- Args:
1139
- ids: A list of episode IDs to be saved to the user's library.
1140
-
1141
- Returns:
1142
- The JSON response from the server confirming successful saving of episodes.
1143
-
1144
- Raises:
1145
- ValueError: Raised if the 'ids' parameter is None.
1146
- HTTPError: Raised if the HTTP PUT request to the server fails.
1147
-
1148
- Tags:
1149
- save, episodes, user-management, async-job
1150
- """
1151
- if ids is None:
1152
- raise ValueError("Missing required parameter 'ids'")
1153
- request_body = {
1154
- "ids": ids,
1155
- }
1156
- request_body = {k: v for k, v in request_body.items() if v is not None}
1157
- url = f"{self.base_url}/me/episodes"
1158
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
1159
- response = self._put(url, data=request_body, params=query_params)
1160
- response.raise_for_status()
1161
- return response.json()
1162
-
1163
- def check_users_saved_episodes(self, ids) -> Any:
1164
- """
1165
- Checks if the specified episodes are saved in the current user's library.
1166
-
1167
- Args:
1168
- ids: A list or comma-separated string of episode IDs to check for presence in the user's saved episodes. Must not be None.
1169
-
1170
- Returns:
1171
- A JSON-compatible object (typically a list of booleans) indicating whether each episode ID is present in the user's saved episodes.
1172
-
1173
- Raises:
1174
- ValueError: Raised if the 'ids' parameter is None.
1175
- HTTPError: Raised if the HTTP request to the remote service fails with a non-success status code.
1176
-
1177
- Tags:
1178
- check, status, async_job, ai, management
1179
- """
1180
- if ids is None:
1181
- raise ValueError("Missing required parameter 'ids'")
1182
- url = f"{self.base_url}/me/episodes/contains"
1183
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
1184
- response = self._get(url, params=query_params)
1185
- response.raise_for_status()
1186
- return response.json()
1187
-
1188
- def get_users_saved_shows(self, limit=None, offset=None) -> Any:
1189
- """
1190
- Retrieves the current user's saved shows from the Spotify API with optional pagination.
1191
-
1192
- Args:
1193
- limit: Optional; maximum number of shows to return. Must be a positive integer or None for default behavior.
1194
- offset: Optional; the index of the first show to return. Must be a non-negative integer or None for default behavior.
1195
-
1196
- Returns:
1197
- A JSON-decoded object containing the list of saved shows and associated metadata.
1198
-
1199
- Raises:
1200
- HTTPError: Raised if the HTTP request to the Spotify API returns an unsuccessful status code.
1201
-
1202
- Tags:
1203
- get, list, shows, spotify, user-content
1204
- """
1205
- url = f"{self.base_url}/me/shows"
1206
- query_params = {
1207
- k: v for k, v in [("limit", limit), ("offset", offset)] if v is not None
1208
- }
1209
- response = self._get(url, params=query_params)
1210
- response.raise_for_status()
1211
- return response.json()
1212
-
1213
- def check_users_saved_shows(self, ids) -> Any:
1214
- """
1215
- Checks if the specified shows are saved in the current user's library.
1216
-
1217
- Args:
1218
- ids: A comma-separated string or list of show IDs to check for presence in the user's library.
1219
-
1220
- Returns:
1221
- A JSON-compatible object (typically a list of booleans) indicating, for each show ID, whether it is saved in the user's library.
1222
-
1223
- Raises:
1224
- ValueError: If the required 'ids' parameter is not provided.
1225
- requests.HTTPError: If the HTTP request to the API fails or returns an error status code.
1226
-
1227
- Tags:
1228
- check, library, status, async-job, ai
1229
- """
1230
- if ids is None:
1231
- raise ValueError("Missing required parameter 'ids'")
1232
- url = f"{self.base_url}/me/shows/contains"
1233
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
1234
- response = self._get(url, params=query_params)
1235
- response.raise_for_status()
1236
- return response.json()
1237
-
1238
- def get_users_profile(self, user_id) -> Any:
1239
- """
1240
- Retrieves the profile information for a specific user by user ID.
1241
-
1242
- Args:
1243
- user_id: The unique identifier of the user whose profile information is to be retrieved.
1244
-
1245
- Returns:
1246
- A JSON-decoded object containing the user's profile information.
1247
-
1248
- Raises:
1249
- ValueError: Raised if the 'user_id' parameter is not provided (i.e., is None).
1250
- requests.exceptions.HTTPError: Raised if the HTTP request to fetch the user's profile fails (non-success status code).
1251
-
1252
- Tags:
1253
- get, profile, user, api
1254
- """
1255
- if user_id is None:
1256
- raise ValueError("Missing required parameter 'user_id'")
1257
- url = f"{self.base_url}/users/{user_id}"
1258
- query_params = {}
1259
- response = self._get(url, params=query_params)
1260
- response.raise_for_status()
1261
- return response.json()
1262
-
1263
- def get_list_users_playlists(self, user_id, limit=None, offset=None) -> Any:
1264
- """
1265
- Retrieves a list of playlists for a specified user.
1266
-
1267
- Args:
1268
- user_id: The ID of the user whose playlists to retrieve. Required.
1269
- limit: The maximum number of playlists to return. Optional.
1270
- offset: The index of the first playlist to return. Used for pagination. Optional.
1271
-
1272
- Returns:
1273
- A JSON object containing the user's playlists data.
1274
-
1275
- Raises:
1276
- ValueError: Raised when the required parameter 'user_id' is None.
1277
- HTTPError: Raised when the HTTP request fails.
1278
-
1279
- Tags:
1280
- retrieve, list, playlists, user, pagination, api
1281
- """
1282
- if user_id is None:
1283
- raise ValueError("Missing required parameter 'user_id'")
1284
- url = f"{self.base_url}/users/{user_id}/playlists"
1285
- query_params = {
1286
- k: v for k, v in [("limit", limit), ("offset", offset)] if v is not None
1287
- }
1288
- response = self._get(url, params=query_params)
1289
- response.raise_for_status()
1290
- return response.json()
1291
-
1292
- def create_playlist(
1293
- self, user_id, name, public=None, collaborative=None, description=None
1294
- ) -> Any:
1295
- """
1296
- Creates a new playlist for a specified user with optional visibility, collaboration, and description settings.
1297
-
1298
- Args:
1299
- user_id: str. The unique identifier of the user for whom the playlist is to be created.
1300
- name: str. The name of the new playlist.
1301
- public: Optional[bool]. If True, the playlist is public; if False, it is private. If None, the default visibility is used.
1302
- collaborative: Optional[bool]. If True, the playlist can be edited by other users. If None, the playlist is not collaborative.
1303
- description: Optional[str]. An optional description for the playlist.
1304
-
1305
- Returns:
1306
- dict. A dictionary containing the created playlist's details as returned by the API.
1307
-
1308
- Raises:
1309
- ValueError: If either 'user_id' or 'name' is not provided.
1310
- requests.HTTPError: If the HTTP request to create the playlist fails.
1311
-
1312
- Tags:
1313
- create, playlist, api, management, important
1314
- """
1315
- if user_id is None:
1316
- raise ValueError("Missing required parameter 'user_id'")
1317
- if name is None:
1318
- raise ValueError("Missing required parameter 'name'")
1319
- request_body = {
1320
- "name": name,
1321
- "public": public,
1322
- "collaborative": collaborative,
1323
- "description": description,
1324
- }
1325
- request_body = {k: v for k, v in request_body.items() if v is not None}
1326
- url = f"{self.base_url}/users/{user_id}/playlists"
1327
- query_params = {}
1328
- response = self._post(url, data=request_body, params=query_params)
1329
- response.raise_for_status()
1330
- return response.json()
1331
-
1332
- def follow_playlist(self, playlist_id, public=None) -> Any:
1333
- """
1334
- Follows a Spotify playlist on behalf of the current user.
1335
-
1336
- Args:
1337
- playlist_id: str. The Spotify ID of the playlist to follow. Must not be None.
1338
- public: Optional[bool]. Whether the playlist should be public (visible on the user's profile). If None, defaults to the server-side default.
1339
-
1340
- Returns:
1341
- Any. The JSON response from the Spotify API confirming the follow action.
1342
-
1343
- Raises:
1344
- ValueError: If 'playlist_id' is None.
1345
- HTTPError: If the HTTP request fails or the API returns an error status.
1346
-
1347
- Tags:
1348
- follow, playlist, api, async-job
1349
- """
1350
- if playlist_id is None:
1351
- raise ValueError("Missing required parameter 'playlist_id'")
1352
- request_body = {
1353
- "public": public,
1354
- }
1355
- request_body = {k: v for k, v in request_body.items() if v is not None}
1356
- url = f"{self.base_url}/playlists/{playlist_id}/followers"
1357
- query_params = {}
1358
- response = self._put(url, data=request_body, params=query_params)
1359
- response.raise_for_status()
1360
- return response.json()
1361
-
1362
- def unfollow_playlist(self, playlist_id) -> Any:
1363
- """
1364
- Unfollows the specified playlist by deleting the current user's following relationship.
1365
-
1366
- Args:
1367
- playlist_id: The unique identifier of the playlist to unfollow. Must not be None.
1368
-
1369
- Returns:
1370
- The API response as a JSON-compatible object containing details of the unfollow operation.
1371
-
1372
- Raises:
1373
- ValueError: If 'playlist_id' is None.
1374
- requests.HTTPError: If the API request fails and returns an unsuccessful HTTP status code.
1375
-
1376
- Tags:
1377
- unfollow, playlist-management, delete, async-job
1378
- """
1379
- if playlist_id is None:
1380
- raise ValueError("Missing required parameter 'playlist_id'")
1381
- url = f"{self.base_url}/playlists/{playlist_id}/followers"
1382
- query_params = {}
1383
- response = self._delete(url, params=query_params)
1384
- response.raise_for_status()
1385
- return response.json()
1386
-
1387
- def get_featured_playlists(self, locale=None, limit=None, offset=None) -> Any:
1388
- """
1389
- Retrieves a list of Spotify's featured playlists with optional localization, result limiting, and pagination.
1390
-
1391
- Args:
1392
- locale: Optional; a string specifying the language and country (e.g., 'en_US') to localize the playlist names and descriptions. If None, the server default is used.
1393
- limit: Optional; an integer specifying the maximum number of playlists to return. If None, the server default is used.
1394
- offset: Optional; an integer specifying the index of the first playlist to return (for pagination). If None, the server default is used.
1395
-
1396
- Returns:
1397
- A dictionary containing the JSON response from the Spotify Web API with details about the featured playlists.
1398
-
1399
- Raises:
1400
- requests.HTTPError: If the HTTP request to the Spotify API fails or returns an unsuccessful status code.
1401
-
1402
- Tags:
1403
- get, list, playlists, featured, api, music
1404
- """
1405
- url = f"{self.base_url}/browse/featured-playlists"
1406
- query_params = {
1407
- k: v
1408
- for k, v in [("locale", locale), ("limit", limit), ("offset", offset)]
1409
- if v is not None
1410
- }
1411
- response = self._get(url, params=query_params)
1412
- response.raise_for_status()
1413
- return response.json()
1414
-
1415
- def get_categories(self, locale=None, limit=None, offset=None) -> Any:
1416
- """
1417
- Retrieves a list of category objects from the API with optional locale, limit, and offset filters.
1418
-
1419
- Args:
1420
- locale: Optional; str. Locale identifier (e.g., 'en_US') to localize the category names returned.
1421
- limit: Optional; int. Maximum number of categories to return in the response.
1422
- offset: Optional; int. The index of the first category to return, used for pagination.
1423
-
1424
- Returns:
1425
- dict. The JSON response from the API containing category data.
1426
-
1427
- Raises:
1428
- requests.HTTPError: If the HTTP request to the API endpoint returns an unsuccessful status code.
1429
-
1430
- Tags:
1431
- get, list, categories, api
1432
- """
1433
- url = f"{self.base_url}/browse/categories"
1434
- query_params = {
1435
- k: v
1436
- for k, v in [("locale", locale), ("limit", limit), ("offset", offset)]
1437
- if v is not None
1438
- }
1439
- response = self._get(url, params=query_params)
1440
- response.raise_for_status()
1441
- return response.json()
1442
-
1443
- def get_a_category(self, category_id, locale=None) -> Any:
1444
- """
1445
- Retrieve detailed information about a specific category by its ID, optionally localized to a given locale.
1446
-
1447
- Args:
1448
- category_id: str. The unique identifier of the category to retrieve.
1449
- locale: Optional[str]. The locale code to use for localization of the category information. If None, the default locale is used.
1450
-
1451
- Returns:
1452
- dict. A JSON object containing the category details as returned by the API.
1453
-
1454
- Raises:
1455
- ValueError: If 'category_id' is None.
1456
- requests.HTTPError: If the HTTP request to the API fails or returns an unsuccessful status code.
1457
-
1458
- Tags:
1459
- get, category, api
1460
- """
1461
- if category_id is None:
1462
- raise ValueError("Missing required parameter 'category_id'")
1463
- url = f"{self.base_url}/browse/categories/{category_id}"
1464
- query_params = {k: v for k, v in [("locale", locale)] if v is not None}
1465
- response = self._get(url, params=query_params)
1466
- response.raise_for_status()
1467
- return response.json()
1468
-
1469
- def get_a_categories_playlists(self, category_id, limit=None, offset=None) -> Any:
1470
- """
1471
- Retrieves playlists associated with a specified category from the API.
1472
-
1473
- Args:
1474
- category_id: str. The unique identifier for the category whose playlists are to be fetched.
1475
- limit: Optional[int]. The maximum number of playlists to return. If None, the default API value is used.
1476
- offset: Optional[int]. The index of the first playlist to return. Used for pagination. If None, the default API value is used.
1477
-
1478
- Returns:
1479
- dict. The JSON response containing playlist data for the specified category.
1480
-
1481
- Raises:
1482
- ValueError: If 'category_id' is None.
1483
- requests.HTTPError: If the API request fails or returns a non-success status code.
1484
-
1485
- Tags:
1486
- get, list, playlists, categories, api, management
1487
- """
1488
- if category_id is None:
1489
- raise ValueError("Missing required parameter 'category_id'")
1490
- url = f"{self.base_url}/browse/categories/{category_id}/playlists"
1491
- query_params = {
1492
- k: v for k, v in [("limit", limit), ("offset", offset)] if v is not None
1493
- }
1494
- response = self._get(url, params=query_params)
1495
- response.raise_for_status()
1496
- return response.json()
1497
-
1498
- def get_playlist_cover(self, playlist_id) -> Any:
1499
- """
1500
- Retrieves the cover image(s) for a specified playlist by its unique ID.
1501
-
1502
- Args:
1503
- playlist_id: The unique identifier of the playlist for which to fetch cover images.
1504
-
1505
- Returns:
1506
- The JSON response containing playlist cover image metadata as returned by the API.
1507
-
1508
- Raises:
1509
- ValueError: Raised when the required parameter 'playlist_id' is None.
1510
- HTTPError: Raised if the HTTP request to retrieve the cover images fails.
1511
-
1512
- Tags:
1513
- get, playlist, cover-image, api
1514
- """
1515
- if playlist_id is None:
1516
- raise ValueError("Missing required parameter 'playlist_id'")
1517
- url = f"{self.base_url}/playlists/{playlist_id}/images"
1518
- query_params = {}
1519
- response = self._get(url, params=query_params)
1520
- response.raise_for_status()
1521
- return response.json()
1522
-
1523
- def get_new_releases(self, limit=None, offset=None) -> Any:
1524
- """
1525
- Retrieves a list of new music releases with optional pagination parameters.
1526
-
1527
- Args:
1528
- limit: Optional; int. The maximum number of items to return. If not specified, the server default is used.
1529
- offset: Optional; int. The index of the first item to return. Used for pagination. If not specified, the server default is used.
1530
-
1531
- Returns:
1532
- dict. A JSON object containing metadata and a list of new releases.
1533
-
1534
- Raises:
1535
- requests.HTTPError: If the HTTP request to fetch new releases returns an unsuccessful status code.
1536
-
1537
- Tags:
1538
- get, list, browse, music, async-job, api
1539
- """
1540
- url = f"{self.base_url}/browse/new-releases"
1541
- query_params = {
1542
- k: v for k, v in [("limit", limit), ("offset", offset)] if v is not None
1543
- }
1544
- response = self._get(url, params=query_params)
1545
- response.raise_for_status()
1546
- return response.json()
1547
-
1548
- def get_followed(self, type, after=None, limit=None) -> Any:
1549
- """
1550
- Retrieves the list of entities the current user is following, with support for pagination and limiting results.
1551
-
1552
- Args:
1553
- type: str. The type of entity to return (e.g., 'artist', 'user'). Required.
1554
- after: str or None. The cursor value to fetch items after a specific entity for pagination. Optional.
1555
- limit: int or None. The maximum number of items to return. Optional.
1556
-
1557
- Returns:
1558
- dict. A JSON-decoded response containing the list of followed entities and pagination details.
1559
-
1560
- Raises:
1561
- ValueError: If the 'type' parameter is not provided.
1562
- HTTPError: If the HTTP request to the API fails (raised by requests.Response.raise_for_status()).
1563
-
1564
- Tags:
1565
- get, list, follow-management, api
1566
- """
1567
- if type is None:
1568
- raise ValueError("Missing required parameter 'type'")
1569
- url = f"{self.base_url}/me/following"
1570
- query_params = {
1571
- k: v
1572
- for k, v in [("type", type), ("after", after), ("limit", limit)]
1573
- if v is not None
1574
- }
1575
- response = self._get(url, params=query_params)
1576
- response.raise_for_status()
1577
- return response.json()
1578
-
1579
- def follow_artists_users(self, type, ids) -> Any:
1580
- """
1581
- Follows one or more artists or users on behalf of the current user.
1582
-
1583
- Args:
1584
- type: str. The type of entity to follow. Valid values are typically 'artist' or 'user'.
1585
- ids: str or list of str. The Spotify IDs of the artists or users to follow. Can be a single ID or a comma-separated/list of IDs.
1586
-
1587
- Returns:
1588
- dict. The response from the API as a parsed JSON object containing the result of the follow operation.
1589
-
1590
- Raises:
1591
- ValueError: If 'type' or 'ids' is None, indicating a missing required parameter.
1592
- HTTPError: If the API request fails or returns an error status code.
1593
-
1594
- Tags:
1595
- follow, users, artists, api
1596
- """
1597
- if type is None:
1598
- raise ValueError("Missing required parameter 'type'")
1599
- if ids is None:
1600
- raise ValueError("Missing required parameter 'ids'")
1601
- request_body = {
1602
- "ids": ids,
1603
- }
1604
- request_body = {k: v for k, v in request_body.items() if v is not None}
1605
- url = f"{self.base_url}/me/following"
1606
- query_params = {
1607
- k: v for k, v in [("type", type), ("ids", ids)] if v is not None
1608
- }
1609
- response = self._put(url, data=request_body, params=query_params)
1610
- response.raise_for_status()
1611
- return response.json()
1612
-
1613
- def check_current_user_follows(self, type, ids) -> Any:
1614
- """
1615
- Check if the current user follows specific Spotify users or artists.
1616
-
1617
- Args:
1618
- type: str. The type of entity to check, either 'artist' or 'user'.
1619
- ids: str or list of str. The Spotify IDs of the users or artists to check, separated by commas if a string.
1620
-
1621
- Returns:
1622
- list of bool. A list indicating, for each provided ID, whether the current user is following the corresponding user or artist.
1623
-
1624
- Raises:
1625
- ValueError: If the 'type' or 'ids' parameter is missing or None.
1626
- requests.HTTPError: If the HTTP request to the API fails or returns an error status.
1627
-
1628
- Tags:
1629
- check, follows, spotify, user, artist, api
1630
- """
1631
- if type is None:
1632
- raise ValueError("Missing required parameter 'type'")
1633
- if ids is None:
1634
- raise ValueError("Missing required parameter 'ids'")
1635
- url = f"{self.base_url}/me/following/contains"
1636
- query_params = {
1637
- k: v for k, v in [("type", type), ("ids", ids)] if v is not None
1638
- }
1639
- response = self._get(url, params=query_params)
1640
- response.raise_for_status()
1641
- return response.json()
1642
-
1643
- def check_if_user_follows_playlist(self, playlist_id, ids) -> Any:
1644
- """
1645
- Checks if one or more users follow a specified playlist.
1646
-
1647
- Args:
1648
- playlist_id: The unique identifier of the playlist to check.
1649
- ids: A comma-separated list or iterable of user IDs to be checked for following the playlist.
1650
-
1651
- Returns:
1652
- A JSON-compatible object indicating, for each user ID, whether that user is following the playlist.
1653
-
1654
- Raises:
1655
- ValueError: If 'playlist_id' or 'ids' is None.
1656
- requests.HTTPError: If the API request fails or returns an error response.
1657
-
1658
- Tags:
1659
- check, playlist, followers, api
1660
- """
1661
- if playlist_id is None:
1662
- raise ValueError("Missing required parameter 'playlist_id'")
1663
- if ids is None:
1664
- raise ValueError("Missing required parameter 'ids'")
1665
- url = f"{self.base_url}/playlists/{playlist_id}/followers/contains"
1666
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
1667
- response = self._get(url, params=query_params)
1668
- response.raise_for_status()
1669
- return response.json()
1670
-
1671
- def get_several_audio_features(self, ids) -> Any:
1672
- """
1673
- Retrieves audio feature information for multiple tracks using their IDs.
1674
-
1675
- Args:
1676
- ids: A comma-separated string or list of track IDs for which to retrieve audio features.
1677
-
1678
- Returns:
1679
- A JSON-decoded object containing audio features for the specified tracks.
1680
-
1681
- Raises:
1682
- ValueError: If the 'ids' parameter is None.
1683
- requests.HTTPError: If the HTTP request to the audio features endpoint fails.
1684
-
1685
- Tags:
1686
- get, audio-features, batch, ai
1687
- """
1688
- if ids is None:
1689
- raise ValueError("Missing required parameter 'ids'")
1690
- url = f"{self.base_url}/audio-features"
1691
- query_params = {k: v for k, v in [("ids", ids)] if v is not None}
1692
- response = self._get(url, params=query_params)
1693
- response.raise_for_status()
1694
- return response.json()
1695
-
1696
- def get_audio_features(self, id) -> Any:
1697
- """
1698
- Retrieves audio feature information for a given identifier from the API.
1699
-
1700
- Args:
1701
- id: The identifier of the audio resource for which to fetch features.
1702
-
1703
- Returns:
1704
- A dictionary containing the audio feature data for the specified resource.
1705
-
1706
- Raises:
1707
- ValueError: Raised if the 'id' parameter is None.
1708
- requests.HTTPError: Raised if the HTTP request to the API fails with a bad status code.
1709
-
1710
- Tags:
1711
- get, audio-features, api, fetch
1712
- """
1713
- if id is None:
1714
- raise ValueError("Missing required parameter 'id'")
1715
- url = f"{self.base_url}/audio-features/{id}"
1716
- query_params = {}
1717
- response = self._get(url, params=query_params)
1718
- response.raise_for_status()
1719
- return response.json()
1720
-
1721
- def get_audio_analysis(self, id) -> Any:
1722
- """
1723
- Retrieves the audio analysis data for a specified audio ID from the API.
1724
-
1725
- Args:
1726
- id: The unique identifier of the audio resource to analyze. Must not be None.
1727
-
1728
- Returns:
1729
- A JSON object containing audio analysis data for the specified audio ID.
1730
-
1731
- Raises:
1732
- ValueError: If the 'id' parameter is None.
1733
- requests.HTTPError: If the HTTP request to the audio analysis endpoint fails (e.g., network error or non-2xx response).
1734
-
1735
- Tags:
1736
- get, audio-analysis, api, fetch
1737
- """
1738
- if id is None:
1739
- raise ValueError("Missing required parameter 'id'")
1740
- url = f"{self.base_url}/audio-analysis/{id}"
1741
- query_params = {}
1742
- response = self._get(url, params=query_params)
1743
- response.raise_for_status()
1744
- return response.json()
1745
-
1746
- def get_recommendations(
1747
- self,
1748
- limit=None,
1749
- market=None,
1750
- seed_artists=None,
1751
- seed_genres=None,
1752
- seed_tracks=None,
1753
- min_acousticness=None,
1754
- max_acousticness=None,
1755
- target_acousticness=None,
1756
- min_danceability=None,
1757
- max_danceability=None,
1758
- target_danceability=None,
1759
- min_duration_ms=None,
1760
- max_duration_ms=None,
1761
- target_duration_ms=None,
1762
- min_energy=None,
1763
- max_energy=None,
1764
- target_energy=None,
1765
- min_instrumentalness=None,
1766
- max_instrumentalness=None,
1767
- target_instrumentalness=None,
1768
- min_key=None,
1769
- max_key=None,
1770
- target_key=None,
1771
- min_liveness=None,
1772
- max_liveness=None,
1773
- target_liveness=None,
1774
- min_loudness=None,
1775
- max_loudness=None,
1776
- target_loudness=None,
1777
- min_mode=None,
1778
- max_mode=None,
1779
- target_mode=None,
1780
- min_popularity=None,
1781
- max_popularity=None,
1782
- target_popularity=None,
1783
- min_speechiness=None,
1784
- max_speechiness=None,
1785
- target_speechiness=None,
1786
- min_tempo=None,
1787
- max_tempo=None,
1788
- target_tempo=None,
1789
- min_time_signature=None,
1790
- max_time_signature=None,
1791
- target_time_signature=None,
1792
- min_valence=None,
1793
- max_valence=None,
1794
- target_valence=None,
1795
- ) -> Any:
1796
- """
1797
- Retrieves track recommendations based on a combination of seed values and audio feature constraints.
1798
-
1799
- Args:
1800
- limit: Optional; maximum number of recommendations to return.
1801
- market: Optional; an ISO 3166-1 alpha-2 country code to filter the response.
1802
- seed_artists: Optional; list or comma-separated string of artist IDs to use as seeds.
1803
- seed_genres: Optional; list or comma-separated string of genre names to use as seeds.
1804
- seed_tracks: Optional; list or comma-separated string of track IDs to use as seeds.
1805
- min_acousticness: Optional; minimum acousticness value (float) of tracks to return.
1806
- max_acousticness: Optional; maximum acousticness value (float) of tracks to return.
1807
- target_acousticness: Optional; target acousticness value (float) for recommended tracks.
1808
- min_danceability: Optional; minimum danceability value (float) of tracks to return.
1809
- max_danceability: Optional; maximum danceability value (float) of tracks to return.
1810
- target_danceability: Optional; target danceability value (float) for recommended tracks.
1811
- min_duration_ms: Optional; minimum duration (in milliseconds) for tracks to return.
1812
- max_duration_ms: Optional; maximum duration (in milliseconds) for tracks to return.
1813
- target_duration_ms: Optional; target duration (in milliseconds) for recommended tracks.
1814
- min_energy: Optional; minimum energy value (float) of tracks to return.
1815
- max_energy: Optional; maximum energy value (float) of tracks to return.
1816
- target_energy: Optional; target energy value (float) for recommended tracks.
1817
- min_instrumentalness: Optional; minimum instrumentalness value (float) of tracks to return.
1818
- max_instrumentalness: Optional; maximum instrumentalness value (float) of tracks to return.
1819
- target_instrumentalness: Optional; target instrumentalness value (float) for recommended tracks.
1820
- min_key: Optional; minimum key value (int) for tracks to return.
1821
- max_key: Optional; maximum key value (int) for tracks to return.
1822
- target_key: Optional; target key value (int) for recommended tracks.
1823
- min_liveness: Optional; minimum liveness value (float) of tracks to return.
1824
- max_liveness: Optional; maximum liveness value (float) of tracks to return.
1825
- target_liveness: Optional; target liveness value (float) for recommended tracks.
1826
- min_loudness: Optional; minimum loudness value (float, in dB) of tracks to return.
1827
- max_loudness: Optional; maximum loudness value (float, in dB) of tracks to return.
1828
- target_loudness: Optional; target loudness value (float, in dB) for recommended tracks.
1829
- min_mode: Optional; minimum mode value (int: 0 for minor, 1 for major) for tracks to return.
1830
- max_mode: Optional; maximum mode value (int: 0 for minor, 1 for major) for tracks to return.
1831
- target_mode: Optional; target mode value (int: 0 for minor, 1 for major) for recommended tracks.
1832
- min_popularity: Optional; minimum popularity (int) of tracks to return.
1833
- max_popularity: Optional; maximum popularity (int) of tracks to return.
1834
- target_popularity: Optional; target popularity (int) for recommended tracks.
1835
- min_speechiness: Optional; minimum speechiness value (float) of tracks to return.
1836
- max_speechiness: Optional; maximum speechiness value (float) of tracks to return.
1837
- target_speechiness: Optional; target speechiness value (float) for recommended tracks.
1838
- min_tempo: Optional; minimum tempo (float, BPM) of tracks to return.
1839
- max_tempo: Optional; maximum tempo (float, BPM) of tracks to return.
1840
- target_tempo: Optional; target tempo (float, BPM) for recommended tracks.
1841
- min_time_signature: Optional; minimum time signature (int) for tracks to return.
1842
- max_time_signature: Optional; maximum time signature (int) for tracks to return.
1843
- target_time_signature: Optional; target time signature (int) for recommended tracks.
1844
- min_valence: Optional; minimum valence value (float) of tracks to return.
1845
- max_valence: Optional; maximum valence value (float) of tracks to return.
1846
- target_valence: Optional; target valence value (float) for recommended tracks.
1847
-
1848
- Returns:
1849
- A JSON object containing a list of recommended tracks matching the provided seeds and filter criteria.
1850
-
1851
- Raises:
1852
- requests.HTTPError: If the HTTP request returned an unsuccessful status code.
1853
- requests.RequestException: If a network-related error occurs during the request.
1854
-
1855
- Tags:
1856
- get, recommendations, ai, music, filter
1857
- """
1858
- url = f"{self.base_url}/recommendations"
1859
- query_params = {
1860
- k: v
1861
- for k, v in [
1862
- ("limit", limit),
1863
- ("market", market),
1864
- ("seed_artists", seed_artists),
1865
- ("seed_genres", seed_genres),
1866
- ("seed_tracks", seed_tracks),
1867
- ("min_acousticness", min_acousticness),
1868
- ("max_acousticness", max_acousticness),
1869
- ("target_acousticness", target_acousticness),
1870
- ("min_danceability", min_danceability),
1871
- ("max_danceability", max_danceability),
1872
- ("target_danceability", target_danceability),
1873
- ("min_duration_ms", min_duration_ms),
1874
- ("max_duration_ms", max_duration_ms),
1875
- ("target_duration_ms", target_duration_ms),
1876
- ("min_energy", min_energy),
1877
- ("max_energy", max_energy),
1878
- ("target_energy", target_energy),
1879
- ("min_instrumentalness", min_instrumentalness),
1880
- ("max_instrumentalness", max_instrumentalness),
1881
- ("target_instrumentalness", target_instrumentalness),
1882
- ("min_key", min_key),
1883
- ("max_key", max_key),
1884
- ("target_key", target_key),
1885
- ("min_liveness", min_liveness),
1886
- ("max_liveness", max_liveness),
1887
- ("target_liveness", target_liveness),
1888
- ("min_loudness", min_loudness),
1889
- ("max_loudness", max_loudness),
1890
- ("target_loudness", target_loudness),
1891
- ("min_mode", min_mode),
1892
- ("max_mode", max_mode),
1893
- ("target_mode", target_mode),
1894
- ("min_popularity", min_popularity),
1895
- ("max_popularity", max_popularity),
1896
- ("target_popularity", target_popularity),
1897
- ("min_speechiness", min_speechiness),
1898
- ("max_speechiness", max_speechiness),
1899
- ("target_speechiness", target_speechiness),
1900
- ("min_tempo", min_tempo),
1901
- ("max_tempo", max_tempo),
1902
- ("target_tempo", target_tempo),
1903
- ("min_time_signature", min_time_signature),
1904
- ("max_time_signature", max_time_signature),
1905
- ("target_time_signature", target_time_signature),
1906
- ("min_valence", min_valence),
1907
- ("max_valence", max_valence),
1908
- ("target_valence", target_valence),
1909
- ]
1910
- if v is not None
1911
- }
1912
- response = self._get(url, params=query_params)
1913
- response.raise_for_status()
1914
- return response.json()
1915
-
1916
- def get_recommendation_genres(
1917
- self,
1918
- ) -> Any:
1919
- """
1920
- Retrieves a list of available genre seeds for recommendations from the remote API.
1921
-
1922
- Args:
1923
- None: This function takes no arguments
1924
-
1925
- Returns:
1926
- dict: A JSON object containing available genre seeds for recommendations.
1927
-
1928
- Raises:
1929
- requests.exceptions.HTTPError: If the HTTP request to the API fails or returns an error status code.
1930
-
1931
- Tags:
1932
- get, list, api, recommendation, genres
1933
- """
1934
- url = f"{self.base_url}/recommendations/available-genre-seeds"
1935
- query_params = {}
1936
- response = self._get(url, params=query_params)
1937
- response.raise_for_status()
1938
- return response.json()
1939
-
1940
- def get_information_about_the_users_current_playback(
1941
- self, market=None, additional_types=None
1942
- ) -> Any:
1943
- """
1944
- Retrieves information about the user's current playback state from the music service.
1945
-
1946
- Args:
1947
- market: Optional; a string specifying an ISO 3166-1 alpha-2 country code to filter the response content. Defaults to None.
1948
- additional_types: Optional; a comma-separated string specifying additional item types to include in the response. Defaults to None.
1949
-
1950
- Returns:
1951
- A JSON object containing the user's current playback information, such as track, device, and playback state.
1952
-
1953
- Raises:
1954
- requests.exceptions.HTTPError: If the HTTP request to the music service API fails or returns an error status code.
1955
-
1956
- Tags:
1957
- get, playback, user, status, api
1958
- """
1959
- url = f"{self.base_url}/me/player"
1960
- query_params = {
1961
- k: v
1962
- for k, v in [("market", market), ("additional_types", additional_types)]
1963
- if v is not None
1964
- }
1965
- response = self._get(url, params=query_params)
1966
- response.raise_for_status()
1967
- return response.json()
1968
-
1969
- def transfer_a_users_playback(self, device_ids, play=None) -> Any:
1970
- """
1971
- Transfers the playback of a user's current session to one or more specified devices.
1972
-
1973
- Args:
1974
- device_ids: list or str. A list of device IDs (or a single device ID) to which playback should be transferred. This parameter is required.
1975
- play: bool or None. Whether playback should start on the new device(s) after transfer. If None, the playback state is not changed. Optional.
1976
-
1977
- Returns:
1978
- dict. A JSON response from the server, typically containing the status or details of the playback transfer.
1979
-
1980
- Raises:
1981
- ValueError: Raised if 'device_ids' is None.
1982
- requests.HTTPError: Raised if the underlying HTTP request fails or returns an error status code.
1983
-
1984
- Tags:
1985
- transfer, playback, management, api-call
1986
- """
1987
- if device_ids is None:
1988
- raise ValueError("Missing required parameter 'device_ids'")
1989
- request_body = {
1990
- "device_ids": device_ids,
1991
- "play": play,
1992
- }
1993
- request_body = {k: v for k, v in request_body.items() if v is not None}
1994
- url = f"{self.base_url}/me/player"
1995
- query_params = {}
1996
- response = self._put(url, data=request_body, params=query_params)
1997
- response.raise_for_status()
1998
- return response.json()
1999
-
2000
- def get_a_users_available_devices(
2001
- self,
2002
- ) -> Any:
2003
- """
2004
- Retrieves the list of devices available to the current user for playback control.
2005
-
2006
- Args:
2007
- None: This function takes no arguments
2008
-
2009
- Returns:
2010
- dict: A JSON object containing information about the user's available playback devices.
2011
-
2012
- Raises:
2013
- requests.HTTPError: If the HTTP request to the devices endpoint fails or returns a non-success status code.
2014
-
2015
- Tags:
2016
- get, list, devices, user, management
2017
- """
2018
- url = f"{self.base_url}/me/player/devices"
2019
- query_params = {}
2020
- response = self._get(url, params=query_params)
2021
- response.raise_for_status()
2022
- return response.json()
2023
-
2024
- def get_the_users_currently_playing_track(
2025
- self, market=None, additional_types=None
2026
- ) -> Any:
2027
- """
2028
- Retrieves information about the track currently being played by the user.
2029
-
2030
- Args:
2031
- market: Optional; a string specifying the market (country code) to filter the track data, ensuring results are relevant to a particular geographic location. Defaults to None.
2032
- additional_types: Optional; a string or comma-separated list specifying additional item types (such as 'episode') to include in the response. Defaults to None.
2033
-
2034
- Returns:
2035
- dict: A dictionary containing details about the currently playing track, or None if no data is available.
2036
-
2037
- Raises:
2038
- requests.HTTPError: If the underlying HTTP request fails or returns an unsuccessful status code.
2039
-
2040
- Tags:
2041
- get, track, player, user, async_job
2042
- """
2043
- url = f"{self.base_url}/me/player/currently-playing"
2044
- query_params = {
2045
- k: v
2046
- for k, v in [("market", market), ("additional_types", additional_types)]
2047
- if v is not None
2048
- }
2049
- response = self._get(url, params=query_params)
2050
- response.raise_for_status()
2051
- return response.json()
2052
-
2053
- def start_a_users_playback(
2054
- self, device_id=None, context_uri=None, uris=None, offset=None, position_ms=None
2055
- ) -> Any:
2056
- """
2057
- Starts or resumes playback of a user's Spotify player on the specified device, context, or track list.
2058
-
2059
- Args:
2060
- device_id: Optional[str]. The Spotify device ID on which playback should start. If not specified, the user's current active device is used.
2061
- context_uri: Optional[str]. Spotify URI of the context to play (album, playlist, or artist). Mutually exclusive with 'uris'.
2062
- uris: Optional[list[str]]. List of Spotify track URIs to play. Mutually exclusive with 'context_uri'.
2063
- offset: Optional[dict or int or str]. Indicates from which position in 'uris' or 'context_uri' playback should start. Can be a dict specifying 'position' or 'uri', or an integer index.
2064
- position_ms: Optional[int]. Start playback at this position in milliseconds.
2065
-
2066
- Returns:
2067
- Any. The JSON-parsed response from the Spotify Web API containing the result of the playback request.
2068
-
2069
- Raises:
2070
- requests.HTTPError: If the underlying HTTP request fails or an error response is returned from the Spotify Web API.
2071
-
2072
- Tags:
2073
- start, playback, ai, management, async_job
2074
- """
2075
- request_body = {
2076
- "context_uri": context_uri,
2077
- "uris": uris,
2078
- "offset": offset,
2079
- "position_ms": position_ms,
2080
- }
2081
- request_body = {k: v for k, v in request_body.items() if v is not None}
2082
- url = f"{self.base_url}/me/player/play"
2083
- query_params = {k: v for k, v in [("device_id", device_id)] if v is not None}
2084
- response = self._put(url, data=request_body, params=query_params)
2085
- response.raise_for_status()
2086
- return response.json()
2087
-
2088
- def pause_a_users_playback(self, device_id=None) -> Any:
2089
- """
2090
- Pauses the current playback for the authenticated user.
2091
-
2092
- Args:
2093
- device_id: Optional string representing the Spotify device ID on which playback should be paused. If not provided, the user's currently active device is targeted.
2094
-
2095
- Returns:
2096
- The JSON response from the Spotify API. This will typically be an empty object if the request was successful.
2097
-
2098
- Raises:
2099
- HTTPError: Raised when the Spotify API returns an error response, such as when the user doesn't have an active device, the user doesn't have a premium account, or there's an authentication issue.
2100
-
2101
- Tags:
2102
- pause, playback, control, spotify
2103
- """
2104
- url = f"{self.base_url}/me/player/pause"
2105
- query_params = {k: v for k, v in [("device_id", device_id)] if v is not None}
2106
- response = self._put(url, data={}, params=query_params)
2107
- response.raise_for_status()
2108
- return response.json()
2109
-
2110
- def skip_users_playback_to_next_track(self, device_id=None) -> Any:
2111
- """
2112
- Skips the user's playback to the next track on the current or specified device.
2113
-
2114
- Args:
2115
- device_id: Optional; the ID of the device on which to skip to the next track. If None, the currently active device is used.
2116
-
2117
- Returns:
2118
- dict: The response from the API after attempting to skip to the next track.
2119
-
2120
- Raises:
2121
- requests.HTTPError: If the HTTP request to skip to the next track fails with an unsuccessful status code.
2122
-
2123
- Tags:
2124
- skip, playback-control, user, spotify-api
2125
- """
2126
- url = f"{self.base_url}/me/player/next"
2127
- query_params = {k: v for k, v in [("device_id", device_id)] if v is not None}
2128
- response = self._post(url, data={}, params=query_params)
2129
- response.raise_for_status()
2130
- return response.json()
2131
-
2132
- def skip_users_playback_to_previous_track(self, device_id=None) -> Any:
2133
- """
2134
- Skips the user's playback to the previous track on the active or specified device.
2135
-
2136
- Args:
2137
- device_id: Optional; string representing the device ID to control. If not provided, defaults to the user's currently active device.
2138
-
2139
- Returns:
2140
- The JSON response from the API after attempting to skip to the previous track.
2141
-
2142
- Raises:
2143
- requests.HTTPError: If the HTTP request to the playback API fails or returns an error status.
2144
-
2145
- Tags:
2146
- playback-control, skip, previous-track, user, api
2147
- """
2148
- url = f"{self.base_url}/me/player/previous"
2149
- query_params = {k: v for k, v in [("device_id", device_id)] if v is not None}
2150
- response = self._post(url, data={}, params=query_params)
2151
- response.raise_for_status()
2152
- return response.json()
2153
-
2154
- def seek_to_position_in_currently_playing_track(
2155
- self, position_ms, device_id=None
2156
- ) -> Any:
2157
- """
2158
- Seeks to the specified position in the currently playing track for the user.
2159
-
2160
- Args:
2161
- position_ms: int. The position in milliseconds to seek to within the currently playing track. Must not be None.
2162
- device_id: Optional[str]. The ID of the target device on which to seek. If not specified, the currently active device is used.
2163
-
2164
- Returns:
2165
- dict. The JSON response from the API after seeking to the specified position.
2166
-
2167
- Raises:
2168
- ValueError: If 'position_ms' is None.
2169
- requests.exceptions.HTTPError: If the HTTP request to seek fails with a bad status code.
2170
-
2171
- Tags:
2172
- seek, player-control, api
2173
- """
2174
- if position_ms is None:
2175
- raise ValueError("Missing required parameter 'position_ms'")
2176
- url = f"{self.base_url}/me/player/seek"
2177
- query_params = {
2178
- k: v
2179
- for k, v in [("position_ms", position_ms), ("device_id", device_id)]
2180
- if v is not None
2181
- }
2182
- response = self._put(url, data={}, params=query_params)
2183
- response.raise_for_status()
2184
- return response.json()
2185
-
2186
- def set_repeat_mode_on_users_playback(self, state, device_id=None) -> Any:
2187
- """
2188
- Sets the repeat mode for the current user's playback on Spotify, optionally targeting a specific device.
2189
-
2190
- Args:
2191
- state: str. The desired repeat mode. Valid values include 'track', 'context', or 'off'.
2192
- device_id: Optional[str]. The Spotify device ID to target. If not specified, applies to the user's currently active device.
2193
-
2194
- Returns:
2195
- dict. The JSON response from the Spotify Web API after updating the repeat mode.
2196
-
2197
- Raises:
2198
- ValueError: Raised if the required 'state' parameter is not provided.
2199
- requests.HTTPError: Raised if the HTTP request to the Spotify API fails (e.g., due to a bad request or authorization error).
2200
-
2201
- Tags:
2202
- set, playback, repeat, management
2203
- """
2204
- if state is None:
2205
- raise ValueError("Missing required parameter 'state'")
2206
- url = f"{self.base_url}/me/player/repeat"
2207
- query_params = {
2208
- k: v
2209
- for k, v in [("state", state), ("device_id", device_id)]
2210
- if v is not None
2211
- }
2212
- response = self._put(url, data={}, params=query_params)
2213
- response.raise_for_status()
2214
- return response.json()
2215
-
2216
- def set_volume_for_users_playback(self, volume_percent, device_id=None) -> Any:
2217
- """
2218
- Set the playback volume for the current user's active device.
2219
-
2220
- Args:
2221
- volume_percent: int. The desired volume level as a percentage (0-100).
2222
- device_id: str, optional. The unique identifier for the target device. If not specified, the user's currently active device is used.
2223
-
2224
- Returns:
2225
- dict. The JSON response from the API containing the result of the volume change operation.
2226
-
2227
- Raises:
2228
- ValueError: If 'volume_percent' is None.
2229
- requests.HTTPError: If the HTTP request to the API fails or returns an error response.
2230
-
2231
- Tags:
2232
- set, volume, playback, user-management
2233
- """
2234
- if volume_percent is None:
2235
- raise ValueError("Missing required parameter 'volume_percent'")
2236
- url = f"{self.base_url}/me/player/volume"
2237
- query_params = {
2238
- k: v
2239
- for k, v in [("volume_percent", volume_percent), ("device_id", device_id)]
2240
- if v is not None
2241
- }
2242
- response = self._put(url, data={}, params=query_params)
2243
- response.raise_for_status()
2244
- return response.json()
2245
-
2246
- def toggle_shuffle_for_users_playback(self, state, device_id=None) -> Any:
2247
- """
2248
- Toggles the shuffle state for the user's playback on the specified device.
2249
-
2250
- Args:
2251
- state: bool. Whether to enable (True) or disable (False) shuffle playback.
2252
- device_id: str or None. The Spotify device ID on which to set shuffle mode. If None, the active device is used.
2253
-
2254
- Returns:
2255
- dict. The JSON response from the server containing the playback state information.
2256
-
2257
- Raises:
2258
- ValueError: If the required parameter 'state' is None.
2259
- HTTPError: If the server returns an unsuccessful status code.
2260
-
2261
- Tags:
2262
- toggle, shuffle, playback, user, management, spotify
2263
- """
2264
- if state is None:
2265
- raise ValueError("Missing required parameter 'state'")
2266
- url = f"{self.base_url}/me/player/shuffle"
2267
- query_params = {
2268
- k: v
2269
- for k, v in [("state", state), ("device_id", device_id)]
2270
- if v is not None
2271
- }
2272
- response = self._put(url, data={}, params=query_params)
2273
- response.raise_for_status()
2274
- return response.json()
2275
-
2276
- def get_recently_played(self, limit=None, after=None, before=None) -> Any:
2277
- """
2278
- Retrieves the current user's recently played tracks from the Spotify API, optionally filtered by time or limited in count.
2279
-
2280
- Args:
2281
- limit: Optional; int or None. Maximum number of items to return (default set by API).
2282
- after: Optional; int, Unix timestamp in milliseconds or None. Returns items played after this time.
2283
- before: Optional; int, Unix timestamp in milliseconds or None. Returns items played before this time.
2284
-
2285
- Returns:
2286
- dict: A JSON object containing the list of recently played track objects and related metadata.
2287
-
2288
- Raises:
2289
- requests.exceptions.HTTPError: If the HTTP request returned an unsuccessful status code.
2290
-
2291
- Tags:
2292
- get, list, spotify-api, user-library, recently-played
2293
- """
2294
- url = f"{self.base_url}/me/player/recently-played"
2295
- query_params = {
2296
- k: v
2297
- for k, v in [("limit", limit), ("after", after), ("before", before)]
2298
- if v is not None
2299
- }
2300
- response = self._get(url, params=query_params)
2301
- response.raise_for_status()
2302
- return response.json()
2303
-
2304
- def get_queue(
2305
- self,
2306
- ) -> Any:
2307
- """
2308
- Retrieves the current playback queue for the user from the music player API.
2309
-
2310
- Args:
2311
- None: This function takes no arguments
2312
-
2313
- Returns:
2314
- dict: The JSON response containing the user's current playback queue.
2315
-
2316
- Raises:
2317
- requests.HTTPError: If the HTTP request to the player queue endpoint returns an unsuccessful status code.
2318
-
2319
- Tags:
2320
- get, queue, api, player
2321
- """
2322
- url = f"{self.base_url}/me/player/queue"
2323
- query_params = {}
2324
- response = self._get(url, params=query_params)
2325
- response.raise_for_status()
2326
- return response.json()
2327
-
2328
- def add_to_queue(self, uri, device_id=None) -> Any:
2329
- """
2330
- Adds an item to the user's playback queue on the specified device using its URI.
2331
-
2332
- Args:
2333
- uri: str. The Spotify URI of the item to add to the queue. Must not be None.
2334
- device_id: Optional[str]. The ID of the target device for playback. If None, uses the user's currently active device.
2335
-
2336
- Returns:
2337
- dict. The JSON response from the Spotify API containing the result of the queue addition.
2338
-
2339
- Raises:
2340
- ValueError: If the 'uri' parameter is None.
2341
- requests.HTTPError: If the HTTP request to the Spotify API fails.
2342
-
2343
- Tags:
2344
- add, queue, spotify, api, player
2345
- """
2346
- if uri is None:
2347
- raise ValueError("Missing required parameter 'uri'")
2348
- url = f"{self.base_url}/me/player/queue"
2349
- query_params = {
2350
- k: v for k, v in [("uri", uri), ("device_id", device_id)] if v is not None
2351
- }
2352
- response = self._post(url, data={}, params=query_params)
2353
- response.raise_for_status()
2354
- return response.json()
2355
-
2356
- def get_available_markets(
2357
- self,
2358
- ) -> Any:
2359
- """
2360
- Retrieves a list of available markets from the API endpoint.
2361
-
2362
- Args:
2363
- None: This function takes no arguments
2364
-
2365
- Returns:
2366
- A JSON-decoded response containing information about available markets.
2367
-
2368
- Raises:
2369
- requests.HTTPError: If the HTTP request to the API endpoint fails or an error status code is returned.
2370
-
2371
- Tags:
2372
- get, markets, api, list, fetch
2373
- """
2374
- url = f"{self.base_url}/markets"
2375
- query_params = {}
2376
- response = self._get(url, params=query_params)
2377
- response.raise_for_status()
2378
- return response.json()
2379
-
2380
- def get_users_top_artists(self, time_range=None, limit=None, offset=None) -> Any:
2381
- """
2382
- Retrieves the current user's top artists from the API, supporting optional filtering by time range, result limit, and pagination offset.
2383
-
2384
- Args:
2385
- time_range: Optional; a string indicating the time range over which to retrieve top artists (e.g., 'short_term', 'medium_term', 'long_term'). If None, the API default is used.
2386
- limit: Optional; an integer specifying the maximum number of artists to return. If None, the API default is used.
2387
- offset: Optional; an integer specifying the index of the first artist to return for pagination. If None, the API default is used.
2388
-
2389
- Returns:
2390
- A JSON-deserialized object containing the user's top artists and related metadata as returned by the API.
2391
-
2392
- Raises:
2393
- requests.HTTPError: If the API request fails or returns an unsuccessful HTTP status code.
2394
-
2395
- Tags:
2396
- get, list, artists, user, ai, batch
2397
- """
2398
- url = f"{self.base_url}/me/top/artists"
2399
- query_params = {
2400
- k: v
2401
- for k, v in [
2402
- ("time_range", time_range),
2403
- ("limit", limit),
2404
- ("offset", offset),
2405
- ]
2406
- if v is not None
2407
- }
2408
- response = self._get(url, params=query_params)
2409
- response.raise_for_status()
2410
- return response.json()
2411
-
2412
- def get_users_top_tracks(self, time_range=None, limit=None, offset=None) -> Any:
2413
- """
2414
- Retrieves the current user's top tracks from the service within an optional time range, with pagination support.
2415
-
2416
- Args:
2417
- time_range: Optional; str. Specifies the time range for top tracks (e.g., 'short_term', 'medium_term', 'long_term').
2418
- limit: Optional; int. The maximum number of tracks to return.
2419
- offset: Optional; int. The index of the first track to return, used for pagination.
2420
-
2421
- Returns:
2422
- dict. The JSON response containing the user's top tracks and associated metadata.
2423
-
2424
- Raises:
2425
- requests.HTTPError: If the HTTP request fails or returns an unsuccessful status code.
2426
-
2427
- Tags:
2428
- get, list, user, tracks, ai
2429
- """
2430
- url = f"{self.base_url}/me/top/tracks"
2431
- query_params = {
2432
- k: v
2433
- for k, v in [
2434
- ("time_range", time_range),
2435
- ("limit", limit),
2436
- ("offset", offset),
2437
- ]
2438
- if v is not None
2439
- }
2440
- response = self._get(url, params=query_params)
2441
- response.raise_for_status()
2442
- return response.json()
2443
-
2444
- def list_tools(self):
2445
- return [
2446
- self.get_an_album,
2447
- self.get_multiple_albums,
2448
- self.get_an_albums_tracks,
2449
- self.get_an_artist,
2450
- self.get_multiple_artists,
2451
- self.get_an_artists_albums,
2452
- self.get_an_artists_top_tracks,
2453
- self.get_an_artists_related_artists,
2454
- self.get_a_show,
2455
- self.get_multiple_shows,
2456
- self.get_a_shows_episodes,
2457
- self.get_an_episode,
2458
- self.get_multiple_episodes,
2459
- self.get_an_audiobook,
2460
- self.get_multiple_audiobooks,
2461
- self.get_audiobook_chapters,
2462
- self.get_users_saved_audiobooks,
2463
- self.save_audiobooks_user,
2464
- self.remove_audiobooks_user,
2465
- self.check_users_saved_audiobooks,
2466
- self.get_a_chapter,
2467
- self.get_several_chapters,
2468
- self.get_track,
2469
- self.get_several_tracks,
2470
- self.search,
2471
- self.get_current_users_profile,
2472
- self.get_playlist,
2473
- self.change_playlist_details,
2474
- self.get_playlists_tracks,
2475
- self.add_tracks_to_playlist,
2476
- self.reorder_or_replace_playlists_tracks,
2477
- self.get_a_list_of_current_users_playlists,
2478
- self.get_users_saved_albums,
2479
- self.check_users_saved_albums,
2480
- self.get_users_saved_tracks,
2481
- self.save_tracks_user,
2482
- self.check_users_saved_tracks,
2483
- self.get_users_saved_episodes,
2484
- self.save_episodes_user,
2485
- self.check_users_saved_episodes,
2486
- self.get_users_saved_shows,
2487
- self.check_users_saved_shows,
2488
- self.get_users_profile,
2489
- self.get_list_users_playlists,
2490
- self.create_playlist,
2491
- self.follow_playlist,
2492
- self.unfollow_playlist,
2493
- self.get_featured_playlists,
2494
- self.get_categories,
2495
- self.get_a_category,
2496
- self.get_a_categories_playlists,
2497
- self.get_playlist_cover,
2498
- self.get_new_releases,
2499
- self.get_followed,
2500
- self.follow_artists_users,
2501
- self.check_current_user_follows,
2502
- self.check_if_user_follows_playlist,
2503
- self.get_several_audio_features,
2504
- self.get_audio_features,
2505
- self.get_audio_analysis,
2506
- self.get_recommendations,
2507
- self.get_recommendation_genres,
2508
- self.get_information_about_the_users_current_playback,
2509
- self.transfer_a_users_playback,
2510
- self.get_a_users_available_devices,
2511
- self.get_the_users_currently_playing_track,
2512
- self.start_a_users_playback,
2513
- self.pause_a_users_playback,
2514
- self.skip_users_playback_to_next_track,
2515
- self.skip_users_playback_to_previous_track,
2516
- self.seek_to_position_in_currently_playing_track,
2517
- self.set_repeat_mode_on_users_playback,
2518
- self.set_volume_for_users_playback,
2519
- self.toggle_shuffle_for_users_playback,
2520
- self.get_recently_played,
2521
- self.get_queue,
2522
- self.add_to_queue,
2523
- self.get_available_markets,
2524
- self.get_users_top_artists,
2525
- self.get_users_top_tracks,
2526
- ]