spotifywebapiPython 1.0.71__py3-none-any.whl → 1.0.73__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 (25) hide show
  1. {spotifywebapiPython-1.0.71.dist-info → spotifywebapiPython-1.0.73.dist-info}/METADATA +1 -1
  2. {spotifywebapiPython-1.0.71.dist-info → spotifywebapiPython-1.0.73.dist-info}/RECORD +25 -25
  3. spotifywebapipython/const.py +1 -1
  4. spotifywebapipython/docs/__init__.html +16 -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 +8 -2
  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/zeroconfdiscoveryresult.py +13 -0
  18. spotifywebapipython/spotifyclient.py +64 -19
  19. spotifywebapipython/zeroconfapi/blobbuilder.py +327 -66
  20. spotifywebapipython/zeroconfapi/cryptodiffiehellman.py +71 -6
  21. spotifywebapipython/zeroconfapi/helpers.py +34 -7
  22. spotifywebapipython/zeroconfapi/zeroconfconnect.py +50 -6
  23. {spotifywebapiPython-1.0.71.dist-info → spotifywebapiPython-1.0.73.dist-info}/LICENSE +0 -0
  24. {spotifywebapiPython-1.0.71.dist-info → spotifywebapiPython-1.0.73.dist-info}/WHEEL +0 -0
  25. {spotifywebapiPython-1.0.71.dist-info → spotifywebapiPython-1.0.73.dist-info}/top_level.txt +0 -0
@@ -340,6 +340,8 @@ class ZeroconfConnect:
340
340
  includeOriginDeviceInfo:bool = False
341
341
  if (info.PublicKey == 'SU5WQUxJRA==') and (info.Availability == 'NOT-LOADED'):
342
342
  includeOriginDeviceInfo = True
343
+ elif info.TokenType == 'authorization_code':
344
+ includeOriginDeviceInfo = True
343
345
 
344
346
  # execute the Spotify Zeroconf API addUser request.
345
347
  responseData:dict = self._ConnectAddUser(
@@ -460,6 +462,8 @@ class ZeroconfConnect:
460
462
  apiMethodParms.AppendKeyValue("includeOriginDeviceInfo", includeOriginDeviceInfo)
461
463
  apiMethodParms.AppendKeyValue("info.Availability", info.Availability)
462
464
  apiMethodParms.AppendKeyValue("info.PublicKey", info.PublicKey)
465
+ apiMethodParms.AppendKeyValue("info.DeviceId", info.DeviceId)
466
+ apiMethodParms.AppendKeyValue("info.RemoteName", info.RemoteName)
463
467
  _logsi.LogMethodParmList(SILevel.Verbose, "Issuing Spotify Connect Zeroconf addUser request (ip=%s)" % self._HostIpAddress, apiMethodParms)
464
468
 
465
469
  # validations.
@@ -481,14 +485,29 @@ class ZeroconfConnect:
481
485
  }
482
486
  _logsi.LogDictionary(SILevel.Debug, "ZeroconfConnect http request: '%s' (headers)" % (endpoint), reqHeaders)
483
487
 
488
+ # set tokenType based on getInfo token type.
489
+ # if TokenType is 'athorization_code', then use it as-is;
490
+ # if TokenType is 'accesstoken', then use `default`.
491
+ # otherwise, use 'default'.
492
+ tokenType:str = 'default'
493
+ if info.TokenType == 'authorization_code':
494
+ tokenType = info.TokenType
495
+
496
+ # set clientKey based on getInfo token type.
497
+ # if TokenType is 'athorization_code', then clientKey should be null.
498
+ # otherwise, clientKey should be the PublicKey (base64 encoded).
499
+ clientKey:str = builder.dh_keys.PublicKeyBase64String
500
+ if info.TokenType == 'authorization_code':
501
+ clientKey = ''
502
+
484
503
  # set request parameters.
485
504
  reqData={
486
505
  'action': 'addUser',
487
- 'version': self.Version,
488
- 'tokenType': 'default', # NOTE - not the same as info.TokenType!
506
+ 'version': info.Version,
507
+ 'tokenType': tokenType,
508
+ 'clientKey': clientKey,
489
509
  'loginId': loginId or '', # canonical login id (e.g. "31l77fd87g8h9j00k89f07jf87ge")
490
510
  'userName': credentials.username.decode('ascii'), # user name (e.g. "youremail@mail.com")
491
- 'clientKey': int_to_b64str(builder.dh_keys.public_key),
492
511
  'blob': blob,
493
512
  }
494
513
 
@@ -624,9 +643,31 @@ class ZeroconfConnect:
624
643
  # trace.
625
644
  _logsi.LogObject(SILevel.Verbose, '%s result (%s)' % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
626
645
 
627
- # if result status is not ok, then raise an exception.
646
+ # was a status value returned?
647
+ # it's been found that some devices (Sonos, etc) do not return a proper JSON response.
648
+ # for these cases, we will rely on the http status code for the response code.
649
+ if (result.Status is None):
650
+
651
+ # was a good http status code returned?
652
+ if response.status_code == 200:
653
+ # yes - default status results if they are not set.
654
+ result.Status = 101
655
+ if result.StatusString is None:
656
+ result.StatusString = "OK"
657
+ if result.SpotifyError is None:
658
+ result.SpotifyError = 0
659
+
660
+ # are we processing result status?
628
661
  if (not ignoreStatusResult):
629
- if (result.Status != 101):
662
+
663
+ if (result.Status is None) and (response.status_code != 200):
664
+ # if status value was not returned and http status is not 200, then
665
+ # raise an exception with http status details.
666
+ raise SpotifyZeroconfApiError(response.status_code, responseData, apiMethodName, response.reason, _logsi)
667
+
668
+ elif (result.Status != 101):
669
+ # if status was returned and it's not ok, then raise an exception
670
+ # with JSON response details.
630
671
  raise SpotifyZeroconfApiError(result.Status, result.ToString(), apiMethodName, result.StatusString, _logsi)
631
672
 
632
673
  # give spotify zeroconf api time to process the change.
@@ -705,6 +746,9 @@ class ZeroconfConnect:
705
746
  Raises:
706
747
  SpotifyWebApiError:
707
748
  If the Spotify Zeroconf API request response contains error information.
749
+
750
+ The request will timeout after 5 seconds and an exception raised if the device cannot be reached
751
+ or does not respond within that time frame.
708
752
 
709
753
  <details>
710
754
  <summary>Sample Code</summary>
@@ -749,7 +793,7 @@ class ZeroconfConnect:
749
793
  # execute spotify zeroconf api request.
750
794
  response = requests.get(
751
795
  self._Uri,
752
- timeout=10,
796
+ timeout=5,
753
797
  headers=reqHeaders,
754
798
  params=reqParams
755
799
  )