spotifywebapiPython 1.0.97__py3-none-any.whl → 1.0.99__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.97.dist-info → spotifywebapiPython-1.0.99.dist-info}/METADATA +1 -1
  2. {spotifywebapiPython-1.0.97.dist-info → spotifywebapiPython-1.0.99.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 +19 -2
  12. spotifywebapipython/docs/spotifywebapiPython/spotifyauthtoken.html +2 -2
  13. spotifywebapipython/docs/spotifywebapiPython/spotifyclient.html +134 -4
  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/playerplaystate.py +24 -0
  18. spotifywebapipython/spotifyapimessage.py +18 -1
  19. spotifywebapipython/spotifyclient.py +146 -7
  20. {spotifywebapiPython-1.0.97.dist-info → spotifywebapiPython-1.0.99.dist-info}/LICENSE +0 -0
  21. {spotifywebapiPython-1.0.97.dist-info → spotifywebapiPython-1.0.99.dist-info}/WHEEL +0 -0
  22. {spotifywebapiPython-1.0.97.dist-info → spotifywebapiPython-1.0.99.dist-info}/top_level.txt +0 -0
@@ -28,6 +28,7 @@ class PlayerPlayState:
28
28
  """
29
29
  self._Actions:PlayerActions = None
30
30
  self._Context:Context = None
31
+ self._ItemType:str = None
31
32
  self._CurrentlyPlayingType:str = None
32
33
  self._Device:Device = None
33
34
  self._Item:object = None
@@ -148,6 +149,27 @@ class PlayerPlayState:
148
149
  return self._Item
149
150
 
150
151
 
152
+ @property
153
+ def ItemType(self) -> str:
154
+ """
155
+ The type of the currently playing episode; can be null.
156
+ This value will be null if the `Item` property value is null.
157
+
158
+ If not null, it can be one of `audiobook` or `podcast`.
159
+
160
+ Note that this is not a Spotify Web API property; it is loaded from our API so
161
+ that the type of episode can be determined programatically (e.g. audiobook or podcast).
162
+ """
163
+ return self._ItemType
164
+
165
+ @ItemType.setter
166
+ def ItemType(self, value:str):
167
+ """
168
+ Sets the ItemType property value.
169
+ """
170
+ self._ItemType = value
171
+
172
+
151
173
  @property
152
174
  def IsAdvertisement(self) -> bool:
153
175
  """
@@ -330,6 +352,7 @@ class PlayerPlayState:
330
352
  'shuffle_state': self._ShuffleState,
331
353
  'smart_shuffle': self._SmartShuffle,
332
354
  'timestamp': self._Timestamp,
355
+ 'item_type': self._ItemType,
333
356
  'item': item,
334
357
  }
335
358
  return result
@@ -342,6 +365,7 @@ class PlayerPlayState:
342
365
  msg:str = 'PlayerPlayState:'
343
366
  #if self._Actions is not None: msg = '%s\n %s' % (msg, str(self._Actions))
344
367
  if self._CurrentlyPlayingType is not None: msg = '%s\n CurrentlyPlayingType="%s"' % (msg, str(self._CurrentlyPlayingType))
368
+ if self._ItemType is not None: msg = '%s\n ItemType="%s"' % (msg, str(self._ItemType))
345
369
  if self._Device is not None: msg = '%s\n Device Name="%s"' % (msg, str(self._Device.Name))
346
370
  #if self._Context is not None: msg = '%s\n %s' % (msg, str(self._Context))
347
371
  #if self._Item is not None: msg = '%s\n %s' % (msg, str(self._Item))
@@ -42,6 +42,7 @@ class SpotifyApiMessage:
42
42
  self._RequestHeaders:Mapping[str, str] = requestHeaders
43
43
  self._RequestJson:dict = None
44
44
  self._ResponseData = {}
45
+ self._IgnoreResponseErrors:bool = False
45
46
  self._IsRequestDataEncoded:bool = False
46
47
  self._Uri:str = uri
47
48
  self._UrlParameters:dict = urlParameters
@@ -99,6 +100,22 @@ class SpotifyApiMessage:
99
100
  return self._RequestData is not None
100
101
 
101
102
 
