spotifywebapiPython 1.0.91__py3-none-any.whl → 1.0.93__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.

Potentially problematic release.


This version of spotifywebapiPython might be problematic. Click here for more details.

Files changed (32) hide show
  1. {spotifywebapiPython-1.0.91.dist-info → spotifywebapiPython-1.0.93.dist-info}/METADATA +1 -1
  2. {spotifywebapiPython-1.0.91.dist-info → spotifywebapiPython-1.0.93.dist-info}/RECORD +32 -32
  3. spotifywebapipython/const.py +1 -1
  4. spotifywebapipython/docs/__init__.html +34 -2
  5. spotifywebapipython/docs/index.html +2 -2
  6. spotifywebapipython/docs/search.js +1 -1
  7. spotifywebapipython/docs/spotifywebapiPython/const.html +3 -3
  8. spotifywebapipython/docs/spotifywebapiPython/saappmessages.html +20 -2
  9. spotifywebapipython/docs/spotifywebapiPython/sautils.html +2 -2
  10. spotifywebapipython/docs/spotifywebapiPython/spotifyapierror.html +2 -2
  11. spotifywebapipython/docs/spotifywebapiPython/spotifyapimessage.html +2 -2
  12. spotifywebapipython/docs/spotifywebapiPython/spotifyauthtoken.html +2 -2
  13. spotifywebapipython/docs/spotifywebapiPython/spotifyclient.html +524 -38
  14. spotifywebapipython/docs/spotifywebapiPython/spotifydiscovery.html +2 -2
  15. spotifywebapipython/docs/spotifywebapiPython/spotifywebapiauthenticationerror.html +2 -2
  16. spotifywebapipython/docs/spotifywebapiPython/spotifywebapierror.html +2 -2
  17. spotifywebapipython/models/artistsimplified.py +4 -0
  18. spotifywebapipython/models/context.py +1 -3
  19. spotifywebapipython/models/device.py +3 -0
  20. spotifywebapipython/models/pageobject.py +2 -2
  21. spotifywebapipython/models/playlistsimplified.py +1 -1
  22. spotifywebapipython/models/spotifyconnectdevice.py +1 -0
  23. spotifywebapipython/models/spotifyconnectdevices.py +1 -0
  24. spotifywebapipython/models/tracksimplified.py +1 -1
  25. spotifywebapipython/models/zeroconfdiscoveryresult.py +2 -1
  26. spotifywebapipython/saappmessages.py +5 -0
  27. spotifywebapipython/spotifyclient.py +668 -285
  28. spotifywebapipython/zeroconfapi/zeroconfgetinfo.py +5 -0
  29. spotifywebapipython/zeroconfapi/zeroconfgetinfoalias.py +1 -0
  30. {spotifywebapiPython-1.0.91.dist-info → spotifywebapiPython-1.0.93.dist-info}/LICENSE +0 -0
  31. {spotifywebapiPython-1.0.91.dist-info → spotifywebapiPython-1.0.93.dist-info}/WHEEL +0 -0
  32. {spotifywebapiPython-1.0.91.dist-info → spotifywebapiPython-1.0.93.dist-info}/top_level.txt +0 -0
@@ -622,137 +622,6 @@ class SpotifyClient:
622
622
  msg.ResponseData = responseData
623
623
 
624
624
 
625
- def _GetPlayerNowPlayingAlbumUri(self) -> str:
626
- """
627
- Returns the album uri value of the currently playing media if something is
628
- playing; otherwise, null is returned.
629
- """
630
- result:str = None
631
-
632
- # get nowplaying status.
633
- _logsi.LogVerbose("Querying NowPlaying status of Spotify player")
634
- nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying()
635
-
636
- # is a track playing? if so, return the album uri value.
637
- if nowPlaying is not None:
638
- _logsi.LogVerbose("NowPlaying data: %s" % str(nowPlaying))
639
- if nowPlaying.CurrentlyPlayingType in ['track']:
640
- trackItem:Track = nowPlaying.Item
641
- if (trackItem is not None) and (trackItem.Album is not None):
642
- result = trackItem.Album.Uri
643
-
644
- return result
645
-
646
-
647
- def _GetPlayerNowPlayingArtistUri(self) -> str:
648
- """
649
- Returns the artist uri value of the currently playing media if something is
650
- playing; otherwise, null is returned.
651
- """
652
- result:str = None
653
-
654
- # get nowplaying status.
655
- _logsi.LogVerbose("Querying NowPlaying status of Spotify player")
656
- nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying()
657
-
658
- # is a track playing? if so, return the artist uri value.
659
- if nowPlaying is not None:
660
- _logsi.LogVerbose("NowPlaying data: %s" % str(nowPlaying))
661
- if nowPlaying.CurrentlyPlayingType in ['track']:
662
- trackItem:Track = nowPlaying.Item
663
- if (trackItem is not None) and (len(trackItem.Artists) > 0):
664
- result = trackItem.Artists[0].Uri
665
-
666
- return result
667
-
668
-
669
- def _GetPlayerNowPlayingAudiobookUri(self) -> str:
670
- """
671
- Returns the audiobook uri value of the currently playing media if something is
672
- playing; otherwise, null is returned.
673
- """
674
- result:str = None
675
-
676
- # get nowplaying status.
677
- _logsi.LogVerbose("Querying NowPlaying status of Spotify player")
678
- nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying(additionalTypes='episode')
679
-
680
- # is an chapter playing? if so, return the parent show uri value.
681
- if nowPlaying is not None:
682
- _logsi.LogVerbose("NowPlaying data: %s" % str(nowPlaying))
683
- if nowPlaying.CurrentlyPlayingType in ['episode']:
684
- playingItem:Chapter = nowPlaying.Item
685
- if (playingItem is not None):
686
- chapter:Chapter = self.GetChapter(playingItem.Id)
687
- result = chapter.Audiobook.Uri
688
- else:
689
- raise SpotifyApiError("Currently playing item is not a Audiobook Chapter", logsi=_logsi)
690
-
691
- return result
692
-
693
-
694
- def _GetPlayerNowPlayingShowUri(self) -> str:
695
- """
696
- Returns the show uri value of the currently playing media if something is
697
- playing; otherwise, null is returned.
698
- """
699
- result:str = None
700
-
701
- # get nowplaying status.
702
- _logsi.LogVerbose("Querying NowPlaying status of Spotify player")
703
- nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying(additionalTypes='episode')
704
-
705
- # is an episode playing? if so, return the parent show uri value.
706
- if nowPlaying is not None:
707
- _logsi.LogVerbose("NowPlaying data: %s" % str(nowPlaying))
708
- if nowPlaying.CurrentlyPlayingType in ['episode']:
709
- playingItem:Episode = nowPlaying.Item
710
- if (playingItem is not None):
711
- episode:Episode = self.GetEpisode(playingItem.Id)
712
- result = episode.Show.Uri
713
- else:
714
- raise SpotifyApiError("Currently playing item is not a Show Episode", logsi=_logsi)
715
-
716
- return result
717
-
718
-
719
- def _GetPlayerNowPlayingUri(
720
- self,
721
- additionalTypes:str=None,
722
- ) -> str:
723
- """
724
- Returns the uri value of the currently playing media type if something is
725
- playing; otherwise, null is returned.
726
-
727
- Args:
728
- additionalTypes (str):
729
- An item type that your client supports besides the default track type.
730
- Valid types are: `track` and `episode`.
731
- Specify `episode` to get podcast track information.
732
- """
733
- result:str = None
734
-
735
- # get nowplaying status.
736
- _logsi.LogVerbose("Querying NowPlaying status of Spotify player")
737
- nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying(additionalTypes=additionalTypes)
738
-
739
- # is anything playing? if so, return the uri value.
740
- if nowPlaying is not None:
741
- _logsi.LogVerbose("NowPlaying data: %s" % str(nowPlaying))
742
- if nowPlaying.Item is not None:
743
- if additionalTypes is None:
744
- # if not validating uri type then just return the uri.
745
- result = nowPlaying.Item.Uri
746
- elif nowPlaying.CurrentlyPlayingType == additionalTypes:
747
- # if validating uri type then return uri if nowplaying types matches desired type.
748
- result = nowPlaying.Item.Uri
749
- else:
750
- # otherwise nowplaying type is not the desired type!
751
- raise SpotifyApiError("Currently playing item is not a %s" % additionalTypes, logsi=_logsi)
752
-
753
- return result
754
-
755
-
756
625
  def _ValidateMarket(self,
757
626
  market:str,
758
627
  ) -> str:
@@ -1121,6 +990,7 @@ class SpotifyClient:
1121
990
  # no results to process - this is pass or fail.
1122
991
  return
1123
992
 
993
+ except SpotifyApiError: raise # pass handled exceptions on thru
1124
994
  except SpotifyWebApiError: raise # pass handled exceptions on thru
1125
995
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
1126
996
  except Exception as ex:
@@ -1193,7 +1063,7 @@ class SpotifyClient:
1193
1063
 
1194
1064
  # if uris not specified, then return currently playing uri value.
1195
1065
  if (uris is None) or (len(uris.strip()) == 0):
1196
- uris = self._GetPlayerNowPlayingUri()
1066
+ uris = self.GetPlayerNowPlayingUri(None)
1197
1067
  if uris is None:
1198
1068
  raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'uris'), logsi=_logsi)
1199
1069
 
@@ -1352,6 +1222,7 @@ class SpotifyClient:
1352
1222
  # no results to process - this is pass or fail.
1353
1223
  return
1354
1224
 
1225
+ except SpotifyApiError: raise # pass handled exceptions on thru
1355
1226
  except SpotifyWebApiError: raise # pass handled exceptions on thru
1356
1227
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
1357
1228
  except Exception as ex:
@@ -1413,7 +1284,7 @@ class SpotifyClient:
1413
1284
 
1414
1285
  # if ids not specified, then return currently playing album id value.
1415
1286
  if (ids is None) or (len(ids.strip()) == 0):
1416
- uri = self._GetPlayerNowPlayingAlbumUri()
1287
+ uri = self.GetPlayerNowPlayingAlbumUri()
1417
1288
  if uri is not None:
1418
1289
  ids = SpotifyClient.GetIdFromUri(uri)
1419
1290
  else:
@@ -1511,7 +1382,7 @@ class SpotifyClient:
1511
1382
 
1512
1383
  # if ids not specified, then return currently playing artist id value.
1513
1384
  if (ids is None) or (len(ids.strip()) == 0):
1514
- uri = self._GetPlayerNowPlayingArtistUri()
1385
+ uri = self.GetPlayerNowPlayingArtistUri()
1515
1386
  if uri is not None:
1516
1387
  ids = SpotifyClient.GetIdFromUri(uri)
1517
1388
  else:
@@ -1607,7 +1478,7 @@ class SpotifyClient:
1607
1478
 
1608
1479
  # if ids not specified, then return currently playing id value.
1609
1480
  if (ids is None) or (len(ids.strip()) == 0):
1610
- uri = self._GetPlayerNowPlayingAudiobookUri()
1481
+ uri = self.GetPlayerNowPlayingAudiobookUri()
1611
1482
  if uri is not None:
1612
1483
  ids = SpotifyClient.GetIdFromUri(uri)
1613
1484
  else:
@@ -1702,7 +1573,7 @@ class SpotifyClient:
1702
1573
 
1703
1574
  # if ids not specified, then return currently playing id value.
1704
1575
  if (ids is None) or (len(ids.strip()) == 0):
1705
- uri = self._GetPlayerNowPlayingUri('episode')
1576
+ uri = self.GetPlayerNowPlayingUri('episode')
1706
1577
  if uri is not None:
1707
1578
  ids = SpotifyClient.GetIdFromUri(uri)
1708
1579
  else:
@@ -1884,7 +1755,7 @@ class SpotifyClient:
1884
1755
 
1885
1756
  # if ids not specified, then return currently playing id value.
1886
1757
  if (ids is None) or (len(ids.strip()) == 0):
1887
- uri = self._GetPlayerNowPlayingShowUri()
1758
+ uri = self.GetPlayerNowPlayingShowUri()
1888
1759
  if uri is not None:
1889
1760
  ids = SpotifyClient.GetIdFromUri(uri)
1890
1761
  else:
@@ -1979,7 +1850,7 @@ class SpotifyClient:
1979
1850
 
1980
1851
  # if ids not specified, then return currently playing id value.
1981
1852
  if (ids is None) or (len(ids.strip()) == 0):
1982
- uri = self._GetPlayerNowPlayingUri('track')
1853
+ uri = self.GetPlayerNowPlayingUri('track')
1983
1854
  if uri is not None:
1984
1855
  ids = SpotifyClient.GetIdFromUri(uri)
1985
1856
  else:
@@ -2202,6 +2073,7 @@ class SpotifyClient:
2202
2073
  _logsi.LogString(SILevel.Verbose, TRACE_METHOD_RESULT % apiMethodName, result)
2203
2074
  return result
2204
2075
 
2076
+ except SpotifyApiError: raise # pass handled exceptions on thru
2205
2077
  except SpotifyWebApiError: raise # pass handled exceptions on thru
2206
2078
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
2207
2079
  except Exception as ex:
@@ -2339,6 +2211,7 @@ class SpotifyClient:
2339
2211
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
2340
2212
  return result
