spotifywebapiPython 1.0.53__py3-none-any.whl → 1.0.55__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 (22) hide show
  1. {spotifywebapiPython-1.0.53.dist-info → spotifywebapiPython-1.0.55.dist-info}/METADATA +1 -1
  2. {spotifywebapiPython-1.0.53.dist-info → spotifywebapiPython-1.0.55.dist-info}/RECORD +22 -22
  3. spotifywebapipython/const.py +1 -1
  4. spotifywebapipython/docs/__init__.html +14 -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 +2 -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 +25 -3
  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/spotifyconnectdevices.py +28 -0
  18. spotifywebapipython/spotifyclient.py +62 -35
  19. spotifywebapipython/zeroconfapi/zeroconfconnect.py +6 -3
  20. {spotifywebapiPython-1.0.53.dist-info → spotifywebapiPython-1.0.55.dist-info}/LICENSE +0 -0
  21. {spotifywebapiPython-1.0.53.dist-info → spotifywebapiPython-1.0.55.dist-info}/WHEEL +0 -0
  22. {spotifywebapiPython-1.0.53.dist-info → spotifywebapiPython-1.0.55.dist-info}/top_level.txt +0 -0
@@ -6027,7 +6027,7 @@ class SpotifyClient:
6027
6027
 
6028
6028
  # does our Spotify Connect user account need to take control of the device?
6029
6029
  # if not, then we are done.
6030
- elif (deviceActiveUser == self._SpotifyConnectUsername.lower()): # or (deviceActiveUser == self.UserProfile.Id.lower()):
6030
+ elif (deviceActiveUser == self._SpotifyConnectUsername.lower()) or (deviceActiveUser == self.UserProfile.Id.lower()):
6031
6031
  _logsi.LogVerbose("Spotify Connect user context '%s' was verified for Device id '%s'; switch not necessary" % (deviceActiveUser, deviceIdResult))
6032
6032
  status = status + "user context switch not needed"
6033
6033
 
@@ -7877,10 +7877,18 @@ class SpotifyClient:
7877
7877
 
7878
7878
  def GetSpotifyConnectDevices(
7879
7879
  self,
7880
+ refresh:bool=True
7880
7881
  ) -> SpotifyConnectDevices:
7881
7882
  """
7882
7883
  Get information about all available Spotify Connect player devices.
7883
7884
 
7885
+ This method requires the `user-read-playback-state` scope.
7886
+
7887
+ Args:
7888
+ refresh (bool):
7889
+ True (default) to return real-time information from the spotify zeroconf api and
7890
+ update the cache; otherwise, False to just return the cached value.
7891
+
7884
7892
  Returns:
7885
7893
  A `SpotifyConnectDevices` object that contain the discovery results
7886
7894
  as well as the `getInfo` result for each found device.
@@ -7903,6 +7911,10 @@ class SpotifyClient:
7903
7911
  process, but still exist in the player device list. These are usually Spotify Connect
7904
7912
  web or mobile players with temporary device id's.
7905
7913
 
7914
+ The `ConfigurationCache` is updated with the results of this method. Use the
7915
+ `refresh` argument (with False value) to retrieve the cached value and avoid
7916
+ the spotify web api request. This results in better performance.
7917
+
7906
7918
  <details>
7907
7919
  <summary>Sample Code</summary>
7908
7920
  ```python
@@ -7912,50 +7924,65 @@ class SpotifyClient:
7912
7924
  """
7913
7925
  apiMethodName:str = 'GetSpotifyConnectDevices'
7914
7926
  result:SpotifyConnectDevices = SpotifyConnectDevices()
7927
+ cacheDesc:str = CACHE_SOURCE_CURRENT
7915
7928
 
7916
7929
  try:
7917
7930
 
7918
7931
  # trace.
7919
7932
  _logsi.EnterMethod(SILevel.Debug, apiMethodName)
7920
7933
 
7921
- # discover Spotify Connect devices on the network, waiting up to the specified timeout
7922
- # for all devices to be discovered. this will return all Spotify Connect devices that
7923
- # are currently powered on, and are registered to Zeroconf / mDNS.
7924
- _logsi.LogVerbose("Discovering Spotify Connect devices on the local network")
7925
- discovery:SpotifyDiscovery = SpotifyDiscovery(self._ZeroconfClient, printToConsole=False)
7926
- discovery.DiscoverDevices(timeout=self._SpotifyConnectDiscoveryTimeout)
7934
+ # can we use the cached value?
7935
+ if (not refresh) and (apiMethodName in self._ConfigurationCache):
7936
+
7937
+ result = self._ConfigurationCache[apiMethodName]
7938
+ cacheDesc = CACHE_SOURCE_CACHED
7939
+
7940
+ else:
7941
+
7942
+ # discover Spotify Connect devices on the network, waiting up to the specified timeout
7943
+ # for all devices to be discovered. this will return all Spotify Connect devices that
7944
+ # are currently powered on, and are registered to Zeroconf / mDNS.
7945
+ _logsi.LogVerbose("Discovering Spotify Connect devices on the local network")
7946
+ discovery:SpotifyDiscovery = SpotifyDiscovery(self._ZeroconfClient, printToConsole=False)
7947
+ discovery.DiscoverDevices(timeout=self._SpotifyConnectDiscoveryTimeout)
7927
7948
 
