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

@@ -156,6 +156,7 @@ class SpotifyClient:
156
156
  self._AuthToken:SpotifyAuthToken = None
157
157
  self._AuthClient:AuthClient = None
158
158
  self._ConfigurationCache:dict = {}
159
+ self._DefaultDeviceId:str = None
159
160
  self._Manager:PoolManager = manager
160
161
  self._SpotifyConnectUsername:str = spotifyConnectUsername
161
162
  self._SpotifyConnectPassword:str = spotifyConnectPassword
@@ -273,6 +274,28 @@ class SpotifyClient:
273
274
  return None
274
275
 
275
276
 
277
+ @property
278
+ def DefaultDeviceId(self):
279
+ """
280
+ Default device id (or name) to use for player transport methods that do not specify a device id and
281
+ there is no active player detected (e.g. "Office", "5d4931f9d0684b625d702eaa24137b2c1d99539c", etc).
282
+
283
+ Set this value to null to use the Spotify player active device.
284
+ """
285
+ return self._DefaultDeviceId
286
+
287
+ @DefaultDeviceId.setter
288
+ def DefaultDeviceId(self, value:str):
289
+ """
290
+ Sets the DefaultDeviceId property value.
291
+ """
292
+ if (value is None) or (isinstance(value,str)):
293
+ if value.strip() == '':
294
+ self._DefaultDeviceId = None
295
+ else:
296
+ self._DefaultDeviceId = value
297
+
298
+
276
299
  @property
277
300
  def Manager(self) -> PoolManager:
278
301
  """
@@ -968,6 +991,10 @@ class SpotifyClient:
968
991
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
969
992
  _logsi.LogMethodParmList(SILevel.Verbose, "Add item to playback queue", apiMethodParms)
970
993
 
994
+ # if deviceId was not specified, then verify that there is an active player device.
995
+ if deviceId is None:
996
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
997
+
971
998
  # check for device name; convert to an id if a name was supplied.
972
999
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
973
1000
 
@@ -5982,6 +6009,56 @@ class SpotifyClient:
5982
6009
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
5983
6010
 
5984
6011
 
6012
+ def VerifyPlayerActiveDeviceId(self) -> str:
6013
+ """
6014
+ Verifies that there is an active Spotify player device id, and returns the `DefaultDeviceId`
6015
+ value if there is not; otherwise, a null is returned to indicate that the currently active
6016
+ Spotify player will be used.
6017
+
6018
+ Note that if there is no active player and there was no `DefaultDeviceId` defined, then
6019
+ subsequent calls to the Spotify Web API player endpoints will probably fail with a
6020
+ "No Active Device" exception.
6021
+
6022
+ Returns:
6023
+ A device id or null value.
6024
+ """
6025
+ apiMethodName:str = 'VerifyPlayerActiveDeviceId'
6026
+
6027
+ try:
6028
+
6029
+ # trace.
6030
+ _logsi.EnterMethod(SILevel.Debug, apiMethodName)
6031
+ _logsi.LogVerbose("Verifying active Spotify player device id")
6032
+
6033
+ # get current playback state.
6034
+ playState:PlayerPlayState = self.GetPlayerPlaybackState()
6035
+
6036
+ # is there an active device?
6037
+ if (playState.Device.Id is None):
6038
+
6039
+ # no - use the `DefaultDeviceId` property value so the Spotify Web API can
6040
+ # re-activate it prior to playing.
6041
+ if self._DefaultDeviceId is not None:
6042
+ _logsi.LogVerbose("Active Spotify player device was not found - using DefaultDeviceId value: '%s'" % self._DefaultDeviceId)
6043
+ return self._DefaultDeviceId
6044
+
6045
+ # otherwise return null, which will use the active Spotify player device for
6046
+ # subsequent calls to the Spotify Web API player endpoints.
6047
+ return None
6048
+
6049
+ except SpotifyWebApiError: raise # pass handled exceptions on thru
6050
+ except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6051
+ except Exception as ex:
6052
+
6053
+ # format unhandled exception.
6054
+ raise SpotifyApiError(SAAppMessages.UNHANDLED_EXCEPTION.format(apiMethodName, str(ex)), ex, logsi=_logsi)
6055
+
6056
+ finally:
6057
+
6058
+ # trace.
6059
+ _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
6060
+
6061
+
5985
6062
  def GetPlayerDevice(self,
5986
6063
  deviceId:str,
5987
6064
  refresh:bool=True
@@ -10095,6 +10172,10 @@ class SpotifyClient:
10095
10172
  # validations.
10096
10173
  delay = validateDelay(delay, 0.50, 10)
10097
10174
 
10175
+ # if deviceId was not specified, then verify that there is an active player device.
10176
+ if deviceId is None:
10177
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10178
+
10098
10179
  # check for device name; convert to an id if a name was supplied.
10099
10180
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10100
10181
 
@@ -10617,6 +10698,10 @@ class SpotifyClient:
10617
10698
  # validations.
10618
10699
  delay = validateDelay(delay, 0.50, 10)
10619
10700
 
10701
+ # if deviceId was not specified, then verify that there is an active player device.
10702
+ if deviceId is None:
10703
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10704
+
10620
10705
  # check for device name; convert to an id if a name was supplied.
10621
10706
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10622
10707
 
@@ -10714,6 +10799,10 @@ class SpotifyClient:
10714
10799
  # validations.
10715
10800
  delay = validateDelay(delay, 0.50, 10)
10716
10801
 
10802
+ # if deviceId was not specified, then verify that there is an active player device.
10803
+ if deviceId is None:
10804
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10805
+
10717
10806
  # check for device name; convert to an id if a name was supplied.
10718
10807
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10719
10808
 
@@ -10806,6 +10895,10 @@ class SpotifyClient:
10806
10895
  # validations.
10807
10896
  delay = validateDelay(delay, 0.50, 10)
10808
10897
 
10898
+ # if deviceId was not specified, then verify that there is an active player device.
10899
+ if deviceId is None:
10900
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10901
+
10809
10902
  # check for device name; convert to an id if a name was supplied.
10810
10903
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10811
10904
 
@@ -10895,6 +10988,10 @@ class SpotifyClient:
10895
10988
  # validations.
10896
10989
  delay = validateDelay(delay, 0.50, 10)
10897
10990
 
10991
+ # if deviceId was not specified, then verify that there is an active player device.
10992
+ if deviceId is None:
10993
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10994
+
10898
10995
  # check for device name; convert to an id if a name was supplied.
10899
10996
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10900
10997
 
@@ -11106,6 +11203,10 @@ class SpotifyClient:
11106
11203
  # validations.
11107
11204
  delay = validateDelay(delay, 0.50, 10)
11108
11205
 
11206
+ # if deviceId was not specified, then verify that there is an active player device.
11207
+ if deviceId is None:
11208
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
11209
+
11109
11210
  # check for device name; convert to an id if a name was supplied.
11110
11211
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
11111
11212
 
@@ -11205,6 +11306,10 @@ class SpotifyClient:
11205
11306
  # validations.
11206
11307
  delay = validateDelay(delay, 0.50, 10)
11207
11308
 
11309
+ # if deviceId was not specified, then verify that there is an active player device.
11310
+ if deviceId is None:
11311
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
11312
+
11208
11313
  # check for device name; convert to an id if a name was supplied.
11209
11314
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
11210
11315
 
@@ -11303,6 +11408,10 @@ class SpotifyClient:
11303
11408
  # validations.
11304
11409
  delay = validateDelay(delay, 0.50, 10)
11305
11410
 
11411
+ # if deviceId was not specified, then verify that there is an active player device.
11412
+ if deviceId is None:
11413
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
11414
+
11306
11415
  # check for device name; convert to an id if a name was supplied.
11307
11416
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
11308
11417