2341
2213
 
2214
+ except SpotifyApiError: raise # pass handled exceptions on thru
2342
2215
  except SpotifyWebApiError: raise # pass handled exceptions on thru
2343
2216
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
2344
2217
  except Exception as ex:
@@ -2352,9 +2225,10 @@ class SpotifyClient:
2352
2225
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
2353
2226
 
2354
2227
 
2355
- def FollowArtists(self,
2356
- ids:str=None,
2357
- ) -> None:
2228
+ def FollowArtists(
2229
+ self,
2230
+ ids:str=None,
2231
+ ) -> None:
2358
2232
  """
2359
2233
  Add the current user as a follower of one or more artists.
2360
2234
 
@@ -2395,7 +2269,7 @@ class SpotifyClient:
2395
2269
 
2396
2270
  # if ids not specified, then return currently playing artist id value.
2397
2271
  if (ids is None) or (len(ids.strip()) == 0):
2398
- uri = self._GetPlayerNowPlayingArtistUri()
2272
+ uri = self.GetPlayerNowPlayingArtistUri()
2399
2273
  if uri is not None:
2400
2274
  ids = SpotifyClient.GetIdFromUri(uri)
2401
2275
  else:
@@ -2423,6 +2297,7 @@ class SpotifyClient:
2423
2297
  # no results to process - this is pass or fail.
2424
2298
  return
2425
2299
 
2300
+ except SpotifyApiError: raise # pass handled exceptions on thru
2426
2301
  except SpotifyWebApiError: raise # pass handled exceptions on thru
2427
2302
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
2428
2303
  except Exception as ex:
@@ -2436,10 +2311,11 @@ class SpotifyClient:
2436
2311
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
2437
2312
 
2438
2313
 
2439
- def FollowPlaylist(self,
2440
- playlistId:str,
2441
- public:bool=True
2442
- ) -> None:
2314
+ def FollowPlaylist(
2315
+ self,
2316
+ playlistId:str=None,
2317
+ public:bool=True
2318
+ ) -> None:
2443
2319
  """
2444
2320
  Add the current user as a follower of a playlist.
2445
2321
 
@@ -2449,6 +2325,7 @@ class SpotifyClient:
2449
2325
  playlistId (str):
2450
2326
  The Spotify ID of the playlist.
2451
2327
  Example: `3cEYpjA9oz9GiPac4AsH4n`
2328
+ If null, the currently playing playlist uri id value is used.
2452
2329
  public (bool):
2453
2330
  If true the playlist will be included in user's public playlists, if false it
2454
2331
  will remain private.
@@ -2479,6 +2356,14 @@ class SpotifyClient:
2479
2356
  apiMethodParms.AppendKeyValue("public", public)
2480
2357
  _logsi.LogMethodParmList(SILevel.Verbose, "Add the current user as a follower of a playlist", apiMethodParms)
2481
2358
 
2359
+ # if playlistId not specified, then return currently playing playlist id value.
2360
+ if (playlistId is None) or (len(playlistId.strip()) == 0):
2361
+ uri = self.GetPlayerNowPlayingPlaylistUri()
2362
+ if uri is not None:
2363
+ playlistId = SpotifyClient.GetIdFromUri(uri)
2364
+ else:
2365
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'playlistId'), logsi=_logsi)
2366
+
2482
2367
  # build spotify web api request parameters.
2483
2368
  reqData:dict = {}
2484
2369
  if public is not None:
@@ -2494,6 +2379,7 @@ class SpotifyClient:
2494
2379
  # no results to process - this is pass or fail.
2495
2380
  return
2496
2381
 
2382
+ except SpotifyApiError: raise # pass handled exceptions on thru
2497
2383
  except SpotifyWebApiError: raise # pass handled exceptions on thru
2498
2384
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
2499
2385
  except Exception as ex:
@@ -2569,6 +2455,7 @@ class SpotifyClient:
2569
2455
  # no results to process - this is pass or fail.
2570
2456
  return
2571
2457
 
2458
+ except SpotifyApiError: raise # pass handled exceptions on thru
2572
2459
  except SpotifyWebApiError: raise # pass handled exceptions on thru
2573
2460
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
2574
2461
  except Exception as ex:
@@ -2582,10 +2469,11 @@ class SpotifyClient:
2582
2469
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
2583
2470
 
2584
2471
 
2585
- def GetAlbum(self,
2586
- albumId:str,
2587
- market:str=None,
2588
- ) -> Album:
2472
+ def GetAlbum(
2473
+ self,
2474
+ albumId:str=None,
2475
+ market:str=None,
2476
+ ) -> Album:
2589
2477
  """
2590
2478
  Get Spotify catalog information for a single album.
2591
2479
 
@@ -2593,6 +2481,8 @@ class SpotifyClient:
2593
2481
  albumId (str):
2594
2482
  The Spotify ID of the album.
2595
2483
  Example: `6vc9OTcyd3hyzabCmsdnwE`
2484
+ If null, the currently playing album uri id value is used; a Spotify Free or Premium account
2485
+ is required to correctly read the currently playing context.
2596
2486
  market (str):
2597
2487
  An ISO 3166-1 alpha-2 country code. If a country code is specified, only content that
2598
2488
  is available in that market will be returned. If a valid user access token is specified
@@ -2616,6 +2506,10 @@ class SpotifyClient:
2616
2506
  <summary>Sample Code</summary>
2617
2507
  ```python
2618
2508
  .. include:: ../docs/include/samplecode/SpotifyClient/GetAlbum.py
2509
+ ```
2510
+ <summary>Sample Code - NowPlaying</summary>
2511
+ ```python
2512
+ .. include:: ../docs/include/samplecode/SpotifyClient/GetAlbum_NowPlaying.py
2619
2513
  ```
2620
2514
  </details>
2621
2515
  """
@@ -2634,6 +2528,14 @@ class SpotifyClient:
2634
2528
  # ensure market was either supplied or implied; default if neither.
2635
2529
  market = self._ValidateMarket(market)
2636
2530
 
2531
+ # if albumId not specified, then return currently playing album id value.
2532
+ if (albumId is None) or (len(albumId.strip()) == 0):
2533
+ uri = self.GetPlayerNowPlayingAlbumUri()
2534
+ if uri is not None:
2535
+ albumId = SpotifyClient.GetIdFromUri(uri)
2536
+ else:
2537
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'albumId'), logsi=_logsi)
2538
+
2637
2539
  # build spotify web api request parameters.
2638
2540
  urlParms:dict = {}
2639
2541
  if market is not None:
@@ -2652,6 +2554,7 @@ class SpotifyClient:
2652
2554
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
2653
2555
  return result
2654
2556
 
2557
+ except SpotifyApiError: raise # pass handled exceptions on thru
2655
2558
  except SpotifyWebApiError: raise # pass handled exceptions on thru
2656
2559
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
2657
2560
  except Exception as ex:
@@ -2810,14 +2713,18 @@ class SpotifyClient:
2810
2713
  # update result object with final paging details.
2811
2714
  result.Total = pageObj.Total
2812
2715
 
2813
- # sort items on Name property, ascending order.
2814
- if (len(result.Items) > 0) and (sortResult is True):
2815
- result.Items.sort(key=lambda x: (x.Album.Name or "").lower(), reverse=False)
2716
+ # sort result items.
2717
+ if (len(result.Items) > 0):
2718
+ if (sortResult is True):
2719
+ result.Items.sort(key=lambda x: (x.Album.Name or "").lower(), reverse=False)
2720
+ else:
2721
+ result.Items.sort(key=lambda x: (x.AddedAt or "").lower(), reverse=True)
2816
2722
 
2817
2723
  # trace.
2818
2724
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
2819
2725
  return result
2820
2726
 
2727
+ except SpotifyApiError: raise # pass handled exceptions on thru
2821
2728
  except SpotifyWebApiError: raise # pass handled exceptions on thru
2822
2729
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
2823
2730
  except Exception as ex:
@@ -2971,14 +2878,16 @@ class SpotifyClient:
2971
2878
  # update result object with final paging details.
2972
2879
  result.Total = pageObj.Total
2973
2880
 
2974
- # sort items on Name property, ascending order.
2975
- if (len(result.Items) > 0) and (sortResult is True):
2976
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
2881
+ # sort result items.
2882
+ if (len(result.Items) > 0):
2883
+ if (sortResult is True):
2884
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
2977
2885
 
2978
2886
  # trace.
2979
2887
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
2980
2888
  return result
2981
2889
 
2890
+ except SpotifyApiError: raise # pass handled exceptions on thru
2982
2891
  except SpotifyWebApiError: raise # pass handled exceptions on thru
2983
2892
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
2984
2893
  except Exception as ex:
@@ -3069,6 +2978,7 @@ class SpotifyClient:
3069
2978
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[Album]'), result)
3070
2979
  return result
3071
2980
 
2981
+ except SpotifyApiError: raise # pass handled exceptions on thru
3072
2982
  except SpotifyWebApiError: raise # pass handled exceptions on thru
3073
2983
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
3074
2984
  except Exception as ex:
@@ -3082,13 +2992,14 @@ class SpotifyClient:
3082
2992
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
3083
2993
 
3084
2994
 
3085
- def GetAlbumTracks(self,
3086
- albumId:str,
3087
- limit:int=20,
3088
- offset:int=0,
3089
- market:str=None,
3090
- limitTotal:int=None
3091
- ) -> TrackPageSimplified:
2995
+ def GetAlbumTracks(
2996
+ self,
2997
+ albumId:str=None,
2998
+ limit:int=20,
2999
+ offset:int=0,
3000
+ market:str=None,
3001
+ limitTotal:int=None
3002
+ ) -> TrackPageSimplified:
3092
3003
  """
3093
3004
  Get Spotify catalog information about an album's tracks.
3094
3005
 
@@ -3098,6 +3009,8 @@ class SpotifyClient:
3098
3009
  albumId (str):
3099
3010
  The Spotify ID of the album.
3100
3011
  Example: `6vc9OTcyd3hyzabCmsdnwE`
3012
+ If null, the currently playing album uri id value is used; a Spotify Free or Premium account
3013
+ is required to correctly read the currently playing context.
3101
3014
  limit (int):
3102
3015
  The maximum number of items to return in a page of items when manual paging is used.
3103
3016
  Default: 20, Range: 1 to 50.
@@ -3176,6 +3089,14 @@ class SpotifyClient:
3176
3089
  # ensure market was either supplied or implied; default if neither.
3177
3090
  market = self._ValidateMarket(market)
3178
3091
 
3092
+ # if albumId not specified, then return currently playing album id value.
3093
+ if (albumId is None) or (len(albumId.strip()) == 0):
3094
+ uri = self.GetPlayerNowPlayingAlbumUri()
3095
+ if uri is not None:
3096
+ albumId = SpotifyClient.GetIdFromUri(uri)
3097
+ else:
3098
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'albumId'), logsi=_logsi)
3099
+
3179
3100
  # build spotify web api request parameters.
3180
3101
  urlParms:dict = \
3181
3102
  {
@@ -3230,6 +3151,7 @@ class SpotifyClient:
3230
3151
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
3231
3152
  return result
3232
3153
 
3154
+ except SpotifyApiError: raise # pass handled exceptions on thru
3233
3155
  except SpotifyWebApiError: raise # pass handled exceptions on thru
3234
3156
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
3235
3157
  except Exception as ex:
@@ -3243,9 +3165,10 @@ class SpotifyClient:
3243
3165
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
3244
3166
 
3245
3167
 
3246
- def GetArtist(self,
3247
- artistId:str,
3248
- ) -> Artist:
3168
+ def GetArtist(
3169
+ self,
3170
+ artistId:str=None,
3171
+ ) -> Artist:
3249
3172
  """
3250
3173
  Get Spotify catalog information for a single artist identified by their unique Spotify ID.
3251
3174
 
@@ -3253,6 +3176,8 @@ class SpotifyClient:
3253
3176
  artistId (str):
3254
3177
  The Spotify ID of the artist.
3255
3178
  Example: `6APm8EjxOHSYM5B4i3vT3q`
3179
+ If null, the currently playing artist uri id value is used; a Spotify Free or Premium account
3180
+ is required to correctly read the currently playing context.
3256
3181
 
3257
3182
  Returns:
3258
3183
  An `Artist` object that contains the artist details.
@@ -3268,6 +3193,10 @@ class SpotifyClient:
3268
3193
  <summary>Sample Code</summary>
3269
3194
  ```python
3270
3195
  .. include:: ../docs/include/samplecode/SpotifyClient/GetArtist.py
3196
+ ```
3197
+ <summary>Sample Code - NowPlaying</summary>
3198
+ ```python
3199
+ .. include:: ../docs/include/samplecode/SpotifyClient/GetArtist_NowPlaying.py
3271
3200
  ```
3272
3201
  </details>
