spotifywebapiPython 1.0.86__py3-none-any.whl → 1.0.88__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,33 @@ 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):
293
+
294
+ self._DefaultDeviceId = value
295
+
296
+ elif (isinstance(value,str)):
297
+
298
+ if value.strip() == '':
299
+ self._DefaultDeviceId = None
300
+ else:
301
+ self._DefaultDeviceId = value
302
+
303
+
276
304
  @property
277
305
  def Manager(self) -> PoolManager:
278
306
  """
@@ -968,6 +996,10 @@ class SpotifyClient:
968
996
  apiMethodParms.AppendKeyValue("deviceId", deviceId)
969
997
  _logsi.LogMethodParmList(SILevel.Verbose, "Add item to playback queue", apiMethodParms)
970
998
 
999
+ # if deviceId was not specified, then verify that there is an active player device.
1000
+ if deviceId is None:
1001
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
1002
+
971
1003
  # check for device name; convert to an id if a name was supplied.
972
1004
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
973
1005
 
@@ -5982,6 +6014,56 @@ class SpotifyClient:
5982
6014
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
5983
6015
 
5984
6016
 
6017
+ def VerifyPlayerActiveDeviceId(self) -> str:
6018
+ """
6019
+ Verifies that there is an active Spotify player device id, and returns the `DefaultDeviceId`
6020
+ value if there is not; otherwise, a null is returned to indicate that the currently active
6021
+ Spotify player will be used.
6022
+
6023
+ Note that if there is no active player and there was no `DefaultDeviceId` defined, then
6024
+ subsequent calls to the Spotify Web API player endpoints will probably fail with a
6025
+ "No Active Device" exception.
6026
+
6027
+ Returns:
6028
+ A device id or null value.
6029
+ """
6030
+ apiMethodName:str = 'VerifyPlayerActiveDeviceId'
6031
+
6032
+ try:
6033
+
6034
+ # trace.
6035
+ _logsi.EnterMethod(SILevel.Debug, apiMethodName)
6036
+ _logsi.LogVerbose("Verifying active Spotify player device id")
6037
+
6038
+ # get current playback state.
6039
+ playState:PlayerPlayState = self.GetPlayerPlaybackState()
6040
+
6041
+ # is there an active device?
6042
+ if (playState.Device.Id is None):
6043
+
6044
+ # no - use the `DefaultDeviceId` property value so the Spotify Web API can
6045
+ # re-activate it prior to playing.
6046
+ if self._DefaultDeviceId is not None:
6047
+ _logsi.LogVerbose("Active Spotify player device was not found - using DefaultDeviceId value: '%s'" % self._DefaultDeviceId)
6048
+ return self._DefaultDeviceId
6049
+
6050
+ # otherwise return null, which will use the active Spotify player device for
6051
+ # subsequent calls to the Spotify Web API player endpoints.
6052
+ return None
6053
+
6054
+ except SpotifyWebApiError: raise # pass handled exceptions on thru
6055
+ except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
6056
+ except Exception as ex:
6057
+
6058
+ # format unhandled exception.
6059
+ raise SpotifyApiError(SAAppMessages.UNHANDLED_EXCEPTION.format(apiMethodName, str(ex)), ex, logsi=_logsi)
6060
+
6061
+ finally:
6062
+
6063
+ # trace.
6064
+ _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
6065
+
6066
+
5985
6067
  def GetPlayerDevice(self,
5986
6068
  deviceId:str,
5987
6069
  refresh:bool=True
@@ -10095,6 +10177,10 @@ class SpotifyClient:
10095
10177
  # validations.
10096
10178
  delay = validateDelay(delay, 0.50, 10)
10097
10179
 
10180
+ # if deviceId was not specified, then verify that there is an active player device.
10181
+ if deviceId is None:
10182
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10183
+
10098
10184
  # check for device name; convert to an id if a name was supplied.
10099
10185
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10100
10186
 
@@ -10617,6 +10703,10 @@ class SpotifyClient:
10617
10703
  # validations.
10618
10704
  delay = validateDelay(delay, 0.50, 10)
10619
10705
 
10706
+ # if deviceId was not specified, then verify that there is an active player device.
10707
+ if deviceId is None:
10708
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10709
+
10620
10710
  # check for device name; convert to an id if a name was supplied.
10621
10711
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10622
10712
 
@@ -10714,6 +10804,10 @@ class SpotifyClient:
10714
10804
  # validations.
10715
10805
  delay = validateDelay(delay, 0.50, 10)
10716
10806
 
10807
+ # if deviceId was not specified, then verify that there is an active player device.
10808
+ if deviceId is None:
10809
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10810
+
10717
10811
  # check for device name; convert to an id if a name was supplied.
10718
10812
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10719
10813
 
@@ -10806,6 +10900,10 @@ class SpotifyClient:
10806
10900
  # validations.
10807
10901
  delay = validateDelay(delay, 0.50, 10)
10808
10902
 
10903
+ # if deviceId was not specified, then verify that there is an active player device.
10904
+ if deviceId is None:
10905
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10906
+
10809
10907
  # check for device name; convert to an id if a name was supplied.
10810
10908
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10811
10909
 
@@ -10895,6 +10993,10 @@ class SpotifyClient:
10895
10993
  # validations.
10896
10994
  delay = validateDelay(delay, 0.50, 10)
10897
10995
 
10996
+ # if deviceId was not specified, then verify that there is an active player device.
10997
+ if deviceId is None:
10998
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
10999
+
10898
11000
  # check for device name; convert to an id if a name was supplied.
10899
11001
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
10900
11002
 
@@ -11106,6 +11208,10 @@ class SpotifyClient:
11106
11208
  # validations.
11107
11209
  delay = validateDelay(delay, 0.50, 10)
11108
11210
 
11211
+ # if deviceId was not specified, then verify that there is an active player device.
11212
+ if deviceId is None:
11213
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
11214
+
11109
11215
  # check for device name; convert to an id if a name was supplied.
11110
11216
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
11111
11217
 
@@ -11205,6 +11311,10 @@ class SpotifyClient:
11205
11311
  # validations.
11206
11312
  delay = validateDelay(delay, 0.50, 10)
11207
11313
 
11314
+ # if deviceId was not specified, then verify that there is an active player device.
11315
+ if deviceId is None:
11316
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
11317
+
11208
11318
  # check for device name; convert to an id if a name was supplied.
11209
11319
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
11210
11320
 
@@ -11303,6 +11413,10 @@ class SpotifyClient:
11303
11413
  # validations.
11304
11414
  delay = validateDelay(delay, 0.50, 10)
11305
11415
 
11416
+ # if deviceId was not specified, then verify that there is an active player device.
11417
+ if deviceId is None:
11418
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
11419
+
11306
11420
  # check for device name; convert to an id if a name was supplied.
11307
11421
  deviceId = self.PlayerConvertDeviceNameToId(deviceId)
11308
11422