spotifywebapiPython 1.0.112__py3-none-any.whl → 1.0.113__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 (23) hide show
  1. {spotifywebapiPython-1.0.112.dist-info → spotifywebapiPython-1.0.113.dist-info}/METADATA +1 -1
  2. {spotifywebapiPython-1.0.112.dist-info → spotifywebapiPython-1.0.113.dist-info}/RECORD +23 -23
  3. spotifywebapipython/const.py +1 -1
  4. spotifywebapipython/docs/__init__.html +11 -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 +62 -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/pageobject.py +28 -0
  18. spotifywebapipython/models/playerqueueinfo.py +34 -4
  19. spotifywebapipython/models/trackpage.py +40 -0
  20. spotifywebapipython/spotifyclient.py +183 -9
  21. {spotifywebapiPython-1.0.112.dist-info → spotifywebapiPython-1.0.113.dist-info}/LICENSE +0 -0
  22. {spotifywebapiPython-1.0.112.dist-info → spotifywebapiPython-1.0.113.dist-info}/WHEEL +0 -0
  23. {spotifywebapiPython-1.0.112.dist-info → spotifywebapiPython-1.0.113.dist-info}/top_level.txt +0 -0
@@ -58,6 +58,46 @@ class TrackPage(PageObject):
58
58
  return self._Items
59
59
 
60
60
 
61
+ def GetUris(self, afterUri:str=None) -> str:
62
+ """
63
+ Gets a comma-delimited list of uri's contained in the underlying `Items` list.
64
+
65
+ args:
66
+ afterUri (str):
67
+ If specified, the process will look for this uri before adding subsequent
68
+ uri's to the returned results. This allows you to skip uri's that have
69
+ recently been played.
70
+
71
+ This is a convenience method so one does not have to loop through the `Items`
72
+ array of PlayHistory objects to get the list of uri's.
73
+ """
74
+ result:str = ""
75
+ addUri:bool = False
76
+ item:Track
77
+
78
+ # add uri's from the beginning if no `afterUri` argument was passed.
79
+ if (afterUri is None) or (len(afterUri.strip()) == 0):
80
+ addUri = True
81
+
82
+ for item in self._Items:
83
+
84
+ if (not addUri):
85
+
86
+ # check for `afterUri` match; if found, we will start adding uri's
87
+ # to the list with the next item.
88
+ if (afterUri == item.Uri):
89
+ addUri = True
90
+
91
+ elif (addUri):
92
+
93
+ # add item uri to the list.
94
+ if (len(result) > 0):
95
+ result += ","
96
+ result += item.Uri
97
+
98
+ return result
99
+
100
+
61
101
  def ToString(self, includeItems:bool=False) -> str:
62
102
  """
63
103
  Returns a displayable string representation of the class.
@@ -839,6 +839,8 @@ class SpotifyClient:
839
839
  deviceId:str=None
840
840
  ) -> None:
841
841
  """
842
+ DEPRECATED - use `AddPlayerQueueItems` method instead.
843
+
842
844
  Add an item to the end of the user's current playback queue.
843
845
 
844
846
  This method requires the `user-modify-playback-state` scope.
@@ -863,13 +865,6 @@ class SpotifyClient:
863
865
  This API only works for users who have Spotify Premium.
864
866
 
865
867
  The order of execution is not guaranteed when you use this API with other Player API endpoints.