3273
3202
  """
@@ -3282,6 +3211,14 @@ class SpotifyClient:
3282
3211
  apiMethodParms.AppendKeyValue("artistId", artistId)
3283
3212
  _logsi.LogMethodParmList(SILevel.Verbose, "Get Spotify catalog information for a single artist", apiMethodParms)
3284
3213
 
3214
+ # if artistId not specified, then return currently playing artist id value.
3215
+ if (artistId is None) or (len(artistId.strip()) == 0):
3216
+ uri = self.GetPlayerNowPlayingArtistUri()
3217
+ if uri is not None:
3218
+ artistId = SpotifyClient.GetIdFromUri(uri)
3219
+ else:
3220
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'artistId'), logsi=_logsi)
3221
+
3285
3222
  # execute spotify web api request.
3286
3223
  msg:SpotifyApiMessage = SpotifyApiMessage(apiMethodName, '/artists/{id}'.format(id=artistId))
3287
3224
  msg.RequestHeaders[self.AuthToken.HeaderKey] = self.AuthToken.HeaderValue
@@ -3294,6 +3231,7 @@ class SpotifyClient:
3294
3231
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
3295
3232
  return result
3296
3233
 
3234
+ except SpotifyApiError: raise # pass handled exceptions on thru
3297
3235
  except SpotifyWebApiError: raise # pass handled exceptions on thru
3298
3236
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
3299
3237
  except Exception as ex:
@@ -3309,7 +3247,7 @@ class SpotifyClient:
3309
3247
 
3310
3248
  def GetArtistAlbums(
3311
3249
  self,
3312
- artistId:str,
3250
+ artistId:str=None,
3313
3251
  include_groups:str='album',
3314
3252
  limit:int=20,
3315
3253
  offset:int=0,
@@ -3324,6 +3262,8 @@ class SpotifyClient:
3324
3262
  artistId (str):
3325
3263
  The Spotify ID of the artist.
3326
3264
  Example: `6APm8EjxOHSYM5B4i3vT3q`
3265
+ If null, the currently playing artist uri id value is used; a Spotify Free or Premium account
3266
+ is required to correctly read the currently playing context.
3327
3267
  include_groups (str):
3328
3268
  A comma-separated list of keywords that will be used to filter the response.
3329
3269
  If not supplied, all album types will be returned.
@@ -3413,6 +3353,14 @@ class SpotifyClient:
3413
3353
  # ensure market was either supplied or implied; default if neither.
3414
3354
  market = self._ValidateMarket(market)
3415
3355
 
3356
+ # if artistId not specified, then return currently playing artist id value.
3357
+ if (artistId is None) or (len(artistId.strip()) == 0):
3358
+ uri = self.GetPlayerNowPlayingArtistUri()
3359
+ if uri is not None:
3360
+ artistId = SpotifyClient.GetIdFromUri(uri)
3361
+ else:
3362
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'artistId'), logsi=_logsi)
3363
+
3416
3364
  # build spotify web api request parameters.
3417
3365
  urlParms:dict = \
3418
3366
  {
@@ -3462,14 +3410,16 @@ class SpotifyClient:
3462
3410
  # update result object with final paging details.
3463
3411
  result.Total = pageObj.Total
3464
3412
 
3465
- # sort items on Name property, ascending order.
3466
- if (len(result.Items) > 0) and (sortResult is True):
3467
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
3413
+ # sort result items.
3414
+ if (len(result.Items) > 0):
3415
+ if (sortResult is True):
3416
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
3468
3417
 
3469
3418
  # trace.
3470
3419
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
3471
3420
  return result
3472
3421
 
3422
+ except SpotifyApiError: raise # pass handled exceptions on thru
3473
3423
  except SpotifyWebApiError: raise # pass handled exceptions on thru
3474
3424
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
3475
3425
  except Exception as ex:
@@ -3483,9 +3433,10 @@ class SpotifyClient:
3483
3433
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
3484
3434
 
3485
3435
 
3486
- def GetArtistInfo(self,
3487
- artistId:str,
3488
- ) -> ArtistInfo:
3436
+ def GetArtistInfo(
3437
+ self,
3438
+ artistId:str=None,
3439
+ ) -> ArtistInfo:
3489
3440
  """
3490
3441
  Get artist about information from the Spotify Artist Biography page for the
3491
3442
  specified Spotify artist ID.
@@ -3494,6 +3445,8 @@ class SpotifyClient:
3494
3445
  artistId (str):
3495
3446
  The Spotify ID of the artist.
3496
3447
  Example: `6APm8EjxOHSYM5B4i3vT3q`
3448
+ If null, the currently playing artist uri id value is used; a Spotify Free or Premium account
3449
+ is required to correctly read the currently playing context.
3497
3450
 
3498
3451
  Returns:
3499
3452
  An `ArtistInfo` object that contains the artist info details.
@@ -3525,6 +3478,14 @@ class SpotifyClient:
3525
3478
  apiMethodParms.AppendKeyValue("artistId", artistId)
3526
3479
  _logsi.LogMethodParmList(SILevel.Verbose, "Get Spotify catalog information for a single artist", apiMethodParms)
3527
3480
 
3481
+ # if artistId not specified, then return currently playing artist id value.
3482
+ if (artistId is None) or (len(artistId.strip()) == 0):
3483
+ uri = self.GetPlayerNowPlayingArtistUri()
3484
+ if uri is not None:
3485
+ artistId = SpotifyClient.GetIdFromUri(uri)
3486
+ else:
3487
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'artistId'), logsi=_logsi)
3488
+
3528
3489
  # execute spotify web api request.
3529
3490
  msg:SpotifyApiMessage = SpotifyApiMessage(apiMethodName, '/artists/{id}'.format(id=artistId))
3530
3491
  msg.RequestHeaders[self.AuthToken.HeaderKey] = self.AuthToken.HeaderValue
@@ -3691,6 +3652,7 @@ class SpotifyClient:
3691
3652
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
3692
3653
  return result
3693
3654
 
3655
+ except SpotifyApiError: raise # pass handled exceptions on thru
3694
3656
  except SpotifyWebApiError: raise # pass handled exceptions on thru
3695
3657
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
3696
3658
  except Exception as ex:
@@ -3731,9 +3693,10 @@ class SpotifyClient:
3731
3693
  return result
3732
3694
 
3733
3695
 
3734
- def GetArtistRelatedArtists(self,
3735
- artistId:str,
3736
- ) -> list[Artist]:
3696
+ def GetArtistRelatedArtists(
3697
+ self,
3698
+ artistId:str=None,
3699
+ ) -> list[Artist]:
3737
3700
  """
3738
3701
  Get Spotify catalog information about artists similar to a given artist.
3739
3702
  Similarity is based on analysis of the Spotify community's listening history.
@@ -3742,6 +3705,8 @@ class SpotifyClient:
3742
3705
  artistId (str):
3743
3706
  The Spotify ID of the artist.
3744
3707
  Example: `6APm8EjxOHSYM5B4i3vT3q`
3708
+ If null, the currently playing artist uri id value is used; a Spotify Free or Premium account
3709
+ is required to correctly read the currently playing context.
3745
3710
 
3746
3711
  Returns:
3747
3712
  A list of `Artist` objects that contain the artist details.
@@ -3771,6 +3736,14 @@ class SpotifyClient:
3771
3736
  apiMethodParms.AppendKeyValue("artistId", artistId)
3772
3737
  _logsi.LogMethodParmList(SILevel.Verbose, "Get Spotify catalog information about artists similar to a given artist", apiMethodParms)
3773
3738
 
3739
+ # if artistId not specified, then return currently playing artist id value.
3740
+ if (artistId is None) or (len(artistId.strip()) == 0):
3741
+ uri = self.GetPlayerNowPlayingArtistUri()
3742
+ if uri is not None:
3743
+ artistId = SpotifyClient.GetIdFromUri(uri)
3744
+ else:
3745
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'artistId'), logsi=_logsi)
3746
+
3774
3747
  # execute spotify web api request.
3775
3748
  msg:SpotifyApiMessage = SpotifyApiMessage(apiMethodName, '/artists/{id}/related-artists'.format(id=artistId))
3776
3749
  msg.RequestHeaders[self.AuthToken.HeaderKey] = self.AuthToken.HeaderValue
@@ -3786,6 +3759,7 @@ class SpotifyClient:
3786
3759
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[Artist]'), result)
3787
3760
  return result
3788
3761
 
3762
+ except SpotifyApiError: raise # pass handled exceptions on thru
3789
3763
  except SpotifyWebApiError: raise # pass handled exceptions on thru
3790
3764
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
3791
3765
  except Exception as ex:
@@ -3861,6 +3835,7 @@ class SpotifyClient:
3861
3835
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[Artist]'), result)
3862
3836
  return result
3863
3837
 
3838
+ except SpotifyApiError: raise # pass handled exceptions on thru
3864
3839
  except SpotifyWebApiError: raise # pass handled exceptions on thru
3865
3840
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
3866
3841
  except Exception as ex:
@@ -4011,14 +3986,16 @@ class SpotifyClient:
4011
3986
  result.Total = pageObj.Total
4012
3987
  result.CursorAfter = pageObj.CursorAfter
4013
3988
 
4014
- # sort items on Name property, ascending order.
4015
- if (len(result.Items) > 0) and (sortResult is True):
4016
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
3989
+ # sort result items.
3990
+ if (len(result.Items) > 0):
3991
+ if (sortResult is True):
3992
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
4017
3993
 
4018
3994
  # trace.
4019
3995
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
4020
3996
  return result
4021
3997
 
3998
+ except SpotifyApiError: raise # pass handled exceptions on thru
4022
3999
  except SpotifyWebApiError: raise # pass handled exceptions on thru
4023
4000
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
4024
4001
  except Exception as ex:
@@ -4032,10 +4009,11 @@ class SpotifyClient:
4032
4009
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
4033
4010
 
4034
4011
 
4035
- def GetArtistTopTracks(self,
4036
- artistId:str,
4037
- market:str,
4038
- ) -> list[Track]:
4012
+ def GetArtistTopTracks(
4013
+ self,
4014
+ artistId:str=None,
4015
+ market:str=None,
4016
+ ) -> list[Track]:
4039
4017
  """
4040
4018
  Get Spotify catalog information about an artist's top tracks by country.
4041
4019
 
@@ -4043,6 +4021,8 @@ class SpotifyClient:
4043
4021
  artistId (str):
4044
4022
  The Spotify ID of the artist.
4045
4023
  Example: `6APm8EjxOHSYM5B4i3vT3q`
4024
+ If null, the currently playing artist uri id value is used; a Spotify Free or Premium account
4025
+ is required to correctly read the currently playing context.
4046
4026
  market (str):
4047
4027
  An ISO 3166-1 alpha-2 country code. If a country code is specified, only content that
4048
4028
  is available in that market will be returned. If a valid user access token is specified
@@ -4084,6 +4064,14 @@ class SpotifyClient:
4084
4064
  # ensure market was either supplied or implied; default if neither.
4085
4065
  market = self._ValidateMarket(market)
4086
4066
 
4067
+ # if artistId not specified, then return currently playing artist id value.
4068
+ if (artistId is None) or (len(artistId.strip()) == 0):
4069
+ uri = self.GetPlayerNowPlayingArtistUri()
4070
+ if uri is not None:
4071
+ artistId = SpotifyClient.GetIdFromUri(uri)
4072
+ else:
4073
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'artistId'), logsi=_logsi)
4074
+
4087
4075
  # build spotify web api request parameters.
4088
4076
  urlParms:dict = {}
4089
4077
  if market is not None:
@@ -4105,6 +4093,7 @@ class SpotifyClient:
4105
4093
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[Track]'), result)
4106
4094
  return result
4107
4095
 
4096
+ except SpotifyApiError: raise # pass handled exceptions on thru
4108
4097
  except SpotifyWebApiError: raise # pass handled exceptions on thru
4109
4098
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
4110
4099
  except Exception as ex:
@@ -4118,10 +4107,11 @@ class SpotifyClient:
4118
4107
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
4119
4108
 
4120
4109
 
4121
- def GetAudiobook(self,
4122
- audiobookId:str,
4123
- market:str=None,
4124
- ) -> Audiobook:
4110
+ def GetAudiobook(
4111
+ self,
4112
+ audiobookId:str=None,
4113
+ market:str=None,
4114
+ ) -> Audiobook:
4125
4115
  """
4126
4116
  Get Spotify catalog information for a single audiobook.
4127
4117
 
@@ -4131,6 +4121,8 @@ class SpotifyClient:
4131
4121
  audiobookId (str):
4132
4122
  The Spotify ID for the audiobook.
4133
4123
  Example: `74aydHJKgYz3AIq3jjBSv1`
4124
+ If null, the currently playing audiobook uri id value is used; a Spotify Free or Premium account
4125
+ is required to correctly read the currently playing context.
4134
4126
  market (str):
4135
4127
  An ISO 3166-1 alpha-2 country code. If a country code is specified, only content that
4136
4128
  is available in that market will be returned. If a valid user access token is specified
@@ -4159,6 +4151,10 @@ class SpotifyClient:
4159
4151
  <summary>Sample Code</summary>
4160
4152
  ```python
4161
4153
  .. include:: ../docs/include/samplecode/SpotifyClient/GetAudiobook.py
4154
+ ```
4155
+ <summary>Sample Code - NowPlaying</summary>
4156
+ ```python
4157
+ .. include:: ../docs/include/samplecode/SpotifyClient/GetAudiobook_NowPlaying.py
4162
4158
  ```
4163
4159
  </details>
4164
4160
  """
@@ -4177,6 +4173,14 @@ class SpotifyClient:
4177
4173
  # ensure market was either supplied or implied; default if neither.
