spotifywebapiPython 1.0.77__py3-none-any.whl → 1.0.79__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.77.dist-info → spotifywebapiPython-1.0.79.dist-info}/METADATA +1 -1
  2. {spotifywebapiPython-1.0.77.dist-info → spotifywebapiPython-1.0.79.dist-info}/RECORD +22 -22
  3. spotifywebapipython/const.py +6 -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 +20 -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 +38 -2
  13. spotifywebapipython/docs/spotifywebapiPython/spotifyclient.html +9 -8
  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/spotifyauthtoken.py +26 -0
  18. spotifywebapipython/spotifyclient.py +8 -4
  19. spotifywebapipython/zeroconfapi/zeroconfconnect.py +66 -48
  20. {spotifywebapiPython-1.0.77.dist-info → spotifywebapiPython-1.0.79.dist-info}/LICENSE +0 -0
  21. {spotifywebapiPython-1.0.77.dist-info → spotifywebapiPython-1.0.79.dist-info}/WHEEL +0 -0
  22. {spotifywebapiPython-1.0.77.dist-info → spotifywebapiPython-1.0.79.dist-info}/top_level.txt +0 -0
@@ -20,6 +20,7 @@ from ..oauthcli.authclient import AuthClient
20
20
  from ..const import (
21
21
  SPOTIFY_API_AUTHORIZE_URL,
22
22
  SPOTIFY_API_TOKEN_URL,
23
+ SPOTIFY_DESKTOP_APP_CLIENT_ID,
23
24
  TRACE_METHOD_RESULT,
24
25
  TRACE_MSG_DELAY_DEVICE,
25
26
  )
@@ -58,7 +59,9 @@ class ZeroconfConnect:
58
59
  hostIpPort:int,
59
60
  cpath:str,
60
61
  version:str=None,
61
- useSSL:bool=False
62
+ useSSL:bool=False,
63
+ tokenStorageDir:str=None,
64
+ tokenAuthInBrowser:bool=False,
62
65
  ) -> None:
63
66
  """
64
67
  Initializes a new instance of the class.
@@ -79,6 +82,20 @@ class ZeroconfConnect:
79
82
  True if the host device utilizes HTTPS Secure Sockets Layer (SSL) support;
80
83
  otherwise, False to utilize HTTP.
81
84
  Default is False (HTTP).
85
+ tokenStorageDir (str):
86
+ The directory path that will contain the `tokens.json` cache file.
87
+ This is used for Spotify Connect devices that utilize the `authorization_code` token type.
88
+ A null value will default to the platform specific storage location:
89
+ Example for Windows OS = `C:\ProgramData\SpotifyWebApiPython`
90
+ tokenAuthInBrowser (bool):
91
+ True to allow authorization access token to be authorized if necessary via an
92
+ interactive browser; otherwise, False.
93
+ Default is False.
94
+
95
+ Set the `tokenAuthInBrowser` argument to False if your process does not allow user interaction
96
+ with the local default browser to approve authorization requests (e.g. if your process runs on
97
+ a server for instance). Set to True if you have a desktop / console application that allows
98
+ interactive access to the local default browser.
82
99
  """
83
100
  # validations.
84
101
  if (useSSL is None) or (not isinstance(useSSL,bool)):
@@ -90,6 +107,8 @@ class ZeroconfConnect:
90
107
  self._CPath:str = cpath
91
108
  self._HostIpPort:int = hostIpPort
92
109
  self._HostIpAddress:str = hostIpAddress
110
+ self._TokenStorageDir:str = tokenStorageDir
111
+ self._TokenAuthInBrowser:str = tokenAuthInBrowser
93
112
  self._UseSSL:bool = useSSL
94
113
  self._Version:str = version
95
114
 
@@ -123,6 +142,23 @@ class ZeroconfConnect:
123
142
  return self._HostIpPort
124
143
 
125
144
 
145
+ @property
146
+ def TokenAuthInBrowser(self) -> bool:
147
+ """
148
+ True to allow authorization access token to be authorized if necessary via an
149
+ interactive browser; otherwise, False.
150
+ """
151
+ return self._TokenAuthInBrowser
152
+
153
+
154
+ @property
155
+ def TokenStorageDir(self) -> str:
156
+ """
157
+ The directory path that will contain the authorization token cache file.
158
+ """
159
+ return self._TokenStorageDir
160
+
161
+
126
162
  @property
127
163
  def Uri(self) -> str:
128
164
  """
@@ -606,6 +642,7 @@ class ZeroconfConnect:
606
642
  apiMethodParms.AppendKeyValue("info.RemoteName", info.RemoteName)
607
643
  apiMethodParms.AppendKeyValue("info.BrandDisplayName", info.BrandDisplayName)
608
644
  apiMethodParms.AppendKeyValue("info.ModelDisplayName", info.ModelDisplayName)
645
+ apiMethodParms.AppendKeyValue("self.TokenAuthInBrowser", self.TokenAuthInBrowser)
609
646
  _logsi.LogMethodParmList(SILevel.Verbose, "Preparing to generate a new authorization_code access token for Spotify Connect device: '%s' (%s)" % (info.RemoteName, info.DeviceId), apiMethodParms)
610
647
 
611
648
  # set variables for spotify authorization_code token generation.
@@ -614,41 +651,12 @@ class ZeroconfConnect:
614
651
  redirectUriPort:str = 4381
615
652
  redirectUriPath:str = '/login'
616
653
  authorizationType:str = 'Authorization Code PKCE'
617
- tokenStorageDir:str = './test/testdata'
618
- tokenProfileId:str = 'SpotifyDesktopApp_Scopes_Streaming' # 'SpotifyDesktopApp_Scopes_Streaming', 'SpotifyDesktopApp_Scopes_All', 'SpotifyDesktopApp_Scopes_NoExtras'
619
- SPOTIFY_DESKTOP_APP_CLIENT_ID:str = '65b708073fc0480ea92a077233ca87bd' # Spotify Desktop App client id
654
+ tokenProfileId:str = 'SpotifyDesktopApp_Scopes_Streaming'
620
655
 
621
- # Spotify Desktop App scopes requested for Spotify Connect
656
+ # Spotify Desktop App scopes requested for Spotify Connect (streaming only as of 2024/08/13)
622
657
  SPOTIFY_SCOPES:list = \
623
658
  [
624
- # 'playlist-modify-private',
625
- # 'playlist-modify-public',
626
- # 'playlist-read-collaborative',
627
- # 'playlist-read-private',
628
- # 'ugc-image-upload',
629
- # 'user-follow-modify',
630
- # 'user-follow-read',
631
- # 'user-library-modify',
632
- # 'user-library-read',
633
- # 'user-modify-playback-state',
634
- # 'user-read-currently-playing',
635
- # 'user-read-email',
636
- # 'user-read-playback-position',
637
- # 'user-read-playback-state',
638
- # 'user-read-private',
639
- # 'user-read-recently-played',
640
- # 'user-top-read',
641
- # *** streaming scope
642
659
  'streaming',
643
- # *** extra scopes used by spotify desktop player
644
- # 'app-remote-control',
645
- # 'playlist-modify',
646
- # 'playlist-read',
647
- # 'user-modify',
648
- # 'user-modify-private',
649
- # 'user-personalized',
650
- # 'user-read-birthdate',
651
- # 'user-read-play-history',
652
660
  ]
653
661
 
654
662
  # create oauth provider for spotify authentication code with pkce.
@@ -659,31 +667,41 @@ class ZeroconfConnect:
659
667
  tokenUrl=SPOTIFY_API_TOKEN_URL,
660
668
  scope=SPOTIFY_SCOPES,
661
669
  clientId=SPOTIFY_DESKTOP_APP_CLIENT_ID,
662
- tokenStorageDir=tokenStorageDir,
670
+ tokenStorageDir=self.TokenStorageDir,
663
671
  tokenProviderId='SpotifyWebApiAuthCodePkce',
664
672
  tokenProfileId=tokenProfileId,
665
673
  )
666
674
 
667
- # force the user to logon to spotify to authorize the application access if we
668
- # do not have an authorized access token, or if the calling application requested
669
- # us (by force) to re-authorize, or if the scope has changed.
675
+ # raise an exception if the authorization token is not present, or the scope has changed.
676
+ # the user must create the authorization token outside of this process, as the Spotify
677
+ # authorization token is driven by responding to a web request for access using OAuth.
678
+ # as this process is running on a server, there is no way for the user to respond to the
679
+ # request (e.g. via browser nor command-line).
670
680
  isAuthorized = authClient.IsAuthorized
671
681
  _logsi.LogVerbose('Checking OAuth2 authorization status: IsAuthorized=%s' % isAuthorized)
672
682
 
673
683
  if (isAuthorized == False):
684
+
685
+ # can the user interact with a local default browser to authorize the request?
686
+ if self.TokenAuthInBrowser:
687
+
688
+ # at this point, we need a new authorization token.
689
+ # the user has up to 2 minutes to respond to the request by copying / pasting the
690
+ # message / auth approval url from the system log into a browser window that is
691
+ # running on the local machine.
692
+ _logsi.LogVerbose('Preparing to retrieve a new OAuth2 authorization access token')
693
+ authClient.AuthorizeWithServer(
694
+ host=redirectUriHost,
695
+ port=redirectUriPort,
696
+ redirect_uri_path=redirectUriPath,
697
+ open_browser=True,
698
+ timeout_seconds=120
699
+ )
674
700
 
675
- # at this point, we need a new authorization token.
676
- # the user has up to 2 minutes to respond to the request by copying / pasting the
677
- # message / auth approval url from the system log into a browser window that is
678
- # running on the local machine.
679
- _logsi.LogVerbose('Preparing to retrieve a new OAuth2 authorization access token')
680
- authClient.AuthorizeWithServer(
681
- host=redirectUriHost,
682
- port=redirectUriPort,
683
- redirect_uri_path=redirectUriPath,
684
- open_browser=False,
685
- timeout_seconds=120
686
- )
701
+ else:
702
+
703
+ # user cannot approve the request - raise an exception.
704
+ raise SpotifyZeroconfApiError(401, 'Spotify Desktop Client Application access token was not authorized', apiMethodName, 'Token Not Authorized', _logsi)
687
705
 
688
706
  else:
689
707