866
-
867
- <details>
868
- <summary>Sample Code</summary>
869
- ```python
870
- .. include:: ../docs/include/samplecode/SpotifyClient/AddPlayerQueueItem.py
871
- ```
872
- </details>
873
868
  """
874
869
  apiMethodName:str = 'AddPlayerQueueItem'
875
870
  apiMethodParms:SIMethodParmListContext = None
@@ -921,6 +916,139 @@ class SpotifyClient:
921
916
  _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
922
917
 
923
918
 
919
+ def AddPlayerQueueItems(
920
+ self,
921
+ uris:str,
922
+ deviceId:str=None,
923
+ verifyDeviceId:bool=True,
924
+ delay:float=0.15,
925
+ ) -> None:
926
+ """
927
+ Add one or more items to the end of the user's current playback queue.
928
+
929
+ This method requires the `user-modify-playback-state` scope.
930
+
931
+ Args:
932
+ uris (str):
933
+ A list of Spotify track or episode URIs to add to the queue; can be track or episode URIs.
934
+ All URIs must be of the same type - you cannot mix and match tracks and episodes!
935
+ Example: [`spotify:track:6zd8T1PBe9JFHmuVnurdRp` ,`spotify:track:1kWUud3vY5ij5r62zxpTRy`].
936
+ It can also be specified as a comma-delimited string.
937
+ Example: `spotify:track:6zd8T1PBe9JFHmuVnurdRp,spotify:track:1kWUud3vY5ij5r62zxpTRy`.
938
+ A maximum of 50 items can be added in one request.
939
+ deviceId (str):
940
+ The id or name of the device this command is targeting.
941
+ If not supplied, the user's currently active device is the target.
942
+ Example: `0d1841b0976bae2a3a310dd74c0f3df354899bc8`
943
+ Example: `Web Player (Chrome)`
944
+ verifyDeviceId (bool):
945
+ True to verify a device id is active; otherwise, false to assume that a
946
+ device id is already active.
947
+ Default is True.
948
+ delay (float):
949
+ Time delay (in seconds) to wait AFTER issuing the add request. This delay will give the
950
+ Spotify web api time to process the queue change before another command is issued.
951
+ Default is 0.15; value range is 0 - 10.
952
+
953
+ Raises:
954
+ SpotifyWebApiError:
955
+ If the Spotify Web API request was for a non-authorization service
956
+ and the response contains error information.
957
+ SpotifApiError:
958
+ If the method fails for any other reason.
959
+
960
+ This API only works for users who have Spotify Premium.
961
+
962
+ The order of execution is not guaranteed when you use this API with other Player API endpoints.
963
+
964
+ The Spotify Web API endpoint is called to add each item individually.
965
+ The Spotify Web API does not currently support adding more than 1 item to the queue at a time.
966
+
967
+ <details>
968
+ <summary>Sample Code</summary>
969
+ ```python
970
+ .. include:: ../docs/include/samplecode/SpotifyClient/AddPlayerQueueItems.py
971
+ ```
972
+ </details>
973
+ """
974
+ apiMethodName:str = 'AddPlayerQueueItems'
975
+ apiMethodParms:SIMethodParmListContext = None
976
+
977
+ try:
978
+
979
+ # trace.
980
+ apiMethodParms = _logsi.EnterMethodParmList(SILevel.Debug, apiMethodName)
981
+ apiMethodParms.AppendKeyValue("uris", uris)
982
+ apiMethodParms.AppendKeyValue("deviceId", deviceId)
983
+ apiMethodParms.AppendKeyValue("verifyDeviceId", verifyDeviceId)
984
+ apiMethodParms.AppendKeyValue("delay", delay)
985
+ _logsi.LogMethodParmList(SILevel.Verbose, "Add items to playback queue", apiMethodParms)
986
+
987
+ # validations.
988
+ delay = validateDelay(delay, 0.15, 10)
989
+ if (verifyDeviceId is None):
990
+ verifyDeviceId = True
991
+
992
+ # build a list of all item uri's.
993
+ # remove any leading / trailing spaces in case user put a space between the items.
994
+ arrUris:list[str] = None
995
+ if isinstance(uris, list):
996
+ arrUris = uris
997
+ else:
998
+ arrUris = uris.split(',')
999
+ for idx in range(0, len(arrUris)):
1000
+ arrUris[idx] = arrUris[idx].strip()
1001
+
1002
+ # if deviceId was not specified, then verify that there is an active player device.
1003
+ if verifyDeviceId:
1004
+ if deviceId is None:
1005
+ deviceId:str = self.VerifyPlayerActiveDeviceId()
1006
+
1007
+ # check for device name; convert to an id if a name was supplied.
1008
+ if verifyDeviceId:
1009
+ deviceId = self.PlayerConvertDeviceNameToId(deviceId)
1010
+
1011
+ # process all uri's.
1012
+ for idx in range(0, len(arrUris)):
1013
+
1014
+ # build spotify web api request parameters.
1015
+ urlParms:dict = \
1016
+ {
1017
+ 'uri': arrUris[idx]
1018
+ }
1019
+ if deviceId is not None:
1020
+ urlParms['device_id'] = deviceId
1021
+
1022
+ # execute spotify web api request.
1023
+ msg:SpotifyApiMessage = SpotifyApiMessage(apiMethodName, '/me/player/queue')
1024
+ msg.RequestHeaders[self.AuthToken.HeaderKey] = self.AuthToken.HeaderValue
1025
+ msg.UrlParameters = urlParms
1026
+ self.MakeRequest('POST', msg)
1027
+
1028
+ # give spotify web api time to process the change.
1029
+ if delay > 0:
1030
+ _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
1031
+ time.sleep(delay)
1032
+
1033
+
1034
+ # process results.
1035
+ # no results to process - this is pass or fail.
1036
+ return
1037
+
1038
+ except SpotifyApiError: raise # pass handled exceptions on thru
1039
+ except SpotifyWebApiError: raise # pass handled exceptions on thru
1040
+ except SpotifyWebApiAuthenticationError: raise # pass handled exceptions on thru
1041
+ except Exception as ex:
1042
+
1043
+ # format unhandled exception.
1044
+ raise SpotifyApiError(SAAppMessages.UNHANDLED_EXCEPTION.format(apiMethodName, str(ex)), ex, logsi=_logsi)
1045
+
1046
+ finally:
1047
+
1048
+ # trace.
1049
+ _logsi.LeaveMethod(SILevel.Debug, apiMethodName)
1050
+
1051
+
924
1052
  def AddPlaylistCoverImage(self,
925
1053
  playlistId:str,
926
1054
  imagePath:str
@@ -2728,7 +2856,8 @@ class SpotifyClient:
2728
2856
 
2729
2857
  # update result object with final paging details.
2730
2858
  result.Total = pageObj.Total
2731
-
2859
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
2860
+
2732
2861
  # sort result items.
2733
2862
  if (len(result.Items) > 0):
2734
2863
  if (sortResult is True):
@@ -2895,6 +3024,7 @@ class SpotifyClient:
2895
3024
 
2896
3025
  # update result object with final paging details.
2897
3026
  result.Total = pageObj.Total
3027
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
2898
3028
 
2899
3029
  # sort result items.
2900
3030
  if (len(result.Items) > 0):
@@ -3162,6 +3292,7 @@ class SpotifyClient:
3162
3292
 
3163
3293
  # update result object with final paging details.
3164
3294
  result.Total = pageObj.Total
3295
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
3165
3296
 
3166
3297
  # do not sort items, as they are in playable order.
3167
3298
 
@@ -3429,6 +3560,7 @@ class SpotifyClient:
3429
3560
 
3430
3561
  # update result object with final paging details.
3431
3562
  result.Total = pageObj.Total
3563
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
3432
3564
 
3433
3565
  # sort result items.
3434
3566
  if (len(result.Items) > 0):
@@ -4021,6 +4153,7 @@ class SpotifyClient:
4021
4153
  # update result object with final paging details.
4022
4154
  result.Total = pageObj.Total
4023
4155
  result.CursorAfter = pageObj.CursorAfter
4156
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
4024
4157
 
4025
4158
  # sort result items.
4026
4159
  if (len(result.Items) > 0):
@@ -4401,6 +4534,7 @@ class SpotifyClient:
4401
4534
 
4402
4535
  # update result object with final paging details.
4403
4536
  result.Total = pageObj.Total
4537
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
4404
4538
 
4405
4539
  # no sorting, as chapters are in playable order.
4406
4540
 
@@ -4553,6 +4687,7 @@ class SpotifyClient:
4553
4687
 
4554
4688
  # update result object with final paging details.
4555
4689
  result.Total = pageObj.Total
4690
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
4556
4691
 
4557
4692
  # sort result items.
4558
4693
  if (len(result.Items) > 0):
@@ -4946,6 +5081,7 @@ class SpotifyClient:
4946
5081
 
4947
5082
  # update result object with final paging details.
4948
5083
  result.Total = pageObj.Total
5084
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
4949
5085
 
4950
5086
  # sort result items.
4951
5087
  if (len(result.Items) > 0):
@@ -5231,6 +5367,7 @@ class SpotifyClient:
5231
5367
 
5232
5368
  # update result object with final paging details.
5233
5369
  result.Total = pageObj.Total
5370
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
5234
5371
 
5235
5372
  # sort result items.
5236
5373
  if (len(result.Items) > 0):
@@ -5692,6 +5829,7 @@ class SpotifyClient:
5692
5829
 
5693
5830
  # update result object with final paging details.
5694
5831
  result.Total = pageObj.Total
5832
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
5695
5833
 
5696
5834
  # sort result items.
5697
5835
  if (len(result.Items) > 0):
@@ -5984,6 +6122,7 @@ class SpotifyClient:
5984
6122
 
5985
6123
  # update result object with final paging details.
5986
6124
  result.Total = pageObj.Total
6125
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
5987
6126
 
5988
6127
  # sort result items.
5989
6128
  if (len(result.Items) > 0):
@@ -7391,6 +7530,7 @@ class SpotifyClient:
7391
7530
  result.Total = result.ItemsCount
7392
7531
  result.CursorAfter = pageObj.CursorAfter
7393
7532
  result.CursorBefore = pageObj.CursorBefore
7533
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
7394
7534
 
7395
7535
  # trace.
7396
7536
  _logsi.LogObject(SILevel.Verbose, TRACE_METHOD_RESULT_TYPE % (apiMethodName, type(result).__name__), result, excludeNonPublic=True)
@@ -7814,6 +7954,7 @@ class SpotifyClient:
7814
7954
 
7815
7955
  # update result object with final paging details.
7816
7956
  result.Total = pageObj.Total
7957
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
7817
7958
 
7818
7959
  # do not sort this list, as it is in play order.
7819
7960
 
@@ -7966,6 +8107,7 @@ class SpotifyClient:
7966
8107
 
7967
8108
  # update result object with final paging details.
7968
8109
  result.Total = pageObj.Total
8110
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
7969
8111
 
7970
8112
  # sort result items.
7971
8113
  if (len(result.Items) > 0):
@@ -8127,6 +8269,7 @@ class SpotifyClient:
8127
8269
 
8128
8270
  # update result object with final paging details.
8129
8271
  result.Total = pageObj.Total
8272
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
8130
8273
 
8131
8274
  # sort result items.
8132
8275
  if (len(result.Items) > 0):
@@ -8407,6 +8550,7 @@ class SpotifyClient:
8407
8550
 
8408
8551
  # update result object with final paging details.
8409
8552
  result.Total = pageObj.Total
8553
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
8410
8554
 
8411
8555
  # no sort, as items are in playable order.
8412
8556
 
@@ -8586,6 +8730,7 @@ class SpotifyClient:
8586
8730
 
8587
8731
  # update result object with final paging details.
8588
8732
  result.Total = pageObj.Total
8733
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
8589
8734
 
8590
8735
  # sort result items.
8591
8736
  if (len(result.Items) > 0):
@@ -9562,6 +9707,7 @@ class SpotifyClient:
9562
9707
 
9563
9708
  # update result object with final paging details.
9564
9709
  result.Total = pageObj.Total
9710
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
9565
9711
 
9566
9712
  # sort result items.
9567
9713
  if (len(result.Items) > 0):
@@ -10490,6 +10636,7 @@ class SpotifyClient:
10490
10636
 
10491
10637
  # update result object with final paging details.
10492
10638
  result.Total = pageObj.Total
10639
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
10493
10640
 
10494
10641
  # sort result items.
10495
10642
  if (len(result.Items) > 0):
@@ -10656,6 +10803,7 @@ class SpotifyClient:
10656
10803
 
10657
10804
  # update result object with final paging details.
10658
10805
  result.Total = pageObj.Total
10806
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
10659
10807
 
10660
10808
  # sort result items.
10661
10809
  if (len(result.Items) > 0):
@@ -11284,6 +11432,25 @@ class SpotifyClient:
11284
11432
  # if so, then use the found device id in case a device name was specified.
11285
11433
  if scDevice is not None:
11286
11434
  deviceId = scDevice.Id
11435
+
11436
+ # left this here in case we want to implement it in the future.
11437
+
11438
+ # # are we backfilling the player queue? if so, we can only have 50 uris total.
11439
+ # if (backfillUrisPageOffset > -1) and (len(arrUris) < 50):
11440
+
11441
+ # # are we playing tracks?
11442
+ # if (len(arrUris) > 0) and (SpotifyClient.GetTypeFromUri(arrUris[0]) == 'track'):
11443
+
11444
+ # _logsi.LogVerbose("Backfilling player queue items from users top tracks")
11445
+
11446
+ # # get list of users top tracks (50 max items).
11447
+ # pageObj:TrackPage = self.GetUsersTopTracks(timeRange='medium_term', offset=backfillUrisPageOffset, limit=(50 - len(arrUris)), sortResult=False)
11448
+
11449
+ # # add them to the player queue; no need to validate the device id, since we
11450
+ # # know there is an active device id by this point.
11451
+ # item:Track
11452
+ # for item in pageObj.Items:
11453
+ # arrUris.append(item.Uri)
11287
11454
 
11288
11455
  # build spotify web api request parameters.
11289
11456
  reqData:dict = \
@@ -11308,7 +11475,7 @@ class SpotifyClient:
11308
11475
  if delay > 0:
11309
11476
  _logsi.LogVerbose(TRACE_MSG_DELAY_DEVICE % delay)
11310
11477
  time.sleep(delay)
11311
-
11478
+
11312
11479
  # process results.
11313
11480
  # no results to process - this is pass or fail.
11314
11481
  return
@@ -14029,6 +14196,7 @@ class SpotifyClient:
14029
14196
 
14030
14197
  # update result object with final paging details.
14031
14198
  result.Total = pageObj.Total
14199
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
14032
14200
 
14033
14201
  # do not sort, as spotify uses intelligent AI to return results in its order.
14034
14202
 
@@ -14221,6 +14389,7 @@ class SpotifyClient:
14221
14389
 
14222
14390
  # update result object with final paging details.
14223
14391
  result.Total = pageObj.Total
14392
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
14224
14393
 
14225
14394
  # do not sort, as spotify uses intelligent AI to return results in its order.
14226
14395
 
@@ -14415,6 +14584,7 @@ class SpotifyClient:
14415
14584
 
14416
14585
  # update result object with final paging details.
14417
14586
  result.Total = pageObj.Total
14587
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
14418
14588
 
14419
14589
  # do not sort, as spotify uses intelligent AI to return results in its order.
14420
14590
 
@@ -14607,6 +14777,7 @@ class SpotifyClient:
14607
14777
 
14608
14778
  # update result object with final paging details.
14609
14779
  result.Total = pageObj.Total
14780
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
14610
14781
 
14611
14782
  # do not sort, as spotify uses intelligent AI to return results in its order.
14612
14783
 
@@ -14799,6 +14970,7 @@ class SpotifyClient:
14799
14970
 
14800
14971
  # update result object with final paging details.
14801
14972
  result.Total = pageObj.Total
14973
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
14802
14974
 
14803
14975
  # do not sort, as spotify uses intelligent AI to return results in its order.
14804
14976
 
@@ -14991,6 +15163,7 @@ class SpotifyClient:
14991
15163
 
14992
15164
  # update result object with final paging details.
14993
15165
  result.Total = pageObj.Total
15166
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
14994
15167
 
14995
15168
  # do not sort, as spotify uses intelligent AI to return results in its order.
14996
15169
 
@@ -15183,6 +15356,7 @@ class SpotifyClient:
15183
15356
 
15184
15357
  # update result object with final paging details.
15185
15358
  result.Total = pageObj.Total
15359
+ result.DateLastRefreshed = datetime.utcnow().timestamp()
15186
15360
 
15187
15361
  # do not sort, as spotify uses intelligent AI to return results in its order.
15188
15362