4178
4174
  market = self._ValidateMarket(market)
4179
4175
 
4176
+ # if audiobookId not specified, then return currently playing audiobook id value.
4177
+ if (audiobookId is None) or (len(audiobookId.strip()) == 0):
4178
+ uri = self.GetPlayerNowPlayingAudiobookUri()
4179
+ if uri is not None:
4180
+ audiobookId = SpotifyClient.GetIdFromUri(uri)
4181
+ else:
4182
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'audiobookId'), logsi=_logsi)
4183
+
4180
4184
  # build spotify web api request parameters.
4181
4185
  urlParms:dict = {}
4182
4186
  if market is not None:
@@ -4195,6 +4199,7 @@ class SpotifyClient:
4195
4199
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
4196
4200
  return result
4197
4201
 
4202
+ except SpotifyApiError: raise # pass handled exceptions on thru
4198
4203
  except SpotifyWebApiError: raise # pass handled exceptions on thru
4199
4204
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
4200
4205
  except Exception as ex:
@@ -4208,13 +4213,14 @@ class SpotifyClient:
4208
4213
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
4209
4214
 
4210
4215
 
4211
- def GetAudiobookChapters(self,
4212
- audiobookId:str,
4213
- limit:int=20,
4214
- offset:int=0,
4215
- market:str=None,
4216
- limitTotal:int=None
4217
- ) -> ChapterPageSimplified:
4216
+ def GetAudiobookChapters(
4217
+ self,
4218
+ audiobookId:str=None,
4219
+ limit:int=20,
4220
+ offset:int=0,
4221
+ market:str=None,
4222
+ limitTotal:int=None
4223
+ ) -> ChapterPageSimplified:
4218
4224
  """
4219
4225
  Get Spotify catalog information about an audiobook's chapters.
4220
4226
 
@@ -4224,6 +4230,8 @@ class SpotifyClient:
4224
4230
  audiobookId (str):
4225
4231
  The Spotify ID for the audiobook.
4226
4232
  Example: `74aydHJKgYz3AIq3jjBSv1`
4233
+ If null, the currently playing audiobook uri id value is used; a Spotify Free or Premium account
4234
+ is required to correctly read the currently playing context.
4227
4235
  limit (int):
4228
4236
  The maximum number of items to return in a page of items when manual paging is used.
4229
4237
  Default: 20, Range: 1 to 50.
@@ -4302,6 +4310,14 @@ class SpotifyClient:
4302
4310
  # ensure market was either supplied or implied; default if neither.
4303
4311
  market = self._ValidateMarket(market)
4304
4312
 
4313
+ # if audiobookId not specified, then return currently playing audiobook id value.
4314
+ if (audiobookId is None) or (len(audiobookId.strip()) == 0):
4315
+ uri = self.GetPlayerNowPlayingAudiobookUri()
4316
+ if uri is not None:
4317
+ audiobookId = SpotifyClient.GetIdFromUri(uri)
4318
+ else:
4319
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'audiobookId'), logsi=_logsi)
4320
+
4305
4321
  # build spotify web api request parameters.
4306
4322
  urlParms:dict = \
4307
4323
  {
@@ -4356,6 +4372,7 @@ class SpotifyClient:
4356
4372
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
4357
4373
  return result
4358
4374
 
4375
+ except SpotifyApiError: raise # pass handled exceptions on thru
4359
4376
  except SpotifyWebApiError: raise # pass handled exceptions on thru
4360
4377
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
4361
4378
  except Exception as ex:
@@ -4499,14 +4516,16 @@ class SpotifyClient:
4499
4516
  # update result object with final paging details.
4500
4517
  result.Total = pageObj.Total
4501
4518
 
4502
- # sort items on Name property, ascending order.
4503
- if (len(result.Items) > 0) and (sortResult is True):
4504
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
4519
+ # sort result items.
4520
+ if (len(result.Items) > 0):
4521
+ if (sortResult is True):
4522
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
4505
4523
 
4506
4524
  # trace.
4507
4525
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
4508
4526
  return result
4509
4527
 
4528
+ except SpotifyApiError: raise # pass handled exceptions on thru
4510
4529
  except SpotifyWebApiError: raise # pass handled exceptions on thru
4511
4530
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
4512
4531
  except Exception as ex:
@@ -4602,6 +4621,7 @@ class SpotifyClient:
4602
4621
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[AudiobookSimplified]'), result)
4603
4622
  return result
4604
4623
 
4624
+ except SpotifyApiError: raise # pass handled exceptions on thru
4605
4625
  except SpotifyWebApiError: raise # pass handled exceptions on thru
4606
4626
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
4607
4627
  except Exception as ex:
@@ -4720,6 +4740,7 @@ class SpotifyClient:
4720
4740
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE_CACHED % (apiMethodName, type(result).__name__, cacheDesc), result, excludeNonPublic=True)
4721
4741
  return result
4722
4742
 
4743
+ except SpotifyApiError: raise # pass handled exceptions on thru
4723
4744
  except SpotifyWebApiError: raise # pass handled exceptions on thru
4724
4745
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
4725
4746
  except Exception as ex:
@@ -4886,14 +4907,16 @@ class SpotifyClient:
4886
4907
  # update result object with final paging details.
4887
4908
  result.Total = pageObj.Total
4888
4909
 
4889
- # sort items on Name property, ascending order.
4890
- if (len(result.Items) > 0) and (sortResult is True):
4891
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
4910
+ # sort result items.
4911
+ if (len(result.Items) > 0):
4912
+ if (sortResult is True):
4913
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
4892
4914
 
4893
4915
  # trace.
4894
4916
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
4895
4917
  return result
4896
4918
 
4919
+ except SpotifyApiError: raise # pass handled exceptions on thru
4897
4920
  except SpotifyWebApiError: raise # pass handled exceptions on thru
4898
4921
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
4899
4922
  except Exception as ex:
@@ -4993,6 +5016,7 @@ class SpotifyClient:
4993
5016
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE_CACHED % (apiMethodName, type(result).__name__, cacheDesc), result)
4994
5017
  return result
4995
5018
 
5019
+ except SpotifyApiError: raise # pass handled exceptions on thru
4996
5020
  except SpotifyWebApiError: raise # pass handled exceptions on thru
4997
5021
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
4998
5022
  except Exception as ex:
@@ -5166,14 +5190,16 @@ class SpotifyClient:
5166
5190
  # update result object with final paging details.
5167
5191
  result.Total = pageObj.Total
5168
5192
 
5169
- # sort items on Name property, ascending order.
5170
- if (len(result.Items) > 0) and (sortResult is True):
5171
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
5193
+ # sort result items.
5194
+ if (len(result.Items) > 0):
5195
+ if (sortResult is True):
5196
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
5172
5197
 
5173
5198
  # trace.
5174
5199
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
5175
5200
  return result, resultMessage
5176
5201
 
5202
+ except SpotifyApiError: raise # pass handled exceptions on thru
5177
5203
  except SpotifyWebApiError: raise # pass handled exceptions on thru
5178
5204
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
5179
5205
  except Exception as ex:
@@ -5264,6 +5290,7 @@ class SpotifyClient:
5264
5290
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
5265
5291
  return result
5266
5292
 
5293
+ except SpotifyApiError: raise # pass handled exceptions on thru
5267
5294
  except SpotifyWebApiError: raise # pass handled exceptions on thru
5268
5295
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
5269
5296
  except Exception as ex:
@@ -5359,6 +5386,7 @@ class SpotifyClient:
5359
5386
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[Chapter]'), result)
5360
5387
  return result
5361
5388
 
5389
+ except SpotifyApiError: raise # pass handled exceptions on thru
5362
5390
  except SpotifyWebApiError: raise # pass handled exceptions on thru
5363
5391
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
5364
5392
  except Exception as ex:
@@ -5372,10 +5400,11 @@ class SpotifyClient:
5372
5400
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
5373
5401
 
5374
5402
 
5375
- def GetEpisode(self,
5376
- episodeId:str,
5377
- market:str=None,
5378
- ) -> Episode:
5403
+ def GetEpisode(
5404
+ self,
5405
+ episodeId:str=None,
5406
+ market:str=None,
5407
+ ) -> Episode:
5379
5408
  """
5380
5409
  Get Spotify catalog information for a single episode identified by its unique Spotify ID.
5381
5410
 
@@ -5385,6 +5414,8 @@ class SpotifyClient:
5385
5414
  episodeId (str):
5386
5415
  The Spotify ID for the episode.
5387
5416
  Example: `512ojhOuo1ktJprKbVcKyQ`
5417
+ If null, the currently playing episode uri id value is used; a Spotify Free or Premium account
5418
+ is required to correctly read the currently playing context.
5388
5419
  market (str):
5389
5420
  An ISO 3166-1 alpha-2 country code. If a country code is specified, only content that
5390
5421
  is available in that market will be returned. If a valid user access token is specified
@@ -5431,6 +5462,14 @@ class SpotifyClient:
5431
5462
  # ensure market was either supplied or implied; default if neither.
5432
5463
  market = self._ValidateMarket(market)
5433
5464
 
5465
+ # if ids not specified, then return currently playing id value.
5466
+ if (episodeId is None) or (len(episodeId.strip()) == 0):
5467
+ uri = self.GetPlayerNowPlayingUri('episode')
5468
+ if uri is not None:
5469
+ episodeId = SpotifyClient.GetIdFromUri(uri)
5470
+ else:
5471
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'episodeId'), logsi=_logsi)
5472
+
5434
5473
  # build spotify web api request parameters.
5435
5474
  urlParms:dict = {}
5436
5475
  if market is not None:
@@ -5449,6 +5488,7 @@ class SpotifyClient:
5449
5488
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
5450
5489
  return result
5451
5490
 
5491
+ except SpotifyApiError: raise # pass handled exceptions on thru
5452
5492
  except SpotifyWebApiError: raise # pass handled exceptions on thru
5453
5493
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
5454
5494
  except Exception as ex:
@@ -5592,14 +5632,18 @@ class SpotifyClient:
5592
5632
  # update result object with final paging details.
5593
5633
  result.Total = pageObj.Total
5594
5634
 
5595
- # sort items on Name property, ascending order.
5596
- if (len(result.Items) > 0) and (sortResult is True):
5597
- result.Items.sort(key=lambda x: (x.Episode.Name or "").lower(), reverse=False)
5635
+ # sort result items.
5636
+ if (len(result.Items) > 0):
5637
+ if (sortResult is True):
5638
+ result.Items.sort(key=lambda x: (x.Episode.Name or "").lower(), reverse=False)
5639
+ else:
5640
+ result.Items.sort(key=lambda x: (x.AddedAt or "").lower(), reverse=True)
5598
5641
 
5599
5642
  # trace.
5600
5643
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
5601
5644
  return result
5602
5645
 
5646
+ except SpotifyApiError: raise # pass handled exceptions on thru
5603
5647
  except SpotifyWebApiError: raise # pass handled exceptions on thru
5604
5648
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
5605
5649
  except Exception as ex:
@@ -5695,6 +5739,7 @@ class SpotifyClient:
5695
5739
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[Episode]'), result)
5696
5740
  return result
5697
5741
 
5742
+ except SpotifyApiError: raise # pass handled exceptions on thru
5698
5743
  except SpotifyWebApiError: raise # pass handled exceptions on thru
5699
5744
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
5700
5745
  except Exception as ex:
@@ -5877,14 +5922,16 @@ class SpotifyClient:
5877
5922
  # update result object with final paging details.
5878
5923
  result.Total = pageObj.Total
5879
5924
 
5880
- # sort items on Name property, ascending order.
5881
- if (len(result.Items) > 0) and (sortResult is True):
5882
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
5925
+ # sort result items.
5926
+ if (len(result.Items) > 0):
5927
+ if (sortResult is True):
5928
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
5883
5929
 
5884
5930
  # trace.
5885
5931
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
5886
5932
  return result, resultMessage
5887
5933
 
5934
+ except SpotifyApiError: raise # pass handled exceptions on thru
5888
5935
  except SpotifyWebApiError: raise # pass handled exceptions on thru
5889
5936
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
5890
5937
  except Exception as ex:
@@ -5965,6 +6012,7 @@ class SpotifyClient:
5965
6012
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE_CACHED % (apiMethodName, type(result).__name__, cacheDesc), result)
5966
6013
  return result
5967
6014
 
6015
+ except SpotifyApiError: raise # pass handled exceptions on thru
5968
6016
  except SpotifyWebApiError: raise # pass handled exceptions on thru
5969
6017
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
5970
6018
  except Exception as ex:
@@ -6083,6 +6131,7 @@ class SpotifyClient:
6083
6131
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE_CACHED % (apiMethodName, type(result).__name__, cacheDesc), result)
6084
6132
  return result
6085
6133
 
6134
+ except SpotifyApiError: raise # pass handled exceptions on thru
6086
6135
  except SpotifyWebApiError: raise # pass handled exceptions on thru
6087
6136
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6088
6137
  except Exception as ex:
@@ -6133,6 +6182,7 @@ class SpotifyClient:
6133
6182
  # subsequent calls to the Spotify Web API player endpoints.
6134
6183
  return None
6135
6184
 
6185
+ except SpotifyApiError: raise # pass handled exceptions on thru
6136
6186
  except SpotifyWebApiError: raise # pass handled exceptions on thru