7928
- # process all discovered devices.
7929
- discoverResult:ZeroconfDiscoveryResult
7930
- for discoverResult in discovery.DiscoveryResults:
7931
-
7932
- # get the id from the device via the zeroconf API getInfo endpoint, as the id is not
7933
- # returned in the zeroconf discovery result.
7934
- zconn:ZeroconfConnect = ZeroconfConnect(discoverResult.HostIpv4Address,
7935
- discoverResult.HostIpPort,
7936
- discoverResult.SpotifyConnectCPath,
7937
- useSSL=False)
7938
- info:ZeroconfGetInfo = zconn.GetInformation()
7939
-
7940
- # create new spotify connect device object.
7941
- scDevice:SpotifyConnectDevice = SpotifyConnectDevice()
7942
- scDevice.DiscoveryResult = discoverResult
7943
- scDevice.DeviceInfo = info
7944
- result.Items.append(scDevice)
7945
-
7946
- # we will also call the GetPlayerDevices method, in case we have any dynamic devices.
7947
- # dynamic devices are Spotify Connect devices that are not found in Zeroconf discovery
7948
- # process, but still exist in the player device list. these are usually Spotify Connect
7949
- # web or mobile players with temporary device id's.
7950
- devices:list[Device] = self.GetPlayerDevices(True)
7949
+ # process all discovered devices.
7950
+ discoverResult:ZeroconfDiscoveryResult
7951
+ for discoverResult in discovery.DiscoveryResults:
7952
+
7953
+ # get the id from the device via the zeroconf API getInfo endpoint, as the id is not
7954
+ # returned in the zeroconf discovery result.
7955
+ zconn:ZeroconfConnect = ZeroconfConnect(discoverResult.HostIpv4Address,
7956
+ discoverResult.HostIpPort,
7957
+ discoverResult.SpotifyConnectCPath,
7958
+ useSSL=False)
7959
+ info:ZeroconfGetInfo = zconn.GetInformation()
7960
+
7961
+ # create new spotify connect device object.
7962
+ scDevice:SpotifyConnectDevice = SpotifyConnectDevice()
7963
+ scDevice.DiscoveryResult = discoverResult
7964
+ scDevice.DeviceInfo = info
7965
+ result.Items.append(scDevice)
7966
+
7967
+ # we will also call the GetPlayerDevices method, in case we have any dynamic devices.
7968
+ # dynamic devices are Spotify Connect devices that are not found in Zeroconf discovery
7969
+ # process, but still exist in the player device list. these are usually Spotify Connect
7970
+ # web or mobile players with temporary device id's.
7971
+ devices:list[Device] = self.GetPlayerDevices(True)
7951
7972
 
7952
- device:Device
7953
- for device in devices:
7954
- if not result.ContainsDeviceId(device.Id):
7955
- result.AddDynamicDevice(device, self.UserProfile.Id)
7973
+ device:Device
7974
+ for device in devices:
7975
+ if not result.ContainsDeviceId(device.Id):
7976
+ result.AddDynamicDevice(device, self.UserProfile.Id)
7956
7977
 
7978
+ # update cache.
7979
+ self._ConfigurationCache[apiMethodName] = result
7980
+
7981
+ # update last refresh date.
7982
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
7983
+
7957
7984
  # trace.
7958
- _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result)
7985
+ _logsi.LogArray(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE_CACHED % (apiMethodName, type(result).__name__, cacheDesc), result)
7959
7986
  return result
7960
7987
 
7961
7988
  except SpotifyZeroconfApiError: raise # pass handled exceptions on thru
@@ -354,7 +354,8 @@ class ZeroconfConnect:
354
354
  self._Uri,
355
355
  timeout=10,
356
356
  headers={
357
- 'Content-Type': 'application/x-www-form-urlencoded'
357
+ 'Content-Type': 'application/x-www-form-urlencoded',
358
+ 'Connection': 'close'
358
359
  },
359
360
  data={
360
361
  'action': 'addUser',
@@ -455,7 +456,8 @@ class ZeroconfConnect:
455
456
  self._Uri,
456
457
  timeout=10,
457
458
  headers={
458
- 'Content-Type': 'application/x-www-form-urlencoded'
459
+ 'Content-Type': 'application/x-www-form-urlencoded',
460
+ 'Connection': 'close'
459
461
  },
460
462
  data={
461
463
  'action': 'resetUsers',
@@ -556,7 +558,8 @@ class ZeroconfConnect:
556
558
  self._Uri,
557
559
  timeout=10,
558
560
  headers={
559
- 'Content-Type': 'application/x-www-form-urlencoded'
561
+ 'Content-Type': 'application/x-www-form-urlencoded',
562
+ 'Connection': 'close'
560
563
  },
561
564
  params={
562
565
  'action': 'getInfo',