103
+ @property
104
+ def IgnoreResponseErrors(self) -> bool:
105
+ """
106
+ Indicates if request response errors are ignored (True) or not (False, default).
107
+ If not, an exception will be thrown with the error details.
108
+ """
109
+ return self._IgnoreResponseErrors
110
+
111
+ @IgnoreResponseErrors.setter
112
+ def IgnoreResponseErrors(self, value:bool):
113
+ """
114
+ Sets the IgnoreResponseErrors property value.
115
+ """
116
+ self._IgnoreResponseErrors = value
117
+
118
+
102
119
  @property
103
120
  def IsRequestDataEncoded(self) -> bool:
104
121
  """
@@ -109,7 +126,7 @@ class SpotifyApiMessage:
109
126
  @IsRequestDataEncoded.setter
110
127
  def IsRequestDataEncoded(self, value:bool):
111
128
  """
112
- Sets the MethodName property value.
129
+ Sets the IsRequestDataEncoded property value.
113
130
  """
114
131
  self._IsRequestDataEncoded = value
115
132
 
@@ -607,7 +607,8 @@ class SpotifyClient:
607
607
  if errCode is None:
608
608
  errCode = response.status
609
609
 
610
- raise SpotifyWebApiError(errCode, errMessage, msg.MethodName, response.reason, _logsi)
610
+ if (not msg.IgnoreResponseErrors):
611
+ raise SpotifyWebApiError(errCode, errMessage, msg.MethodName, response.reason, _logsi)
611
612
 
612
613
  elif isinstance(errObj, str):
613
614
 
@@ -5216,6 +5217,7 @@ class SpotifyClient:
5216
5217
  def GetChapter(self,
5217
5218
  chapterId:str,
5218
5219
  market:str=None,
5220
+ ignoreResponseErrors:bool=False,
5219
5221
  ) -> Chapter:
5220
5222
  """
5221
5223
  Get Spotify catalog information for a single audiobook chapter identified by its unique Spotify ID.
@@ -5234,6 +5236,9 @@ class SpotifyClient:
5234
5236
  Note: If neither market or user country are provided, the content is considered unavailable for the client.
5235
5237
  Users can view the country that is associated with their account in the account settings.
5236
5238
  Example: `ES`
5239
+ ignoreResponseErrors (bool):
5240
+ True to ignore any request response errors that occur; otherwise, an exception will be thrown
5241
+ if a response error is detected (default).
5237
5242
 
5238
5243
  Returns:
5239
5244
  An `Chapter` object that contain the chapter details.
@@ -5267,6 +5272,7 @@ class SpotifyClient:
5267
5272
  apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
5268
5273
  apiMethodParms.AppendKeyValue("chapterId", chapterId)
5269
5274
  apiMethodParms.AppendKeyValue("market", market)
5275
+ apiMethodParms.AppendKeyValue("ignoreResponseErrors", ignoreResponseErrors)
5270
5276
  _logsi.LogMethodParmList(SILevel.Verbose, "Get Spotify catalog information for a single audiobook chapter", apiMethodParms)
5271
5277
 
5272
5278
  # ensure market was either supplied or implied; default if neither.
@@ -5281,6 +5287,7 @@ class SpotifyClient:
5281
5287
  msg:SpotifyApiMessage = SpotifyApiMessage(apiMethodName, '/chapters/{id}'.format(id=chapterId))
5282
5288
  msg.RequestHeaders[self.AuthToken.HeaderKey] = self.AuthToken.HeaderValue
5283
5289
  msg.UrlParameters = urlParms
5290
+ msg.IgnoreResponseErrors = ignoreResponseErrors
5284
5291
  self.MakeRequest('GET', msg)
5285
5292
 
5286
5293
  # process results.
@@ -6760,6 +6767,17 @@ class SpotifyClient:
6760
6767
 
6761
6768
  # process results.
6762
6769
  result = PlayerPlayState(root=msg.ResponseData)