6137
6187
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6138
6188
  except Exception as ex:
@@ -6222,6 +6272,7 @@ class SpotifyClient:
6222
6272
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'Device'), result, excludeNonPublic=True)
6223
6273
  return result
6224
6274
 
6275
+ except SpotifyApiError: raise # pass handled exceptions on thru
6225
6276
  except SpotifyWebApiError: raise # pass handled exceptions on thru
6226
6277
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6227
6278
  except Exception as ex:
@@ -6513,6 +6564,7 @@ class SpotifyClient:
6513
6564
  _logsi.LogVerbose("Device name '%s' could not be found in the Spotify Connect Device list; subsequent actions will probably fail using this device name" % value)
6514
6565
  return value
6515
6566
 
6567
+ except SpotifyApiError: raise # pass handled exceptions on thru
6516
6568
  except SpotifyWebApiError: raise # pass handled exceptions on thru
6517
6569
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6518
6570
  except Exception as ex:
@@ -6616,6 +6668,7 @@ class SpotifyClient:
6616
6668
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE_CACHED % (apiMethodName, 'list[Device]', cacheDesc), result)
6617
6669
  return result
6618
6670
 
6671
+ except SpotifyApiError: raise # pass handled exceptions on thru
6619
6672
  except SpotifyWebApiError: raise # pass handled exceptions on thru
6620
6673
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6621
6674
  except Exception as ex:
@@ -6682,11 +6735,16 @@ class SpotifyClient:
6682
6735
  # trace.
6683
6736
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
6684
6737
  apiMethodParms.AppendKeyValue("market", market)
6738
+ apiMethodParms.AppendKeyValue("additionalTypes", additionalTypes)
6685
6739
  _logsi.LogMethodParmList(SILevel.Verbose, "Get the object currently being played on the user's Spotify account", apiMethodParms)
6686
6740
 
6687
6741
  # ensure market was either supplied or implied; default if neither.
6688
6742
  market = self._ValidateMarket(market)
6689
6743
 
6744
+ # a spotify free or premium level membership is required to get the nowplaying info.
6745
+ if (not self.UserProfile.IsProductPremium) and (not self.UserProfile.IsProductFree):
6746
+ raise SpotifyApiError(SAAppMessages.MSG_SPOTIFY_ACCOUNT_REQUIRED_FOR_NOWPLAYING, logsi=_logsi)
6747
+
6690
6748
  # build spotify web api request parameters.
6691
6749
  urlParms:dict = {}
6692
6750
  if market is not None:
@@ -6707,6 +6765,7 @@ class SpotifyClient:
6707
6765
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
6708
6766
  return result
6709
6767
 
6768
+ except SpotifyApiError: raise # pass handled exceptions on thru
6710
6769
  except SpotifyWebApiError: raise # pass handled exceptions on thru
6711
6770
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6712
6771
  except Exception as ex:
@@ -6720,6 +6779,188 @@ class SpotifyClient:
6720
6779
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
6721
6780
 
6722
6781
 
6782
+ def GetPlayerNowPlayingAlbumUri(self) -> str:
6783
+ """
6784
+ Returns the album uri value of the currently playing media if something is
6785
+ playing; otherwise, null is returned.
6786
+
6787
+ Raises:
6788
+ SpotifyApiError:
6789
+ If current user does not have a Spotify free or premium level account.
6790
+ If nowplaying context does not contain an album reference.
6791
+ """
6792
+ result:str = None
6793
+
6794
+ # get nowplaying status.
6795
+ nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying(additionalTypes='track')
6796
+
6797
+ # is a track playing? if so, return the album uri value.
6798
+ if nowPlaying is not None:
6799
+ if nowPlaying.CurrentlyPlayingType in ['track']:
6800
+ trackItem:Track = nowPlaying.Item
6801
+ if (trackItem is not None) and (trackItem.Album is not None):
6802
+ result = trackItem.Album.Uri
6803
+ else:
6804
+ raise SpotifyApiError("Currently playing item does not contain an Album reference", logsi=_logsi)
6805
+
6806
+ return result
6807
+
6808
+
6809
+ def GetPlayerNowPlayingArtistUri(self) -> str:
6810
+ """
6811
+ Returns the artist uri value of the currently playing media if something is
6812
+ playing; otherwise, null is returned.
6813
+
6814
+ Raises:
6815
+ SpotifyApiError:
6816
+ If current user does not have a Spotify free or premium level account.
6817
+ If nowplaying context does not contain an artist reference.
6818
+ """
6819
+ result:str = None
6820
+
6821
+ # get nowplaying status.
6822
+ nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying()
6823
+
6824
+ # is a track playing? if so, return the artist uri value.
6825
+ if nowPlaying is not None:
6826
+ if nowPlaying.CurrentlyPlayingType in ['track']:
6827
+ trackItem:Track = nowPlaying.Item
6828
+ if (trackItem is not None) and (len(trackItem.Artists) > 0):
6829
+ result = trackItem.Artists[0].Uri
6830
+ else:
6831
+ raise SpotifyApiError("Currently playing item does not contain an Artist reference", logsi=_logsi)
6832
+
6833
+ return result
6834
+
6835
+
6836
+ def GetPlayerNowPlayingAudiobookUri(self) -> str:
6837
+ """
6838
+ Returns the audiobook uri value of the currently playing media if something is
6839
+ playing; otherwise, null is returned.
6840
+
6841
+ Raises:
6842
+ SpotifyApiError:
6843
+ If current user does not have a Spotify free or premium level account.
6844
+ If nowplaying context is not a audiobook chapter.
6845
+ """
6846
+ result:str = None
6847
+
6848
+ # get nowplaying status.
6849
+ nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying(additionalTypes='episode')
6850
+
6851
+ # is an chapter playing? if so, return the parent show uri value.
6852
+ if nowPlaying is not None:
6853
+ if nowPlaying.CurrentlyPlayingType in ['episode']:
6854
+ playingItem:Chapter = nowPlaying.Item
6855
+ if (playingItem is not None):
6856
+ chapter:Chapter = self.GetChapter(playingItem.Id)
6857
+ result = chapter.Audiobook.Uri
6858
+ else:
6859
+ raise SpotifyApiError("Currently playing item is not a Audiobook Chapter", logsi=_logsi)
6860
+
6861
+ return result
6862
+
6863
+
6864
+ def GetPlayerNowPlayingPlaylistUri(self) -> str:
6865
+ """
6866
+ Returns the playlist uri value of the currently playing media if something is
6867
+ playing; otherwise, null is returned.
6868
+
6869
+ Raises:
6870
+ SpotifyApiError:
6871
+ If current user does not have a Spotify free or premium level account.
6872
+ If nowplaying context is not a playlist.
6873
+ """
6874
+ result:str = None
6875
+
6876
+ # get nowplaying status.
6877
+ nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying()
6878
+
6879
+ # is a playlist playing? if so, return the uri value.
6880
+ if nowPlaying is not None:
6881
+ context:Context = nowPlaying.Context
6882
+ if (context is not None) and (context.Type == 'playlist'):
6883
+ result = context.Uri
6884
+ else:
6885
+ raise SpotifyApiError("Currently playing context is not a Playlist", logsi=_logsi)
6886
+
6887
+ return result
6888
+
6889
+
6890
+ def GetPlayerNowPlayingShowUri(self) -> str:
6891
+ """
6892
+ Returns the show uri value of the currently playing media if something is
6893
+ playing; otherwise, null is returned.
6894
+
6895
+ Raises:
6896
+ SpotifyApiError:
6897
+ If current user does not have a Spotify free or premium level account.
6898
+ If nowplaying context is not a show episode.
6899
+ """
6900
+ result:str = None
6901
+
6902
+ # get nowplaying status.
6903
+ nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying(additionalTypes='episode')
6904
+
6905
+ # is an episode playing? if so, return the parent show uri value.
6906
+ if nowPlaying is not None:
6907
+ if nowPlaying.CurrentlyPlayingType in ['episode']:
6908
+ playingItem:Episode = nowPlaying.Item
6909
+ if (playingItem is not None):
6910
+ episode:Episode = self.GetEpisode(playingItem.Id)
6911
+ result = episode.Show.Uri
6912
+ else:
6913
+ raise SpotifyApiError("Currently playing item is not a Show Episode", logsi=_logsi)
6914
+
6915
+ return result
6916
+
6917
+
6918
+ def GetPlayerNowPlayingUri(
6919
+ self,
6920
+ additionalTypes:str=None,
6921
+ ) -> str:
6922
+ """
6923
+ Returns the uri value of the currently playing media type if something is
6924
+ playing; otherwise, null is returned.
6925
+
6926
+ Args:
6927
+ additionalTypes (str):
6928
+ An item type that your client supports besides the default track type.
6929
+ Valid types are: `track` and `episode`.
6930
+ Specify `episode` to get podcast track information.
6931
+
6932
+ Raises:
6933
+ SpotifyApiError:
6934
+ If current user does not have a Spotify free or premium level account.
6935
+ If nowplaying item is not of the specified `additionalType`.
6936
+ """
6937
+ result:str = None
6938
+
6939
+ # get nowplaying status.
6940
+ nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying(additionalTypes=additionalTypes)
6941
+
6942
+ # is anything playing? if so, return the uri value.
6943
+ if nowPlaying is not None:
6944
+ if nowPlaying.Item is not None:
6945
+ if additionalTypes is None:
6946
+ # if not validating uri type then just return the uri.
6947
+ result = nowPlaying.Item.Uri
6948
+ elif nowPlaying.CurrentlyPlayingType == additionalTypes:
6949
+ # if validating uri type then return uri if nowplaying types matches desired type.
6950
+ result = nowPlaying.Item.Uri
6951
+ else:
6952
+ # otherwise nowplaying type is not the desired type!
6953
+ raise SpotifyApiError("Currently playing item is not a %s" % additionalTypes, logsi=_logsi)
6954
+ else:
6955
+ # otherwise nowplaying item does not contain the desired type!
6956
+ if additionalTypes is None:
6957
+ raise SpotifyApiError("Currently playing item context is not set", logsi=_logsi)
6958
+ else:
6959
+ raise SpotifyApiError("Currently playing item context is not a %s item" % additionalTypes, logsi=_logsi)
6960
+
6961
+ return result
6962
+
6963
+
6723
6964
  def GetPlayerPlaybackState(self,
6724
6965
  market:str=None,
6725
6966
  additionalTypes:str=None
@@ -6811,6 +7052,7 @@ class SpotifyClient:
6811
7052
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
6812
7053
  return result
6813
7054
 
7055
+ except SpotifyApiError: raise # pass handled exceptions on thru
6814
7056
  except SpotifyWebApiError: raise # pass handled exceptions on thru
6815
7057
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6816
7058
  except Exception as ex:
@@ -6868,6 +7110,7 @@ class SpotifyClient:
6868
7110
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
6869
7111
  return result
6870
7112
 
7113
+ except SpotifyApiError: raise # pass handled exceptions on thru
6871
7114
  except SpotifyWebApiError: raise # pass handled exceptions on thru
6872
7115
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6873
7116
  except Exception as ex:
@@ -7052,6 +7295,7 @@ class SpotifyClient:
7052
7295
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
7053
7296
  return result
7054
7297
 
7298
+ except SpotifyApiError: raise # pass handled exceptions on thru
7055
7299
  except SpotifyWebApiError: raise # pass handled exceptions on thru
7056
7300
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
7057
7301
  except Exception as ex:
@@ -7065,12 +7309,13 @@ class SpotifyClient:
7065
7309
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
7066
7310
 
7067
7311
 
7068
- def GetPlaylist(self,
7069
- playlistId:str,
7070
- market:str=None,
7071
- fields:str=None,
7072
- additionalTypes:str=None
7073
- ) -> Playlist:
7312
+ def GetPlaylist(
7313
+ self,
7314
+ playlistId:str=None,
7315
+ market:str=None,
7316
+ fields:str=None,
7317
+ additionalTypes:str=None
7318
+ ) -> Playlist:
7074
7319
  """
7075
7320
  Get a playlist owned by a Spotify user.
7076
7321
 
@@ -7078,6 +7323,7 @@ class SpotifyClient:
7078
7323
  playlistId (str):
7079
7324
  The Spotify ID of the playlist.
7080
7325
  Example: `5v5ETK9WFXAnGQ3MRubKuE`
7326
+ If null, the currently playing playlist uri id value is used.
7081
7327
  market (str):
7082
7328
  An ISO 3166-1 alpha-2 country code. If a country code is specified, only content that
7083
7329
  is available in that market will be returned. If a valid user access token is specified
@@ -7121,6 +7367,10 @@ class SpotifyClient:
7121
7367
  <summary>Sample Code</summary>
7122
7368
  ```python
7123
7369
  .. include:: ../docs/include/samplecode/SpotifyClient/GetPlaylist.py
7370
+ ```
7371
+ <summary>Sample Code - NowPlaying</summary>
7372
+ ```python
7373
+ .. include:: ../docs/include/samplecode/SpotifyClient/GetPlaylist_NowPlaying.py
7124
7374
  ```
7125
7375
  </details>
7126
7376
  """
@@ -7141,6 +7391,14 @@ class SpotifyClient:
7141
7391
  # ensure market was either supplied or implied; default if neither.
7142
7392
  market = self._ValidateMarket(market)
7143
7393
 
7394
+ # if playlistId not specified, then return currently playing playlist id value.
7395
+ if (playlistId is None) or (len(playlistId.strip()) == 0):
7396
+ uri = self.GetPlayerNowPlayingPlaylistUri()
7397
+ if uri is not None:
7398
+ playlistId = SpotifyClient.GetIdFromUri(uri)
7399
+ else:
7400
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'playlistId'), logsi=_logsi)
7401
+
7144
7402
  # was the Spotify DJ playlist specified?
