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

@@ -3,6 +3,7 @@ import base64
3
3
  import json
4
4
  from io import BytesIO
5
5
  from oauthlib.oauth2 import BackendApplicationClient, WebApplicationClient
6
+ import time
6
7
  from typing import Tuple, Callable
7
8
  from urllib3 import PoolManager, Timeout, HTTPResponse
8
9
  from urllib.parse import urlencode
@@ -29,6 +30,7 @@ from .const import (
29
30
  TRACE_METHOD_RESULT_TYPE_PAGE,
30
31
  TRACE_MSG_AUTHTOKEN_CREATE,
31
32
  TRACE_MSG_AUTOPAGING_NEXT,
33
+ TRACE_MSG_DELAY_DEVICE,
32
34
  TRACE_MSG_USERPROFILE,
33
35
  TRACE_WARN_SPOTIFY_SEARCH_NO_MARKET,
34
36
  )
@@ -548,6 +550,32 @@ class SpotifyClient:
548
550
  return result
549
551
 
550
552
 
553
+ def _ValidateDelay(self, delay:float, default:float=0.5, maxDelay:float=10) -> float:
554
+ """
555
+ Validates a delay value.
556
+
557
+ Args:
558
+ delay (int):
559
+ The delay value to validate.
560
+ default (int):
561
+ The default delay value to set if the user-input delay is not valid.
562
+ maxDelay (int):
563
+ The maximum delay value allowed.
564
+ Default is 10.
565
+ """
566
+ if (isinstance(delay,int)):
567
+ delay = float(delay)
568
+
569
+ if (not isinstance(delay,float)) or (delay < 0):
570
+ result = default
571
+ elif (delay > maxDelay):
572
+ result = maxDelay
573
+ else:
574
+ result = delay
575
+
576
+ return result
577
+
578
+
551
579
  def _ValidateMarket(self,
552
580
  market:str,
553
581
  ) -> str:
@@ -5689,7 +5717,8 @@ class SpotifyClient:
5689
5717
  properly handles cases of new types in the future by checking against the type field of each object.
5690
5718
 
5691
5719
  Returns:
5692
- A `PlayerPlayState` object that contains the currently playing media, or null if nothing is playing.
5720
+ A `PlayerPlayState` object that contains player state details as well as
5721
+ currently playing content.
5693
5722
 
5694
5723
  Raises:
5695
5724
  SpotifyWebApiError:
@@ -5780,7 +5809,8 @@ class SpotifyClient:
5780
5809
  properly handles cases of new types in the future by checking against the type field of each object.
5781
5810
 
5782
5811
  Returns:
5783
- A `PlayerPlayState` object that contains the currently playing media state.
5812
+ A `PlayerPlayState` object that contains player state details as well as
5813
+ currently playing content.
5784
5814
 
5785
5815
  Raises:
5786
5816
  SpotifyWebApiError:
@@ -8579,7 +8609,8 @@ class SpotifyClient:
8579
8609
 
8580
8610
 
8581
8611
  def PlayerMediaPause(self,
8582
- deviceId:str=None
8612
+ deviceId:str=None,
8613
+ delay:float=0.50
8583
8614
  ) -> None:
8584
8615
  """
8585
8616
  Pause media play for the specified Spotify Connect device.
@@ -8591,7 +8622,12 @@ class SpotifyClient:
8591
8622
  The id of the device this command is targeting.
8592
8623
  If not supplied, the user's currently active device is the target.
8593
8624
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
8594
-
8625
+ delay (float):
8626
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
8627
+ This delay will give the spotify web api time to process the change before
8628
+ another command is issued.
8629
+ Default is 0.50; value range is 0 - 10.
8630
+
8595
8631
  Raises:
8596
8632
  SpotifyWebApiError:
8597
8633
  If the Spotify Web API request was for a non-authorization service
@@ -8618,8 +8654,12 @@ class SpotifyClient:
8618
8654
  # trace.
8619
8655
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
8620
8656
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
8657
+ apiMethodParms.AppendKeyValue("delay", delay)
8621
8658
  _logsi.LogMethodParmList(SILevel.Verbose, "Spotify Connect device pause playback", apiMethodParms)
8622
8659
 
8660
+ # validations.
8661
+ delay = self._ValidateDelay(delay, 0.50, 10)
8662
+
8623
8663
  # build spotify web api request parameters.
8624
8664
  urlParms:dict = {}
8625
8665
  if deviceId is not None:
@@ -8631,6 +8671,11 @@ class SpotifyClient:
8631
8671
  msg.UrlParameters = urlParms
8632
8672
  self.MakeRequest('PUT', msg)
8633
8673
 
8674
+ # give spotify web api time to process the change.
8675
+ if delay > 0:
8676
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
8677
+ time.sleep(delay)
8678
+
8634
8679
  # process results.
8635
8680
  # no results to process - this is pass or fail.
8636
8681
  return
@@ -8653,7 +8698,8 @@ class SpotifyClient:
8653
8698
  offsetUri:str=None,
8654
8699
  offsetPosition:int=None,
8655
8700
  positionMS:int=0,
8656
- deviceId:str=None
8701
+ deviceId:str=None,
8702
+ delay:float=0.50
8657
8703
  ) -> None:
8658
8704
  """
8659
8705
  Start playing one or more tracks of the specified context on a Spotify Connect device.
@@ -8687,6 +8733,11 @@ class SpotifyClient:
8687
8733
  The id of the device this command is targeting.
8688
8734
  If not supplied, the user's currently active device is the target.
8689
8735
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
8736
+ delay (float):
8737
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
8738
+ This delay will give the spotify web api time to process the change before
8739
+ another command is issued.
8740
+ Default is 0.50; value range is 0 - 10.
8690
8741
 
8691
8742
  Raises:
8692
8743
  SpotifyWebApiError:
@@ -8732,8 +8783,12 @@ class SpotifyClient:
8732
8783
  apiMethodParms.AppendKeyValue("offsetPosition", offsetPosition)
8733
8784
  apiMethodParms.AppendKeyValue("positionMS", positionMS)
8734
8785
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
8786
+ apiMethodParms.AppendKeyValue("delay", delay)
8735
8787
  _logsi.LogMethodParmList(SILevel.Verbose, "Spotify Connect device play context", apiMethodParms)
8736
8788
 
8789
+ # validations.
8790
+ delay = self._ValidateDelay(delay, 0.50, 10)
8791
+
8737
8792
  # build spotify web api request parameters.
8738
8793
  reqData:dict = \
8739
8794
  {
@@ -8756,6 +8811,11 @@ class SpotifyClient:
8756
8811
  msg.RequestJson = reqData
8757
8812
  self.MakeRequest('PUT', msg)
8758
8813
 
8814
+ # give spotify web api time to process the change.
8815
+ if delay > 0:
8816
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
8817
+ time.sleep(delay)
8818
+
8759
8819
  # process results.
8760
8820
  # no results to process - this is pass or fail.
8761
8821
  return
@@ -8776,7 +8836,8 @@ class SpotifyClient:
8776
8836
  def PlayerMediaPlayTracks(self,
8777
8837
  uris:list[str],
8778
8838
  positionMS:int=0,
8779
- deviceId:str=None
8839
+ deviceId:str=None,
8840
+ delay:float=0.50
8780
8841
  ) -> None:
8781
8842
  """
8782
8843
  Start playing one or more tracks on the specified Spotify Connect device.
@@ -8800,6 +8861,11 @@ class SpotifyClient:
8800
8861
  The id of the device this command is targeting.
8801
8862
  If not supplied, the user's currently active device is the target.
8802
8863
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
8864
+ delay (float):
8865
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
8866
+ This delay will give the spotify web api time to process the change before
8867
+ another command is issued.
8868
+ Default is 0.50; value range is 0 - 10.
8803
8869
 
8804
8870
  Raises:
8805
8871
  SpotifyWebApiError:
@@ -8829,8 +8895,12 @@ class SpotifyClient:
8829
8895
  apiMethodParms.AppendKeyValue("uris", uris)
8830
8896
  apiMethodParms.AppendKeyValue("positionMS", positionMS)
8831
8897
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
8898
+ apiMethodParms.AppendKeyValue("delay", delay)
8832
8899
  _logsi.LogMethodParmList(SILevel.Verbose, "Spotify Connect device play tracks", apiMethodParms)
8833
8900
 
8901
+ # validations.
8902
+ delay = self._ValidateDelay(delay, 0.50, 10)
8903
+
8834
8904
  # build a list of all item uri's.
8835
8905
  # remove any leading / trailing spaces in case user put a space between the items.
8836
8906
  arrUris:list[str] = None
@@ -8860,6 +8930,11 @@ class SpotifyClient:
8860
8930
  msg.RequestJson = reqData
8861
8931
  self.MakeRequest('PUT', msg)
8862
8932
 
8933
+ # give spotify web api time to process the change.
8934
+ if delay > 0:
8935
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
8936
+ time.sleep(delay)
8937
+
8863
8938
  # process results.
8864
8939
  # no results to process - this is pass or fail.
8865
8940
  return
@@ -8878,7 +8953,8 @@ class SpotifyClient:
8878
8953
 
8879
8954
 
8880
8955
  def PlayerMediaResume(self,
8881
- deviceId:str=None
8956
+ deviceId:str=None,
8957
+ delay:float=0.50
8882
8958
  ) -> None:
8883
8959
  """
8884
8960
  Resume media play for the specified Spotify Connect device.
@@ -8890,6 +8966,11 @@ class SpotifyClient:
8890
8966
  The id of the device this command is targeting.
8891
8967
  If not supplied, the user's currently active device is the target.
8892
8968
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
8969
+ delay (float):
8970
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
8971
+ This delay will give the spotify web api time to process the change before
8972
+ another command is issued.
8973
+ Default is 0.50; value range is 0 - 10.
8893
8974
 
8894
8975
  Raises:
8895
8976
  SpotifyWebApiError:
@@ -8917,8 +8998,13 @@ class SpotifyClient:
8917
8998
  # trace.
8918
8999
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
8919
9000
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
9001
+ apiMethodParms.AppendKeyValue("delay", delay)
8920
9002
  _logsi.LogMethodParmList(SILevel.Verbose, "Spotify Connect device resume playback", apiMethodParms)
8921
9003
 
9004
+ # validations.
9005
+ delay = self._ValidateDelay(delay, 0.50, 10)
9006
+
9007
+ # build spotify web api request parameters.
8922
9008
  urlParms:dict = {}
8923
9009
  if deviceId is not None:
8924
9010
  urlParms['device_id'] = deviceId
@@ -8929,6 +9015,11 @@ class SpotifyClient:
8929
9015
  msg.UrlParameters = urlParms
8930
9016
  self.MakeRequest('PUT', msg)
8931
9017
 
9018
+ # give spotify web api time to process the change.
9019
+ if delay > 0:
9020
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
9021
+ time.sleep(delay)
9022
+
8932
9023
  # process results.
8933
9024
  # no results to process - this is pass or fail.
8934
9025
  return
@@ -8948,7 +9039,8 @@ class SpotifyClient:
8948
9039
 
8949
9040
  def PlayerMediaSeek(self,
8950
9041
  positionMS:int=0,
8951
- deviceId:str=None
9042
+ deviceId:str=None,
9043
+ delay:float=0.50
8952
9044
  ) -> None:
8953
9045
  """
8954
9046
  Seeks to the given position in the user's currently playing track for the specified
@@ -8966,6 +9058,11 @@ class SpotifyClient:
8966
9058
  The id of the device this command is targeting.
8967
9059
  If not supplied, the user's currently active device is the target.
8968
9060
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
9061
+ delay (float):
9062
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
9063
+ This delay will give the spotify web api time to process the change before
9064
+ another command is issued.
9065
+ Default is 0.50; value range is 0 - 10.
8969
9066
 
8970
9067
  Raises:
8971
9068
  SpotifyWebApiError:
@@ -8994,8 +9091,13 @@ class SpotifyClient:
8994
9091
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
8995
9092
  apiMethodParms.AppendKeyValue("positionMS", positionMS)
8996
9093
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
9094
+ apiMethodParms.AppendKeyValue("delay", delay)
8997
9095
  _logsi.LogMethodParmList(SILevel.Verbose, "Spotify Connect device seek position", apiMethodParms)
8998
9096
 
9097
+ # validations.
9098
+ delay = self._ValidateDelay(delay, 0.50, 10)
9099
+
9100
+ # build spotify web api request parameters.
8999
9101
  urlParms:dict = \
9000
9102
  {
9001
9103
  'position_ms': positionMS
@@ -9009,6 +9111,11 @@ class SpotifyClient:
9009
9111
  msg.UrlParameters = urlParms
9010
9112
  self.MakeRequest('PUT', msg)
9011
9113
 
9114
+ # give spotify web api time to process the change.
9115
+ if delay > 0:
9116
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
9117
+ time.sleep(delay)
9118
+
9012
9119
  # process results.
9013
9120
  # no results to process - this is pass or fail.
9014
9121
  return
@@ -9027,7 +9134,8 @@ class SpotifyClient:
9027
9134
 
9028
9135
 
9029
9136
  def PlayerMediaSkipNext(self,
9030
- deviceId:str=None
9137
+ deviceId:str=None,
9138
+ delay:float=0.50
9031
9139
  ) -> None:
9032
9140
  """
9033
9141
  Skips to next track in the user's queue for the specified Spotify Connect device.
@@ -9039,6 +9147,11 @@ class SpotifyClient:
9039
9147
  The id of the device this command is targeting.
9040
9148
  If not supplied, the user's currently active device is the target.
9041
9149
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
9150
+ delay (float):
9151
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
9152
+ This delay will give the spotify web api time to process the change before
9153
+ another command is issued.
9154
+ Default is 0.50; value range is 0 - 10.
9042
9155
 
9043
9156
  Raises:
9044
9157
  SpotifyWebApiError:
@@ -9066,8 +9179,13 @@ class SpotifyClient:
9066
9179
  # trace.
9067
9180
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
9068
9181
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
9182
+ apiMethodParms.AppendKeyValue("delay", delay)
9069
9183
  _logsi.LogMethodParmList(SILevel.Verbose, "Spotify Connect device skip next", apiMethodParms)
9070
9184
 
9185
+ # validations.
9186
+ delay = self._ValidateDelay(delay, 0.50, 10)
9187
+
9188
+ # build spotify web api request parameters.
9071
9189
  urlParms:dict = {}
9072
9190
  if deviceId is not None:
9073
9191
  urlParms['device_id'] = deviceId
@@ -9078,6 +9196,11 @@ class SpotifyClient:
9078
9196
  msg.UrlParameters = urlParms
9079
9197
  self.MakeRequest('POST', msg)
9080
9198
 
9199
+ # give spotify web api time to process the change.
9200
+ if delay > 0:
9201
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
9202
+ time.sleep(delay)
9203
+
9081
9204
  # process results.
9082
9205
  # no results to process - this is pass or fail.
9083
9206
  return
@@ -9096,7 +9219,8 @@ class SpotifyClient:
9096
9219
 
9097
9220
 
9098
9221
  def PlayerMediaSkipPrevious(self,
9099
- deviceId:str=None
9222
+ deviceId:str=None,
9223
+ delay:float=0.50
9100
9224
  ) -> None:
9101
9225
  """
9102
9226
  Skips to previous track in the user's queue for the specified Spotify Connect device.
@@ -9108,6 +9232,11 @@ class SpotifyClient:
9108
9232
  The id of the device this command is targeting.
9109
9233
  If not supplied, the user's currently active device is the target.
9110
9234
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
9235
+ delay (float):
9236
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
9237
+ This delay will give the spotify web api time to process the change before
9238
+ another command is issued.
9239
+ Default is 0.50; value range is 0 - 10.
9111
9240
 
9112
9241
  Raises:
9113
9242
  SpotifyWebApiError:
@@ -9135,8 +9264,13 @@ class SpotifyClient:
9135
9264
  # trace.
9136
9265
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
9137
9266
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
9267
+ apiMethodParms.AppendKeyValue("delay", delay)
9138
9268
  _logsi.LogMethodParmList(SILevel.Verbose, "Spotify Connect device skip previous", apiMethodParms)
9139
9269
 
9270
+ # validations.
9271
+ delay = self._ValidateDelay(delay, 0.50, 10)
9272
+
9273
+ # build spotify web api request parameters.
9140
9274
  urlParms:dict = {}
9141
9275
  if deviceId is not None:
9142
9276
  urlParms['device_id'] = deviceId
@@ -9147,6 +9281,11 @@ class SpotifyClient:
9147
9281
  msg.UrlParameters = urlParms
9148
9282
  self.MakeRequest('POST', msg)
9149
9283
 
9284
+ # give spotify web api time to process the change.
9285
+ if delay > 0:
9286
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
9287
+ time.sleep(delay)
9288
+
9150
9289
  # process results.
9151
9290
  # no results to process - this is pass or fail.
9152
9291
  return
@@ -9166,7 +9305,8 @@ class SpotifyClient:
9166
9305
 
9167
9306
  def PlayerSetRepeatMode(self,
9168
9307
  state:str='off',
9169
- deviceId:str=None
9308
+ deviceId:str=None,
9309
+ delay:float=0.50
9170
9310
  ) -> None:
9171
9311
  """
9172
9312
  Set repeat mode for the specified Spotify Connect device.
@@ -9184,6 +9324,11 @@ class SpotifyClient:
9184
9324
  The id of the device this command is targeting.
9185
9325
  If not supplied, the user's currently active device is the target.
9186
9326
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
9327
+ delay (float):
9328
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
9329
+ This delay will give the spotify web api time to process the change before
9330
+ another command is issued.
9331
+ Default is 0.50; value range is 0 - 10.
9187
9332
 
9188
9333
  Raises:
9189
9334
  SpotifyWebApiError:
@@ -9212,8 +9357,12 @@ class SpotifyClient:
9212
9357
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
9213
9358
  apiMethodParms.AppendKeyValue("state", state)
9214
9359
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
9360
+ apiMethodParms.AppendKeyValue("delay", delay)
9215
9361
  _logsi.LogMethodParmList(SILevel.Verbose, "Set Spotify Connect device set repeat mode", apiMethodParms)
9216
9362
 
9363
+ # validations.
9364
+ delay = self._ValidateDelay(delay, 0.50, 10)
9365
+
9217
9366
  # build spotify web api request parameters.
9218
9367
  urlParms:dict = \
9219
9368
  {
@@ -9228,6 +9377,11 @@ class SpotifyClient:
9228
9377
  msg.UrlParameters = urlParms
9229
9378
  self.MakeRequest('PUT', msg)
9230
9379
 
9380
+ # give spotify web api time to process the change.
9381
+ if delay > 0:
9382
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
9383
+ time.sleep(delay)
9384
+
9231
9385
  # process results.
9232
9386
  # no results to process - this is pass or fail.
9233
9387
  return
@@ -9247,7 +9401,8 @@ class SpotifyClient:
9247
9401
 
9248
9402
  def PlayerSetShuffleMode(self,
9249
9403
  state:bool=False,
9250
- deviceId:str=None
9404
+ deviceId:str=None,
9405
+ delay:float=0.50
9251
9406
  ) -> None:
9252
9407
  """
9253
9408
  Set shuffle mode for the specified Spotify Connect device.
@@ -9264,6 +9419,11 @@ class SpotifyClient:
9264
9419
  The id of the device this command is targeting.
9265
9420
  If not supplied, the user's currently active device is the target.
9266
9421
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
9422
+ delay (float):
9423
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
9424
+ This delay will give the spotify web api time to process the change before
9425
+ another command is issued.
9426
+ Default is 0.50; value range is 0 - 10.
9267
9427
 
9268
9428
  Raises:
9269
9429
  SpotifyWebApiError:
@@ -9292,8 +9452,12 @@ class SpotifyClient:
9292
9452
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
9293
9453
  apiMethodParms.AppendKeyValue("state", state)
9294
9454
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
9455
+ apiMethodParms.AppendKeyValue("delay", delay)
9295
9456
  _logsi.LogMethodParmList(SILevel.Verbose, "Set Spotify Connect device set shuffle mode", apiMethodParms)
9296
9457
 
9458
+ # validations.
9459
+ delay = self._ValidateDelay(delay, 0.50, 10)
9460
+
9297
9461
  # build spotify web api request parameters.
9298
9462
  urlParms:dict = \
9299
9463
  {
@@ -9308,6 +9472,11 @@ class SpotifyClient:
9308
9472
  msg.UrlParameters = urlParms
9309
9473
  self.MakeRequest('PUT', msg)
9310
9474
 
9475
+ # give spotify web api time to process the change.
9476
+ if delay > 0:
9477
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
9478
+ time.sleep(delay)
9479
+
9311
9480
  # process results.
9312
9481
  # no results to process - this is pass or fail.
9313
9482
  return
@@ -9327,7 +9496,8 @@ class SpotifyClient:
9327
9496
 
9328
9497
  def PlayerSetVolume(self,
9329
9498
  volumePercent:int,
9330
- deviceId:str=None
9499
+ deviceId:str=None,
9500
+ delay:float=0.50
9331
9501
  ) -> None:
9332
9502
  """
9333
9503
  Set volume level for the specified Spotify Connect device.
@@ -9343,6 +9513,11 @@ class SpotifyClient:
9343
9513
  The id of the device this command is targeting.
9344
9514
  If not supplied, the user's currently active device is the target.
9345
9515
  Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
9516
+ delay (float):
9517
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
9518
+ This delay will give the spotify web api time to process the change before
9519
+ another command is issued.
9520
+ Default is 0.50; value range is 0 - 10.
9346
9521
 
9347
9522
  Raises:
9348
9523
  SpotifyWebApiError:
@@ -9371,8 +9546,12 @@ class SpotifyClient:
9371
9546
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
9372
9547
  apiMethodParms.AppendKeyValue("volumePercent", volumePercent)
9373
9548
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
9549
+ apiMethodParms.AppendKeyValue("delay", delay)
9374
9550
  _logsi.LogMethodParmList(SILevel.Verbose, "Set Spotify Connect device set volume level", apiMethodParms)
9375
9551
 
9552
+ # validations.
9553
+ delay = self._ValidateDelay(delay, 0.50, 10)
9554
+
9376
9555
  # build spotify web api request parameters.
9377
9556
  urlParms:dict = \
9378
9557
  {
@@ -9387,6 +9566,11 @@ class SpotifyClient:
9387
9566
  msg.UrlParameters = urlParms
9388
9567
  self.MakeRequest('PUT', msg)
9389
9568
 
9569
+ # give spotify web api time to process the change.
9570
+ if delay > 0:
9571
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
9572
+ time.sleep(delay)
9573
+
9390
9574
  # process results.
9391
9575
  # no results to process - this is pass or fail.
9392
9576
  return
@@ -9407,6 +9591,7 @@ class SpotifyClient:
9407
9591
  def PlayerTransferPlayback(self,
9408
9592
  deviceId:str=None,
9409
9593
  play:bool=True,
9594
+ delay:float=0.50
9410
9595
  ) -> None:
9411
9596
  """
9412
9597
  Transfer playback to a new Spotify Connect device and optionally begin playback.
@@ -9422,6 +9607,11 @@ class SpotifyClient:
9422
9607
  - `True` - ensure playback happens on new device.
9423
9608
  - `False` - keep the current playback state.
9424
9609
  Default: `True`
9610
+ delay (float):
9611
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
9612
+ This delay will give the spotify web api time to process the change before
9613
+ another command is issued.
9614
+ Default is 0.50; value range is 0 - 10.
9425
9615
 
9426
9616
  Raises:
9427
9617
  SpotifyWebApiError:
@@ -9450,8 +9640,12 @@ class SpotifyClient:
9450
9640
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
9451
9641
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
9452
9642
  apiMethodParms.AppendKeyValue("play", play)
9643
+ apiMethodParms.AppendKeyValue("delay", delay)
9453
9644
  _logsi.LogMethodParmList(SILevel.Verbose, "Transfer playback to a new Spotify Connect device", apiMethodParms)
9454
-
9645
+
9646
+ # validations.
9647
+ delay = self._ValidateDelay(delay, 0.50, 10)
9648
+
9455
9649
  # build spotify web api request parameters.
9456
9650
  reqData:dict = \
9457
9651
  {
@@ -9466,6 +9660,11 @@ class SpotifyClient:
9466
9660
  msg.RequestJson = reqData
9467
9661
  self.MakeRequest('PUT', msg)
9468
9662
 
9663
+ # give spotify web api time to process the change.
9664
+ if delay > 0:
9665
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
9666
+ time.sleep(delay)
9667
+
9469
9668
  # process results.
9470
9669
  # no results to process - this is pass or fail.
9471
9670
  return
@@ -9486,6 +9685,7 @@ class SpotifyClient:
9486
9685
  def PlayerVerifyDeviceDefault(self,
9487
9686
  defaultDeviceId:str=None,
9488
9687
  play:bool=False,
9688
+ delay:float=0.50
9489
9689
  ) -> PlayerPlayState:
9490
9690
  """
9491
9691
  Checks to see if there is an active Spotify Connect device, and if not to make one active.
@@ -9505,9 +9705,15 @@ class SpotifyClient:
9505
9705
  - `True` - ensure playback happens on new device.
9506
9706
  - `False` - keep the current playback state.
9507
9707
  Default: `False`
9708
+ delay (float):
9709
+ Time delay (in seconds) to wait AFTER issuing the command to the player.
9710
+ This delay will give the spotify web api time to process the change before
9711
+ another command is issued.
9712
+ Default is 0.50; value range is 0 - 10.
9508
9713
 
9509
9714
  Returns:
9510
- A `PlayerPlayState` object that contains the currently playing media, or null if nothing is playing.
9715
+ A `PlayerPlayState` object that contains player state details as well as
9716
+ currently playing content.
9511
9717
 
9512
9718
  Raises:
9513
9719
  SpotifyWebApiError:
@@ -9533,20 +9739,24 @@ class SpotifyClient:
9533
9739
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
9534
9740
  apiMethodParms.AppendKeyValue("defaultDeviceId", defaultDeviceId)
9535
9741
  apiMethodParms.AppendKeyValue("play", play)
9742
+ apiMethodParms.AppendKeyValue("delay", delay)
9536
9743
  _logsi.LogMethodParmList(SILevel.Verbose, "Checks if a Spotify Connect device is active, and activate one if not", apiMethodParms)
9537
9744
 
9745
+ # validations.
9746
+ delay = self._ValidateDelay(delay, 0.50, 10)
9747
+
9538
9748
  # get current Spotify Connect player state.
9539
9749
  result = self.GetPlayerPlaybackState()
9540
9750
 
9541
9751
  # is there an active device set?
9542
- if (result is None) \
9543
- or (result.CurrentlyPlayingType is None and result.Context is None) \
9544
- or (result.Device is None):
9752
+ if (result.CurrentlyPlayingType is None and result.Context is None) \
9753
+ or (result.Device is None) \
9754
+ or (result.Device.Id is None):
9545
9755
 
9546
9756
  _logsi.LogVerbose('No active Spotify Connect device was found - activating device "%s"' % defaultDeviceId)
9547
9757
 
9548
9758
  # no - transfer control to the default device.
9549
- self.PlayerTransferPlayback(defaultDeviceId, play)
9759
+ self.PlayerTransferPlayback(defaultDeviceId, play, delay)
9550
9760
 
9551
9761
  # get current Spotify Connect player state.
9552
9762
  result = self.GetPlayerPlaybackState()