6770
+
6771
+ # is this an episode? if so, then determine the item type (e.g. podcast or audiobook).
6772
+ if (result is not None):
6773
+ if (result.Item is not None):
6774
+ result.ItemType = SpotifyClient.GetTypeFromUri(result.Item.Uri)
6775
+ if (result.CurrentlyPlayingType == 'episode'):
6776
+ uriId:str = SpotifyClient.GetIdFromUri(result.Item.Uri)
6777
+ if (self.IsChapterEpisode(uriId)):
6778
+ result.ItemType = 'audiobook'
6779
+ else:
6780
+ result.ItemType = 'podcast'
6763
6781
 
6764
6782
  # trace.
6765
6783
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
@@ -6833,11 +6851,28 @@ class SpotifyClient:
6833
6851
  return result
6834
6852
 
6835
6853
 
6836
- def GetPlayerNowPlayingAudiobookUri(self) -> str:
6854
+ def GetPlayerNowPlayingAudiobookUri(
6855
+ self,
6856
+ market:str=None,
6857
+ ignoreResponseErrors:bool=False,
6858
+ ) -> str:
6837
6859
  """
6838
6860
  Returns the audiobook uri value of the currently playing media if something is
6839
6861
  playing; otherwise, null is returned.
6840
6862
 
6863
+ Args:
6864
+ market (str):
6865
+ An ISO 3166-1 alpha-2 country code. If a country code is specified, only content that
6866
+ is available in that market will be returned. If a valid user access token is specified
6867
+ in the request header, the country associated with the user account will take priority over
6868
+ this parameter.
6869
+ Note: If neither market or user country are provided, the content is considered unavailable for the client.
6870
+ Users can view the country that is associated with their account in the account settings.
6871
+ Example: `ES`
6872
+ ignoreResponseErrors (bool):
6873
+ True to ignore any request response errors that occur; otherwise, an exception will be thrown
6874
+ if a response error is detected (default).
6875
+
6841
6876
  Raises:
6842
6877
  SpotifyApiError:
6843
6878
  If current user does not have a Spotify free or premium level account.
@@ -6846,17 +6881,19 @@ class SpotifyClient:
6846
6881
  result:str = None
6847
6882
 
6848
6883
  # get nowplaying status.
6849
- nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying(additionalTypes='episode')
6884
+ nowPlaying:PlayerPlayState = self.GetPlayerNowPlaying(market, additionalTypes='episode')
6850
6885
 
6851
6886
  # is an chapter playing? if so, return the parent show uri value.
6852
6887
  if nowPlaying is not None:
6853
6888
  if nowPlaying.CurrentlyPlayingType in ['episode']:
6854
6889
  playingItem:Chapter = nowPlaying.Item
6855
6890
  if (playingItem is not None):
6856
- chapter:Chapter = self.GetChapter(playingItem.Id)
6857
- result = chapter.Audiobook.Uri
6891
+ chapter:Chapter = self.GetChapter(playingItem.Id, market, ignoreResponseErrors)
6892
+ if (chapter.Audiobook is not None):
6893
+ result = chapter.Audiobook.Uri
6858
6894
  else:
6859
- raise SpotifyApiError("Currently playing item is not a Audiobook Chapter", logsi=_logsi)
6895
+ if (not ignoreResponseErrors):
6896
+ raise SpotifyApiError("Currently playing item is not a Audiobook Chapter", logsi=_logsi)
6860
6897
 
6861
6898
  return result
6862
6899
 
@@ -7035,7 +7072,18 @@ class SpotifyClient:
7035
7072
 
7036
7073
  # process results.
7037
7074
  result = PlayerPlayState(root=msg.ResponseData)
7038
-
7075
+
7076
+ # is this an episode? if so, then determine the item type (e.g. podcast or audiobook).
7077
+ if (result is not None):
7078
+ if (result.Item is not None):
7079
+ result.ItemType = SpotifyClient.GetTypeFromUri(result.Item.Uri)
7080
+ if (result.CurrentlyPlayingType == 'episode'):
7081
+ uriId:str = SpotifyClient.GetIdFromUri(result.Item.Uri)
7082
+ if (self.IsChapterEpisode(uriId)):
7083
+ result.ItemType = 'audiobook'
7084
+ else:
7085
+ result.ItemType = 'podcast'
7086
+
7039
7087
  # check for a restricted device; if found, then grab the device id from the
7040
7088
  # cached list of spotify connect devices (if present).
7041
7089
  if result is not None:
@@ -10523,6 +10571,97 @@ class SpotifyClient:
10523
10571
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
10524
10572
 
10525
10573
 
10574
+ def IsChapterEpisode(
10575
+ self,
10576
+ episodeId:str=None,
10577
+ market:str=None,
10578
+ ) -> bool:
10579
+ """
10580
+ Returns true if the specified episode id is an audiobook chapter; otherwise, false.
10581
+
10582
+ Args:
10583
+ episodeId (str):
10584
+ The Spotify ID to check.
10585
+ Example: `74aydHJKgYz3AIq3jjBSv1`
10586
+ If null, the currently playing uri id value is used; a Spotify Free or Premium account
10587
+ is required to correctly read the currently playing context.
10588
+ market (str):
10589
+ An ISO 3166-1 alpha-2 country code. If a country code is specified, only content that
10590
+ is available in that market will be returned. If a valid user access token is specified
10591
+ in the request header, the country associated with the user account will take priority over
10592
+ this parameter.
10593
+ Note: If neither market or user country are provided, the content is considered unavailable for the client.
10594
+ Users can view the country that is associated with their account in the account settings.
10595
+ Example: `ES`
10596
+
10597
+ Returns:
10598
+ True if the specified id is an audiobook chapter; otherwise, false.
10599
+
10600
+ Raises:
10601
+ SpotifyWebApiError:
10602
+ If the Spotify Web API request was for a non-authorization service
10603
+ and the response contains error information.
10604
+ SpotifApiError:
10605
+ If the method fails for any other reason.
10606
+
10607
+ <details>
10608
+ <summary>Sample Code</summary>
10609
+ ```python
10610
+ .. include:: ../docs/include/samplecode/SpotifyClient/IsChapterEpisode.py
10611
+ ```
10612
+ <summary>Sample Code - NowPlaying</summary>
10613
+ ```python
10614
+ .. include:: ../docs/include/samplecode/SpotifyClient/IsChapterEpisode_NowPlaying.py
10615
+ ```
10616
+ </details>
10617
+ """
10618
+ apiMethodName:str = 'IsChapterEpisode'
10619
+ apiMethodParms:SIMethodParmListContext = None
10620
+ result:bool = False
10621
+
10622
+ try:
10623
+
10624
+ # trace.
10625
+ apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
10626
+ apiMethodParms.AppendKeyValue("episodeId", episodeId)
10627
+ apiMethodParms.AppendKeyValue("market", market)
10628
+ _logsi.LogMethodParmList(SILevel.Verbose, "Check if episode id is an audiobook chapter or not", apiMethodParms)
10629
+
10630
+ # ensure market was either supplied or implied; default if neither.
10631
+ market = self._ValidateMarket(market)
10632
+
10633
+ # if id not specified, then return currently playing id value.
10634
+ # this will issue a GetChapter call to retrieve the actual audiobook id.
10635
+ # the `GetPlayerNowPlayingAudiobookUri` method will fail if it's not a chapter id.
10636
+ if (episodeId is None) or (len(episodeId.strip()) == 0):
10637
+
10638
+ uri = self.GetPlayerNowPlayingAudiobookUri(market, True)
10639
+ result = (uri is not None)
10640
+
10641
+ else:
10642
+
10643
+ # if id was supplied, then call the `GetChapter` method to retrieve chapter information.
10644
+ # the `GetChapter` method will fail if it's not a chapter id.
10645
+ chapter:Chapter = self.GetChapter(episodeId, market, True)
10646
+ result = (chapter.Id is not None)
10647
+
10648
+ return result
10649
+
10650
+ except Exception as ex:
10651
+
10652
+ # at this point we can safely assume it's NOT an audiobook chapter.
10653
+ result = False
10654
+ return result
10655
+
10656
+ finally:
10657
+
10658
+ # trace.
10659
+ _logsi.LogValue(SILevel.Verbose, TRACE_METHOD_RESULT % (apiMethodName), result)
10660
+
10661
+ # trace.
10662
+ _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
10663
+
10664
+
10526
10665
  @staticmethod
10527
10666
  def IsDeviceId(value:str) -> bool:
10528
10667
  """