7145
7403
  # the DJ is not fully integrated with the playlist API, so the GET request will fail.
7146
7404
  # we will manually build a basic playlist object to return for the playlist.
@@ -7184,6 +7442,7 @@ class SpotifyClient:
7184
7442
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
7185
7443
  return result
7186
7444
 
7445
+ except SpotifyApiError: raise # pass handled exceptions on thru
7187
7446
  except SpotifyWebApiError: raise # pass handled exceptions on thru
7188
7447
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
7189
7448
  except Exception as ex:
@@ -7252,6 +7511,7 @@ class SpotifyClient:
7252
7511
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
7253
7512
  return result
7254
7513
 
7514
+ except SpotifyApiError: raise # pass handled exceptions on thru
7255
7515
  except SpotifyWebApiError: raise # pass handled exceptions on thru
7256
7516
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
7257
7517
  except Exception as ex:
@@ -7265,15 +7525,16 @@ class SpotifyClient:
7265
7525
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
7266
7526
 
7267
7527
 
7268
- def GetPlaylistItems(self,
7269
- playlistId:str,
7270
- limit:int=50,
7271
- offset:int=0,
7272
- market:str=None,
7273
- fields:str=None,
7274
- additionalTypes:str=None,
7275
- limitTotal:int=None
7276
- ) -> PlaylistPage:
7528
+ def GetPlaylistItems(
7529
+ self,
7530
+ playlistId:str=None,
7531
+ limit:int=50,
7532
+ offset:int=0,
7533
+ market:str=None,
7534
+ fields:str=None,
7535
+ additionalTypes:str=None,
7536
+ limitTotal:int=None
7537
+ ) -> PlaylistPage:
7277
7538
  """
7278
7539
  Get full details of the items of a playlist owned by a Spotify user.
7279
7540
 
@@ -7283,6 +7544,7 @@ class SpotifyClient:
7283
7544
  playlistId (str):
7284
7545
  The Spotify ID of the playlist.
7285
7546
  Example: `5v5ETK9WFXAnGQ3MRubKuE`
7547
+ If null, the currently playing playlist uri id value is used.
7286
7548
  limit (int):
7287
7549
  The maximum number of items to return in a page of items when manual paging is used.
7288
7550
  Default: 50, Range: 1 to 50.
@@ -7384,6 +7646,14 @@ class SpotifyClient:
7384
7646
  # ensure market was either supplied or implied; default if neither.
7385
7647
  market = self._ValidateMarket(market)
7386
7648
 
7649
+ # if playlistId not specified, then return currently playing playlist id value.
7650
+ if (playlistId is None) or (len(playlistId.strip()) == 0):
7651
+ uri = self.GetPlayerNowPlayingPlaylistUri()
7652
+ if uri is not None:
7653
+ playlistId = SpotifyClient.GetIdFromUri(uri)
7654
+ else:
7655
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'playlistId'), logsi=_logsi)
7656
+
7387
7657
  # build spotify web api request parameters.
7388
7658
  urlParms:dict = \
7389
7659
  {
@@ -7442,6 +7712,7 @@ class SpotifyClient:
7442
7712
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
7443
7713
  return result
7444
7714
 
7715
+ except SpotifyApiError: raise # pass handled exceptions on thru
7445
7716
  except SpotifyWebApiError: raise # pass handled exceptions on thru
7446
7717
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
7447
7718
  except Exception as ex:
@@ -7585,14 +7856,16 @@ class SpotifyClient:
7585
7856
  # update result object with final paging details.
7586
7857
  result.Total = pageObj.Total
7587
7858
 
7588
- # sort items on Name property, ascending order.
7589
- if (len(result.Items) > 0) and (sortResult is True):
7590
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
7859
+ # sort result items.
7860
+ if (len(result.Items) > 0):
7861
+ if (sortResult is True):
7862
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
7591
7863
 
7592
7864
  # trace.
7593
7865
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
7594
7866
  return result
7595
7867
 
7868
+ except SpotifyApiError: raise # pass handled exceptions on thru
7596
7869
  except SpotifyWebApiError: raise # pass handled exceptions on thru
7597
7870
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
7598
7871
  except Exception as ex:
@@ -7742,14 +8015,16 @@ class SpotifyClient:
7742
8015
  # update result object with final paging details.
7743
8016
  result.Total = pageObj.Total
7744
8017
 
7745
- # sort items on Name property, ascending order.
7746
- if (len(result.Items) > 0) and (sortResult is True):
7747
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
8018
+ # sort result items.
8019
+ if (len(result.Items) > 0):
8020
+ if (sortResult is True):
8021
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
7748
8022
 
7749
8023
  # trace.
7750
8024
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
7751
8025
  return result
7752
8026
 
8027
+ except SpotifyApiError: raise # pass handled exceptions on thru
7753
8028
  except SpotifyWebApiError: raise # pass handled exceptions on thru
7754
8029
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
7755
8030
  except Exception as ex:
@@ -7763,10 +8038,11 @@ class SpotifyClient:
7763
8038
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
7764
8039
 
7765
8040
 
7766
- def GetShow(self,
7767
- showId:str,
7768
- market:str=None,
7769
- ) -> Show:
8041
+ def GetShow(
8042
+ self,
8043
+ showId:str=None,
8044
+ market:str=None,
8045
+ ) -> Show:
7770
8046
  """
7771
8047
  Get Spotify catalog information for a single show identified by its unique Spotify ID.
7772
8048
 
@@ -7774,6 +8050,8 @@ class SpotifyClient:
7774
8050
  showId (str):
7775
8051
  The Spotify ID for the show.
7776
8052
  Example: `5CfCWKI5pZ28U0uOzXkDHe`
8053
+ If null, the currently playing show uri id value is used; a Spotify Free or Premium account
8054
+ is required to correctly read the currently playing context.
7777
8055
  market (str):
7778
8056
  An ISO 3166-1 alpha-2 country code. If a country code is specified, only content that
7779
8057
  is available in that market will be returned. If a valid user access token is specified
@@ -7802,6 +8080,10 @@ class SpotifyClient:
7802
8080
  <summary>Sample Code</summary>
7803
8081
  ```python
7804
8082
  .. include:: ../docs/include/samplecode/SpotifyClient/GetShow.py
8083
+ ```
8084
+ <summary>Sample Code - NowPlaying</summary>
8085
+ ```python
8086
+ .. include:: ../docs/include/samplecode/SpotifyClient/GetShow_NowPlaying.py
7805
8087
  ```
7806
8088
  </details>
7807
8089
  """
@@ -7820,6 +8102,14 @@ class SpotifyClient:
7820
8102
  # ensure market was either supplied or implied; default if neither.
7821
8103
  market = self._ValidateMarket(market)
7822
8104
 
8105
+ # if showId not specified, then return currently playing show id value.
8106
+ if (showId is None) or (len(showId.strip()) == 0):
8107
+ uri = self.GetPlayerNowPlayingShowUri()
8108
+ if uri is not None:
8109
+ showId = SpotifyClient.GetIdFromUri(uri)
8110
+ else:
8111
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'showId'), logsi=_logsi)
8112
+
7823
8113
  # build spotify web api request parameters.
7824
8114
  urlParms:dict = {}
7825
8115
  if market is not None:
@@ -7838,6 +8128,7 @@ class SpotifyClient:
7838
8128
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
7839
8129
  return result
7840
8130
 
8131
+ except SpotifyApiError: raise # pass handled exceptions on thru
7841
8132
  except SpotifyWebApiError: raise # pass handled exceptions on thru
7842
8133
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
7843
8134
  except Exception as ex:
@@ -7851,13 +8142,14 @@ class SpotifyClient:
7851
8142
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
7852
8143
 
7853
8144
 
7854
- def GetShowEpisodes(self,
7855
- showId:str,
7856
- limit:int=20,
7857
- offset:int=0,
7858
- market:str=None,
7859
- limitTotal:int=None
7860
- ) -> EpisodePageSimplified:
8145
+ def GetShowEpisodes(
8146
+ self,
8147
+ showId:str=None,
8148
+ limit:int=20,
8149
+ offset:int=0,
8150
+ market:str=None,
8151
+ limitTotal:int=None
8152
+ ) -> EpisodePageSimplified:
7861
8153
  """
7862
8154
  Get Spotify catalog information about a show's episodes.
7863
8155
 
@@ -7867,6 +8159,8 @@ class SpotifyClient:
7867
8159
  showId (str):
7868
8160
  The Spotify ID for the show.
7869
8161
  Example: `6kAsbP8pxwaU2kPibKTuHE`
8162
+ If null, the currently playing show uri id value is used; a Spotify Free or Premium account
8163
+ is required to correctly read the currently playing context.
7870
8164
  limit (int):
7871
8165
  The maximum number of items to return in a page of items when manual paging is used.
7872
8166
  Default: 20, Range: 1 to 50.
@@ -7945,6 +8239,14 @@ class SpotifyClient:
7945
8239
  # ensure market was either supplied or implied; default if neither.
7946
8240
  market = self._ValidateMarket(market)
7947
8241
 
8242
+ # if showId not specified, then return currently playing show id value.
8243
+ if (showId is None) or (len(showId.strip()) == 0):
8244
+ uri = self.GetPlayerNowPlayingShowUri()
8245
+ if uri is not None:
8246
+ showId = SpotifyClient.GetIdFromUri(uri)
8247
+ else:
8248
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'showId'), logsi=_logsi)
8249
+
7948
8250
  # build spotify web api request parameters.
7949
8251
  urlParms:dict = \
7950
8252
  {
@@ -7999,6 +8301,7 @@ class SpotifyClient:
7999
8301
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
8000
8302
  return result
8001
8303
 
8304
+ except SpotifyApiError: raise # pass handled exceptions on thru
8002
8305
  except SpotifyWebApiError: raise # pass handled exceptions on thru
8003
8306
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
8004
8307
  except Exception as ex:
@@ -8128,7 +8431,7 @@ class SpotifyClient:
8128
8431
  else:
8129
8432
 
8130
8433
  # append page of items to final results.
8131
- item:AlbumSaved
8434
+ item:ShowSaved
8132
8435
  for item in pageObj.Items:
8133
8436
  result.Items.append(item)
8134
8437
  result.Limit = result.ItemsCount
@@ -8142,14 +8445,18 @@ class SpotifyClient:
8142
8445
  # update result object with final paging details.
8143
8446
  result.Total = pageObj.Total
8144
8447
 
8145
- # sort items on Name property, ascending order.
8146
- if (len(result.Items) > 0) and (sortResult is True):
8147
- result.Items.sort(key=lambda x: (x.Show.Name or "").lower(), reverse=False)
8448
+ # sort result items.
8449
+ if (len(result.Items) > 0):
8450
+ if (sortResult is True):
8451
+ result.Items.sort(key=lambda x: (x.Show.Name or "").lower(), reverse=False)
8452
+ else:
8453
+ result.Items.sort(key=lambda x: (x.AddedAt or "").lower(), reverse=True)
8148
8454
 
8149
8455
  # trace.
8150
8456
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
8151
8457
  return result
8152
8458
 
8459
+ except SpotifyApiError: raise # pass handled exceptions on thru
8153
8460
  except SpotifyWebApiError: raise # pass handled exceptions on thru
8154
8461
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
8155
8462
  except Exception as ex:
@@ -8245,6 +8552,7 @@ class SpotifyClient:
8245
8552
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[ShowSimplified]'), result)
8246
8553
  return result
8247
8554
 
8555
+ except SpotifyApiError: raise # pass handled exceptions on thru
8248
8556
  except SpotifyWebApiError: raise # pass handled exceptions on thru
8249
8557
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
8250
8558
  except Exception as ex:
@@ -8776,9 +9084,10 @@ class SpotifyClient:
8776
9084
  # update cache.
8777
9085
  self._ConfigurationCache[apiMethodName] = result
8778
9086
 
8779
- # sort items on Name property, ascending order.
8780
- if (len(result.Items) > 0) and (sortResult is True):
8781
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
9087
+ # sort result items.
9088
+ if (len(result.Items) > 0):
9089
+ if (sortResult is True):
9090
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
8782
9091
 
8783
9092
  # update last refresh date.
8784
9093
  result.DateLastRefreshed = datetime.utcnow().timestamp()
@@ -8800,9 +9109,10 @@ class SpotifyClient:
8800
9109
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
8801
9110
 
8802
9111
 
8803
- def GetTrack(self,
8804
- trackId:str,
8805
- ) -> Track:
9112
+ def GetTrack(
9113
+ self,
9114
+ trackId:str=None,
9115
+ ) -> Track:
8806
9116
  """
8807
9117
  Get Spotify catalog information for a single track identified by its unique Spotify ID.
8808
9118
 
@@ -8810,6 +9120,8 @@ class SpotifyClient:
8810
9120
  trackId (str):
8811
9121
  The Spotify ID of the track.
8812
9122
  Example: `1kWUud3vY5ij5r62zxpTRy`
9123
+ If null, the currently playing track uri id value is used; a Spotify Free or Premium account
9124
+ is required to correctly read the currently playing context.
8813
9125
 
8814
9126
  Returns:
8815
9127
  A `Track` object that contains the track details.
@@ -8825,6 +9137,10 @@ class SpotifyClient:
8825
9137
  <summary>Sample Code</summary>
8826
9138
  ```python
8827
9139
  .. include:: ../docs/include/samplecode/SpotifyClient/GetTrack.py
9140
+ ```
9141
+ <summary>Sample Code - NowPlaying</summary>
9142
+ ```python
9143
+ .. include:: ../docs/include/samplecode/SpotifyClient/GetTrack_NowPlaying.py
8828
9144
  ```
8829
9145
  </details>
8830
9146
  """
@@ -8839,6 +9155,14 @@ class SpotifyClient:
8839
9155
  apiMethodParms.AppendKeyValue("trackId", trackId)
8840
9156
  _logsi.LogMethodParmList(SILevel.Verbose, "Get Spotify catalog information for a single track", apiMethodParms)
8841
9157
 
9158
+ # if trackId not specified, then return currently playing track id value.
9159
+ if (trackId is None) or (len(trackId.strip()) == 0):
9160
+ uri = self.GetPlayerNowPlayingUri('track')
9161
+ if uri is not None:
9162
+ trackId = SpotifyClient.GetIdFromUri(uri)
9163
+ else:
9164
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'trackId'), logsi=_logsi)
9165
+
8842
9166
  # execute spotify web api request.
8843
9167
  msg:SpotifyApiMessage = SpotifyApiMessage(apiMethodName, '/tracks/{id}'.format(id=trackId))
8844
9168
  msg.RequestHeaders[self.AuthToken.HeaderKey] = self.AuthToken.HeaderValue
@@ -8851,6 +9175,7 @@ class SpotifyClient:
8851
9175
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
8852
9176
  return result
8853
9177
 
9178
+ except SpotifyApiError: raise # pass handled exceptions on thru
8854
9179
  except SpotifyWebApiError: raise # pass handled exceptions on thru
8855
9180
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
8856
9181
  except Exception as ex:
@@ -8864,9 +9189,10 @@ class SpotifyClient:
8864
9189
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
8865
9190
 
8866
9191
 
8867
- def GetTrackAudioFeatures(self,
8868
- trackId:str,
8869
- ) -> AudioFeatures:
9192
+ def GetTrackAudioFeatures(
9193
+ self,
9194
+ trackId:str=None,
9195
+ ) -> AudioFeatures:
8870
9196
  """
8871
9197
  Get audio feature information for a single track identified by its unique Spotify ID.
8872
9198
 
@@ -8874,6 +9200,8 @@ class SpotifyClient:
8874
9200
  trackId (str):
8875
9201
  The Spotify ID of the track.
8876
9202
  Example: `1kWUud3vY5ij5r62zxpTRy`
9203
+ If null, the currently playing track uri id value is used; a Spotify Free or Premium account
9204
+ is required to correctly read the currently playing context.
8877
9205
 
8878
9206
  Returns:
8879
9207
  An `AudioFeatures` object that contains the audio feature details.
@@ -8903,6 +9231,14 @@ class SpotifyClient:
8903
9231
  apiMethodParms.AppendKeyValue("trackId", trackId)
8904
9232
  _logsi.LogMethodParmList(SILevel.Verbose, "Get audio feature information for a single track", apiMethodParms)
8905
9233
 
9234
+ # if trackId not specified, then return currently playing track id value.
9235
+ if (trackId is None) or (len(trackId.strip()) == 0):
9236
+ uri = self.GetPlayerNowPlayingUri('track')
9237
+ if uri is not None:
9238
+ trackId = SpotifyClient.GetIdFromUri(uri)
9239
+ else:
9240
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'trackId'), logsi=_logsi)
9241
+
8906
9242
  # execute spotify web api request.
8907
9243
  msg:SpotifyApiMessage = SpotifyApiMessage(apiMethodName, '/audio-features/{id}'.format(id=trackId))
8908
9244
  msg.RequestHeaders[self.AuthToken.HeaderKey] = self.AuthToken.HeaderValue
@@ -8915,6 +9251,7 @@ class SpotifyClient:
8915
9251
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
8916
9252
  return result
8917
9253
 
9254
+ except SpotifyApiError: raise # pass handled exceptions on thru
8918
9255
  except SpotifyWebApiError: raise # pass handled exceptions on thru
8919
9256
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
8920
9257
  except Exception as ex:
@@ -9073,14 +9410,18 @@ class SpotifyClient:
9073
9410
  # update result object with final paging details.
9074
9411
  result.Total = pageObj.Total
9075
9412
 
9076
- # sort items on Name property, ascending order.
9077
- if (len(result.Items) > 0) and (sortResult is True):
9078
- result.Items.sort(key=lambda x: (x.Track.Name or "").lower(), reverse=False)
9413
+ # sort result items.
9414
+ if (len(result.Items) > 0):
9415
+ if (sortResult is True):
9416
+ result.Items.sort(key=lambda x: (x.Track.Name or "").lower(), reverse=False)
9417
+ else:
9418
+ result.Items.sort(key=lambda x: (x.AddedAt or "").lower(), reverse=True)
9079
9419
 
9080
9420
  # trace.
9081
9421
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
9082
9422
  return result
9083
9423
 
9424
+ except SpotifyApiError: raise # pass handled exceptions on thru
9084
9425
  except SpotifyWebApiError: raise # pass handled exceptions on thru
9085
9426
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
9086
9427
  except Exception as ex:
@@ -9171,6 +9512,7 @@ class SpotifyClient:
9171
9512
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[Track]'), result)
9172
9513
  return result
9173
9514
 
9515
+ except SpotifyApiError: raise # pass handled exceptions on thru
9174
9516
  except SpotifyWebApiError: raise # pass handled exceptions on thru
9175
9517
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
9176
9518
  except Exception as ex:
@@ -9246,6 +9588,7 @@ class SpotifyClient:
9246
9588
  _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, 'list[AudioFeatures]'), result)
9247
9589
  return result
9248
9590
 
9591
+ except SpotifyApiError: raise # pass handled exceptions on thru
9249
9592
  except SpotifyWebApiError: raise # pass handled exceptions on thru
9250
9593
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
9251
9594
  except Exception as ex:
@@ -9648,6 +9991,7 @@ class SpotifyClient:
9648
9991
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
9649
9992
  return result
9650
9993
 
9994
+ except SpotifyApiError: raise # pass handled exceptions on thru
9651
9995
  except SpotifyWebApiError: raise # pass handled exceptions on thru
9652
9996
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
9653
9997
  except Exception as ex:
@@ -9772,6 +10116,7 @@ class SpotifyClient:
9772
10116
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE_CACHED % (apiMethodName, type(result).__name__, cacheDesc), result, excludeNonPublic=True)
9773
10117
  return result
9774
10118
 
10119
+ except SpotifyApiError: raise # pass handled exceptions on thru
9775
10120
  except SpotifyWebApiError: raise # pass handled exceptions on thru
9776
10121
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
9777
10122
  except Exception as ex:
@@ -9836,6 +10181,7 @@ class SpotifyClient:
9836
10181
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
9837
10182
  return result
9838
10183
 
10184
+ except SpotifyApiError: raise # pass handled exceptions on thru
9839
10185
  except SpotifyWebApiError: raise # pass handled exceptions on thru
9840
10186
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
9841
10187
  except Exception as ex:
@@ -9990,14 +10336,16 @@ class SpotifyClient:
9990
10336
  # update result object with final paging details.
9991
10337
  result.Total = pageObj.Total
9992
10338
 
9993
- # sort items on Name property, ascending order.
9994
- if (len(result.Items) > 0) and (sortResult is True):
9995
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
10339
+ # sort result items.
10340
+ if (len(result.Items) > 0):
10341
+ if (sortResult is True):
10342
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
9996
10343
 
9997
10344
  # trace.
9998
10345
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
9999
10346
  return result
10000
10347
 
10348
+ except SpotifyApiError: raise # pass handled exceptions on thru
10001
10349
  except SpotifyWebApiError: raise # pass handled exceptions on thru
10002
10350
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
10003
10351
  except Exception as ex:
@@ -10152,14 +10500,16 @@ class SpotifyClient:
10152
10500
  # update result object with final paging details.
10153
10501
  result.Total = pageObj.Total
10154
10502
 
10155
- # sort items on Name property, ascending order.
10156
- if (len(result.Items) > 0) and (sortResult is True):
10157
- result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
10503
+ # sort result items.
10504
+ if (len(result.Items) > 0):
10505
+ if (sortResult is True):
10506
+ result.Items.sort(key=lambda x: (x.Name or "").lower(), reverse=False)
10158
10507
 
10159
10508
  # trace.
10160
10509
  _logsi.LogObject(SILevel.Verbose, (TRACE_METHOD_RESULT_TYPE + result.PagingInfo) % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
10161
10510
  return result
10162
10511
 
10512
+ except SpotifyApiError: raise # pass handled exceptions on thru
10163
10513
  except SpotifyWebApiError: raise # pass handled exceptions on thru
10164
10514
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
10165
10515
  except Exception as ex:
@@ -10812,6 +11162,7 @@ class SpotifyClient:
10812
11162
  # no results to process - this is pass or fail.
10813
11163
  return
10814
11164
 
11165
+ except SpotifyApiError: raise # pass handled exceptions on thru
10815
11166
  except SpotifyWebApiError: raise # pass handled exceptions on thru
10816
11167
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
10817
11168
  except Exception as ex:
@@ -10916,6 +11267,7 @@ class SpotifyClient:
10916
11267
  # no results to process - this is pass or fail.
10917
11268
  return
10918
11269
 
11270
+ except SpotifyApiError: raise # pass handled exceptions on thru
10919
11271
  except SpotifyWebApiError: raise # pass handled exceptions on thru
10920
11272
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
10921
11273
  except Exception as ex:
@@ -11009,6 +11361,7 @@ class SpotifyClient:
11009
11361
  # no results to process - this is pass or fail.
11010
11362
  return
11011
11363
 
11364
+ except SpotifyApiError: raise # pass handled exceptions on thru
11012
11365
  except SpotifyWebApiError: raise # pass handled exceptions on thru
11013
11366
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
11014
11367
  except Exception as ex:
@@ -11102,6 +11455,7 @@ class SpotifyClient:
11102
11455
  # no results to process - this is pass or fail.
11103
11456
  return
11104
11457
 
11458
+ except SpotifyApiError: raise # pass handled exceptions on thru
11105
11459
  except SpotifyWebApiError: raise # pass handled exceptions on thru
11106
11460
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
11107
11461
  except Exception as ex:
@@ -11320,6 +11674,7 @@ class SpotifyClient:
11320
11674
  # no results to process - this is pass or fail.
11321
11675
  return
11322
11676
 
11677
+ except SpotifyApiError: raise # pass handled exceptions on thru
11323
11678
  except SpotifyWebApiError: raise # pass handled exceptions on thru
11324
11679
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
11325
11680
  except Exception as ex:
@@ -11423,6 +11778,7 @@ class SpotifyClient:
11423
11778
  # no results to process - this is pass or fail.
11424
11779
  return
11425
11780
 
11781
+ except SpotifyApiError: raise # pass handled exceptions on thru
11426
11782
  except SpotifyWebApiError: raise # pass handled exceptions on thru
11427
11783
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
11428
11784
  except Exception as ex:
@@ -11525,6 +11881,7 @@ class SpotifyClient:
11525
11881
  # no results to process - this is pass or fail.
11526
11882
  return
11527
11883
 
11884
+ except SpotifyApiError: raise # pass handled exceptions on thru
11528
11885
  except SpotifyWebApiError: raise # pass handled exceptions on thru
11529
11886
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
11530
11887
  except Exception as ex:
@@ -11746,6 +12103,7 @@ class SpotifyClient:
11746
12103
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
11747
12104
  return result
11748
12105
 
12106
+ except SpotifyApiError: raise # pass handled exceptions on thru
11749
12107
  except SpotifyWebApiError: raise # pass handled exceptions on thru
11750
12108
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
11751
12109
  except Exception as ex:
@@ -11806,7 +12164,7 @@ class SpotifyClient:
11806
12164
 
11807
12165
  # if ids not specified, then return currently playing album id value.
11808
12166
  if (ids is None) or (len(ids.strip()) == 0):
11809
- uri = self._GetPlayerNowPlayingAlbumUri()
12167
+ uri = self.GetPlayerNowPlayingAlbumUri()
11810
12168
  if uri is not None:
11811
12169
  ids = SpotifyClient.GetIdFromUri(uri)
11812
12170
  else:
@@ -11896,7 +12254,7 @@ class SpotifyClient:
11896
12254
 
11897
12255
  # if ids not specified, then return currently playing id value.
11898
12256
  if (ids is None) or (len(ids.strip()) == 0):
11899
- uri = self._GetPlayerNowPlayingAudiobookUri()
12257
+ uri = self.GetPlayerNowPlayingAudiobookUri()
11900
12258
  if uri is not None:
11901
12259
  ids = SpotifyClient.GetIdFromUri(uri)
11902
12260
  else:
@@ -11986,7 +12344,7 @@ class SpotifyClient:
11986
12344
 
11987
12345
  # if ids not specified, then return currently playing id value.
11988
12346
  if (ids is None) or (len(ids.strip()) == 0):
11989
- uri = self._GetPlayerNowPlayingUri('episode')
12347
+ uri = self.GetPlayerNowPlayingUri('episode')
11990
12348
  if uri is not None:
11991
12349
  ids = SpotifyClient.GetIdFromUri(uri)
11992
12350
  else:
@@ -12157,7 +12515,7 @@ class SpotifyClient:
12157
12515
 
12158
12516
  # if uris not specified, then return currently playing uri value.
12159
12517
  if (uris is None) or (len(uris.strip()) == 0):
12160
- uris = self._GetPlayerNowPlayingUri()
12518
+ uris = self.GetPlayerNowPlayingUri(None)
12161
12519
  if uris is None:
12162
12520
  raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'uris'), logsi=_logsi)
12163
12521
 
@@ -12255,7 +12613,7 @@ class SpotifyClient:
12255
12613
 
12256
12614
  # if ids not specified, then return currently playing id value.
12257
12615
  if (ids is None) or (len(ids.strip()) == 0):
12258
- uri = self._GetPlayerNowPlayingShowUri()
12616
+ uri = self.GetPlayerNowPlayingShowUri()
12259
12617
  if uri is not None:
12260
12618
  ids = SpotifyClient.GetIdFromUri(uri)
12261
12619
  else:
@@ -12344,7 +12702,7 @@ class SpotifyClient:
12344
12702
 
12345
12703
  # if ids not specified, then return currently playing id value.
12346
12704
  if (ids is None) or (len(ids.strip()) == 0):
12347
- uri = self._GetPlayerNowPlayingUri('track')
12705
+ uri = self.GetPlayerNowPlayingUri('track')
12348
12706
  if uri is not None:
12349
12707
  ids = SpotifyClient.GetIdFromUri(uri)
12350
12708
  else:
@@ -12485,6 +12843,7 @@ class SpotifyClient:
12485
12843
  _logsi.LogString(SILevel.Verbose, TRACE_METHOD_RESULT % apiMethodName, result)
12486
12844
  return result
12487
12845
 
12846
+ except SpotifyApiError: raise # pass handled exceptions on thru
12488
12847
  except SpotifyWebApiError: raise # pass handled exceptions on thru
12489
12848
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
12490
12849
  except Exception as ex:
@@ -12574,6 +12933,7 @@ class SpotifyClient:
12574
12933
  _logsi.LogString(SILevel.Verbose, TRACE_METHOD_RESULT % apiMethodName, result)
12575
12934
  return result
12576
12935
 
12936
+ except SpotifyApiError: raise # pass handled exceptions on thru
12577
12937
  except SpotifyWebApiError: raise # pass handled exceptions on thru
12578
12938
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
12579
12939
  except Exception as ex:
@@ -12634,7 +12994,7 @@ class SpotifyClient:
12634
12994
 
12635
12995
  # if ids not specified, then return currently playing album id value.
12636
12996
  if (ids is None) or (len(ids.strip()) == 0):
12637
- uri = self._GetPlayerNowPlayingAlbumUri()
12997
+ uri = self.GetPlayerNowPlayingAlbumUri()
12638
12998
  if uri is not None:
12639
12999
  ids = SpotifyClient.GetIdFromUri(uri)
12640
13000
  else:
@@ -12724,7 +13084,7 @@ class SpotifyClient:
12724
13084
 
12725
13085
  # if ids not specified, then return currently playing id value.
12726
13086
  if (ids is None) or (len(ids.strip()) == 0):
12727
- uri = self._GetPlayerNowPlayingAudiobookUri()
13087
+ uri = self.GetPlayerNowPlayingAudiobookUri()
12728
13088
  if uri is not None:
12729
13089
  ids = SpotifyClient.GetIdFromUri(uri)
12730
13090
  else:
@@ -12814,7 +13174,7 @@ class SpotifyClient:
12814
13174
 
12815
13175
  # if ids not specified, then return currently playing id value.
12816
13176
  if (ids is None) or (len(ids.strip()) == 0):
12817
- uri = self._GetPlayerNowPlayingUri('episode')
13177
+ uri = self.GetPlayerNowPlayingUri('episode')
12818
13178
  if uri is not None:
12819
13179
  ids = SpotifyClient.GetIdFromUri(uri)
12820
13180
  else:
@@ -12904,7 +13264,7 @@ class SpotifyClient:
12904
13264
 
12905
13265
  # if ids not specified, then return currently playing id value.
12906
13266
  if (ids is None) or (len(ids.strip()) == 0):
12907
- uri = self._GetPlayerNowPlayingShowUri()
13267
+ uri = self.GetPlayerNowPlayingShowUri()
12908
13268
  if uri is not None:
12909
13269
  ids = SpotifyClient.GetIdFromUri(uri)
12910
13270
  else:
@@ -12993,7 +13353,7 @@ class SpotifyClient:
12993
13353
 
12994
13354
  # if ids not specified, then return currently playing id value.
12995
13355
  if (ids is None) or (len(ids.strip()) == 0):
12996
- uri = self._GetPlayerNowPlayingUri('track')
13356
+ uri = self.GetPlayerNowPlayingUri('track')
12997
13357
  if uri is not None:
12998
13358
  ids = SpotifyClient.GetIdFromUri(uri)
12999
13359
  else:
@@ -13199,6 +13559,7 @@ class SpotifyClient:
13199
13559
  # _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
13200
13560
  # return result
13201
13561
 
13562
+ # except SpotifyApiError: raise # pass handled exceptions on thru
13202
13563
  # except SpotifyWebApiError: raise # pass handled exceptions on thru
13203
13564
  # except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
13204
13565
  # except Exception as ex:
@@ -13390,6 +13751,7 @@ class SpotifyClient:
13390
13751
  response.Albums = result
13391
13752
  return response
13392
13753
 
13754
+ except SpotifyApiError: raise # pass handled exceptions on thru
13393
13755
  except SpotifyWebApiError: raise # pass handled exceptions on thru
13394
13756
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
13395
13757
  except Exception as ex:
@@ -13581,6 +13943,7 @@ class SpotifyClient:
13581
13943
  response.Artists = result
13582
13944
  return response
13583
13945
 
13946
+ except SpotifyApiError: raise # pass handled exceptions on thru
13584
13947
  except SpotifyWebApiError: raise # pass handled exceptions on thru
13585
13948
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
13586
13949
  except Exception as ex:
@@ -13774,6 +14137,7 @@ class SpotifyClient:
13774
14137
  response.Audiobooks = result
13775
14138
  return response
13776
14139
 
14140
+ except SpotifyApiError: raise # pass handled exceptions on thru
13777
14141
  except SpotifyWebApiError: raise # pass handled exceptions on thru
13778
14142
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
13779
14143
  except Exception as ex:
@@ -13965,6 +14329,7 @@ class SpotifyClient:
13965
14329
  response.Episodes = result
13966
14330
  return response
13967
14331
 
14332
+ except SpotifyApiError: raise # pass handled exceptions on thru
13968
14333
  except SpotifyWebApiError: raise # pass handled exceptions on thru
13969
14334
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
13970
14335
  except Exception as ex:
@@ -14156,6 +14521,7 @@ class SpotifyClient:
14156
14521
  response.Playlists = result
14157
14522
  return response
14158
14523
 
14524
+ except SpotifyApiError: raise # pass handled exceptions on thru
14159
14525
  except SpotifyWebApiError: raise # pass handled exceptions on thru
14160
14526
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
14161
14527
  except Exception as ex:
@@ -14347,6 +14713,7 @@ class SpotifyClient:
14347
14713
  response.Shows = result
14348
14714
  return response
14349
14715
 
14716
+ except SpotifyApiError: raise # pass handled exceptions on thru
14350
14717
  except SpotifyWebApiError: raise # pass handled exceptions on thru
14351
14718
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
14352
14719
  except Exception as ex:
@@ -14538,6 +14905,7 @@ class SpotifyClient:
14538
14905
  response.Tracks = result
14539
14906
  return response
14540
14907
 
14908
+ except SpotifyApiError: raise # pass handled exceptions on thru
14541
14909
  except SpotifyWebApiError: raise # pass handled exceptions on thru
14542
14910
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
14543
14911
  except Exception as ex:
@@ -14999,6 +15367,7 @@ class SpotifyClient:
14999
15367
  # trace.
15000
15368
  _logsi.LogObject(SILevel.Verbose, TRACE_MSG_USERPROFILE % (self._UserProfile.DisplayName, self._UserProfile.EMail), self._UserProfile, excludeNonPublic=True)
15001
15369
 
15370
+ except SpotifyApiError: raise # pass handled exceptions on thru
15002
15371
  except SpotifyWebApiError: raise # pass handled exceptions on thru
15003
15372
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
15004
15373
  except Exception as ex:
@@ -15133,9 +15502,10 @@ class SpotifyClient:
15133
15502
  return msg
15134
15503
 
15135
15504
 
15136
- def UnfollowArtists(self,
15137
- ids:str=None,
15138
- ) -> None:
15505
+ def UnfollowArtists(
15506
+ self,
15507
+ ids:str=None,
15508
+ ) -> None:
15139
15509
  """
15140
15510
  Remove the current user as a follower of one or more artists.
15141
15511
 
@@ -15176,7 +15546,7 @@ class SpotifyClient:
15176
15546
 
15177
15547
  # if ids not specified, then return currently playing artist id value.
15178
15548
  if (ids is None) or (len(ids.strip()) == 0):
15179
- uri = self._GetPlayerNowPlayingArtistUri()
15549
+ uri = self.GetPlayerNowPlayingArtistUri()
15180
15550
  if uri is not None:
15181
15551
  ids = SpotifyClient.GetIdFromUri(uri)
15182
15552
  else:
@@ -15204,6 +15574,7 @@ class SpotifyClient:
15204
15574
  # no results to process - this is pass or fail.
15205
15575
  return
15206
15576
 
15577
+ except SpotifyApiError: raise # pass handled exceptions on thru
15207
15578
  except SpotifyWebApiError: raise # pass handled exceptions on thru
15208
15579
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
15209
15580
  except Exception as ex:
@@ -15217,9 +15588,10 @@ class SpotifyClient:
15217
15588
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
15218
15589
 
15219
15590
 
15220
- def UnfollowPlaylist(self,
15221
- playlistId:str,
15222
- ) -> None:
15591
+ def UnfollowPlaylist(
15592
+ self,
15593
+ playlistId:str=None,
15594
+ ) -> None:
15223
15595
  """
15224
15596
  Remove the current user as a follower of a playlist.
15225
15597
 
@@ -15229,6 +15601,7 @@ class SpotifyClient:
15229
15601
  playlistId (str):
15230
15602
  The Spotify ID of the playlist.
15231
15603
  Example: `3cEYpjA9oz9GiPac4AsH4n`
15604
+ If null, the currently playing playlist uri id value is used.
15232
15605
 
15233
15606
  Raises:
15234
15607
  SpotifyWebApiError:
@@ -15254,6 +15627,14 @@ class SpotifyClient:
15254
15627
  apiMethodParms.AppendKeyValue("playlistId", playlistId)
15255
15628
  _logsi.LogMethodParmList(SILevel.Verbose, "Remove the current user as a follower of a playlist", apiMethodParms)
15256
15629
 
15630
+ # if playlistId not specified, then return currently playing playlist id value.
15631
+ if (playlistId is None) or (len(playlistId.strip()) == 0):
15632
+ uri = self.GetPlayerNowPlayingPlaylistUri()
15633
+ if uri is not None:
15634
+ playlistId = SpotifyClient.GetIdFromUri(uri)
15635
+ else:
15636
+ raise SpotifyApiError(SAAppMessages.ARGUMENT_REQUIRED_ERROR % (apiMethodName, 'playlistId'), logsi=_logsi)
15637
+
15257
15638
  # execute spotify web api request.
15258
15639
  msg:SpotifyApiMessage = SpotifyApiMessage(apiMethodName, '/playlists/{playlist_id}/followers'.format(playlist_id=playlistId))
15259
15640
  msg.RequestHeaders[self.AuthToken.HeaderKey] = self.AuthToken.HeaderValue
@@ -15263,6 +15644,7 @@ class SpotifyClient:
15263
15644
  # no results to process - this is pass or fail.
15264
15645
  return
15265
15646
 
15647
+ except SpotifyApiError: raise # pass handled exceptions on thru
15266
15648
  except SpotifyWebApiError: raise # pass handled exceptions on thru
15267
15649
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
15268
15650
  except Exception as ex:
@@ -15338,6 +15720,7 @@ class SpotifyClient:
15338
15720
  # no results to process - this is pass or fail.
15339
15721
  return
15340
15722
 
15723
+ except SpotifyApiError: raise # pass handled exceptions on thru
15341
15724
  except SpotifyWebApiError: raise # pass handled exceptions on thru
15342
15725
  except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
15343
15726
  except Exception as ex: