spotifywebapiPython 1.0.155__py3-none-any.whl → 1.0.156__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.155.dist-info → spotifywebapiPython-1.0.156.dist-info}/METADATA +1 -1
  2. {spotifywebapiPython-1.0.155.dist-info → spotifywebapiPython-1.0.156.dist-info}/RECORD +22 -22
  3. spotifywebapipython/const.py +1 -1
  4. spotifywebapipython/docs/__init__.html +8 -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 +2 -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/docs/spotifywebapipython/spotifywebplayertoken.html +2 -2
  18. spotifywebapipython/spotifyclient.py +94 -19
  19. spotifywebapipython/spotifyconnect/__init__.py +2 -2
  20. {spotifywebapiPython-1.0.155.dist-info → spotifywebapiPython-1.0.156.dist-info}/LICENSE +0 -0
  21. {spotifywebapiPython-1.0.155.dist-info → spotifywebapiPython-1.0.156.dist-info}/WHEEL +0 -0
  22. {spotifywebapiPython-1.0.155.dist-info → spotifywebapiPython-1.0.156.dist-info}/top_level.txt +0 -0
@@ -24,7 +24,7 @@ from zeroconf import Zeroconf
24
24
  from .oauthcli import AuthClient
25
25
  from .models import *
26
26
  from .models import UserProfile as UserProfileCurrentUser
27
- from .spotifyconnect import SpotifyConnectDirectoryTask
27
+ from .spotifyconnect import SpotifyConnectDirectoryTask, SpotifyConnectDeviceNotFound
28
28
  from .saappmessages import SAAppMessages
29
29
  from .spotifyapierror import SpotifyApiError
30
30
  from .spotifyapimessage import SpotifyApiMessage
@@ -473,6 +473,25 @@ class SpotifyClient:
473
473
  return self._ZeroconfClient
474
474
 
475
475
 
476
+ def _CheckForDeviceNotFound(
477
+ self,
478
+ scDevice:SpotifyConnectDevice,
479
+ deviceId:str,
480
+ ) -> None:
481
+ """
482
+ Called to raise a SpotifyConnectDeviceNotFound exception when a Spotify Connect
483
+ device could not be found and there is no active player.
484
+ """
485
+ # was a device resolved?
486
+ if (scDevice is None):
487
+
488
+ # if deviceId could not be resolved, then it's an error.
489
+ if (deviceId is None) or (deviceId == "*"):
490
+ raise SpotifyConnectDeviceNotFound("There is no active Spotify player, and a default player device was not configured; select a player device and try again.")
491
+ else:
492
+ raise SpotifyConnectDeviceNotFound("Spotify Player device \"%s\" was not found, and there is no active Spotify player; verify the device is active and available on the local network, and try again." % (deviceId))
493
+
494
+
476
495
  def _CheckForNextPageWithOffset(
477
496
  self,
478
497
  pageObj:PageObject,
@@ -1231,10 +1250,11 @@ class SpotifyClient:
1231
1250
  for idx in range(0, len(arrUris)):
1232
1251
  arrUris[idx] = arrUris[idx].strip()
1233
1252
 
1234
- # resolve / activate the device object if needed.
1253
+ # resolve the device object from the device id.
1235
1254
  scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, False)
1236
1255
 
1237
- # is this a Sonos device?
1256
+ # is this an active Sonos device?
1257
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
1238
1258
  if (scDevice is not None) and (scDevice.IsSonos):
1239
1259
 
1240
1260
  # trace.
@@ -1257,6 +1277,10 @@ class SpotifyClient:
1257
1277
  # trace.
1258
1278
  _logsi.LogVerbose("Items will be added to playback queue for device: %s" % (scDevice.Title))
1259
1279
 
1280
+ # was the deviceId resolved?
1281
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
1282
+ self._CheckForDeviceNotFound(scDevice, deviceId)
1283
+
1260
1284
  # process all uri's.
1261
1285
  for idx in range(0, len(arrUris)):
1262
1286
 
@@ -11569,10 +11593,11 @@ class SpotifyClient:
11569
11593
  # validations.
11570
11594
  delay = validateDelay(delay, 0.50, 10)
11571
11595
 
11572
- # resolve / activate the device object if needed.
11596
+ # resolve the device object from the device id.
11573
11597
  scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, False)
11574
11598
 
11575
11599
  # is this an active Sonos device?
11600
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
11576
11601
  if (scDevice is not None) and (scDevice.IsSonos):
11577
11602
 
11578
11603
  _logsi.LogVerbose("Issuing command to Sonos device %s: PAUSE" % (scDevice.Title))
@@ -11581,6 +11606,10 @@ class SpotifyClient:
11581
11606
 
11582
11607
  else:
11583
11608
 
11609
+ # was the deviceId resolved?
11610
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
11611
+ self._CheckForDeviceNotFound(scDevice, deviceId)
11612
+
11584
11613
  # build spotify web api request parameters.
11585
11614
  urlParms:dict = {}
11586
11615
  if (scDevice is not None):
@@ -11728,10 +11757,11 @@ class SpotifyClient:
11728
11757
  if (offsetPosition is None) or (offsetPosition < 0):
11729
11758
  offsetPosition = 0
11730
11759
 
11731
- # resolve / activate the device object if needed.
11732
- scDevice = self._ResolveDeviceObject(deviceId, False)
11760
+ # resolve the device object from the device idl activate if it's dormant.
11761
+ scDevice = self._ResolveDeviceObject(deviceId, True)
11733
11762
 
11734
- # is this a Sonos device?
11763
+ # is this an active Sonos device?
11764
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
11735
11765
  if (scDevice is not None) and (scDevice.IsSonos):
11736
11766
 
11737
11767
  # trace.
@@ -11808,6 +11838,10 @@ class SpotifyClient:
11808
11838
  # trace.
11809
11839
  _logsi.LogVerbose("Context will be played on the Spotify Connect device via Spotify Web API")
11810
11840
 
11841
+ # was the deviceId resolved?
11842
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
11843
+ self._CheckForDeviceNotFound(scDevice, deviceId)
11844
+
11811
11845
  # build spotify web api request parameters.
11812
11846
  reqData:dict = \
11813
11847
  {
@@ -11950,7 +11984,7 @@ class SpotifyClient:
11950
11984
  for trackSaved in tracks.Items:
11951
11985
  arrUris.append(trackSaved.Track.Uri)
11952
11986
 
11953
- # resolve / activate the device object if needed.
11987
+ # resolve the device object from the device id.
11954
11988
  scDevice = self._ResolveDeviceObject(deviceId, False)
11955
11989
 
11956
11990
  # set desired shuffle mode.
@@ -12073,10 +12107,11 @@ class SpotifyClient:
12073
12107
  for idx in range(0, len(arrUris)):
12074
12108
  arrUris[idx] = arrUris[idx].strip()
12075
12109
 
12076
- # resolve / activate the device object if needed.
12110
+ # resolve the device object from the device id; activate if it's dormant.
12077
12111
  scDevice = self._ResolveDeviceObject(deviceId, True)
12078
12112
 
12079
- # is this a Sonos device?
12113
+ # is this an active Sonos device?
12114
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
12080
12115
  if (scDevice is not None) and (scDevice.IsSonos):
12081
12116
 
12082
12117
  # trace.
@@ -12129,6 +12164,10 @@ class SpotifyClient:
12129
12164
  # trace.
12130
12165
  _logsi.LogVerbose("Track list will be played on the Spotify Connect device via Spotify Web API")
12131
12166
 
12167
+ # was the deviceId resolved?
12168
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
12169
+ self._CheckForDeviceNotFound(scDevice, deviceId)
12170
+
12132
12171
  # build spotify web api request parameters.
12133
12172
  reqData:dict = \
12134
12173
  {
@@ -12228,10 +12267,12 @@ class SpotifyClient:
12228
12267
  # validations.
12229
12268
  delay = validateDelay(delay, 0.50, 10)
12230
12269
 
12231
- # resolve / activate the device object if needed.
12232
- scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, False)
12270
+ # resolve the device object from the device id; activate if it's dormant.
12271
+ # we activate the device here, as it may have been paused for a long time.
12272
+ scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, True)
12233
12273
 
12234
12274
  # is this an active Sonos device?
12275
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
12235
12276
  if (scDevice is not None) and (scDevice.IsSonos):
12236
12277
 
12237
12278
  _logsi.LogVerbose("Issuing command to Sonos device %s: PLAY (RESUME)" % (scDevice.Title))
@@ -12240,6 +12281,10 @@ class SpotifyClient:
12240
12281
 
12241
12282
  else:
12242
12283
 
12284
+ # was the deviceId resolved?
12285
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
12286
+ self._CheckForDeviceNotFound(scDevice, deviceId)
12287
+
12243
12288
  # build spotify web api request parameters.
12244
12289
  urlParms:dict = {}
12245
12290
  if (scDevice is not None):
@@ -12366,7 +12411,7 @@ class SpotifyClient:
12366
12411
  if (relativePositionMS is None):
12367
12412
  relativePositionMS = 0
12368
12413
 
12369
- # resolve / activate the device object if needed.
12414
+ # resolve the device object from the device id.
12370
12415
  scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, False)
12371
12416
 
12372
12417
  # was relative seeking specified?
@@ -12384,6 +12429,7 @@ class SpotifyClient:
12384
12429
  positionMS = newPositionMS
12385
12430
 
12386
12431
  # is this an active Sonos device?
12432
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
12387
12433
  if (scDevice is not None) and (scDevice.IsSonos):
12388
12434
 
12389
12435
  sonosPosition:str = mediaPositionHMS_fromSeconds(positionMS / 1000) # convert from milliseconds to Sonos H:MM:SS format
@@ -12393,6 +12439,10 @@ class SpotifyClient:
12393
12439
 
12394
12440
  else:
12395
12441
 
12442
+ # was the deviceId resolved?
12443
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
12444
+ self._CheckForDeviceNotFound(scDevice, deviceId)
12445
+
12396
12446
  # build spotify web api request parameters.
12397
12447
  urlParms:dict = \
12398
12448
  {
@@ -12487,10 +12537,11 @@ class SpotifyClient:
12487
12537
  # validations.
12488
12538
  delay = validateDelay(delay, 0.50, 10)
12489
12539
 
12490
- # resolve / activate the device object if needed.
12540
+ # resolve the device object from the device id.
12491
12541
  scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, False)
12492
12542
 
12493
12543
  # is this an active Sonos device?
12544
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
12494
12545
  if (scDevice is not None) and (scDevice.IsSonos):
12495
12546
 
12496
12547
  _logsi.LogVerbose("Issuing command to Sonos device %s: NEXT" % (scDevice.Title))
@@ -12499,6 +12550,10 @@ class SpotifyClient:
12499
12550
 
12500
12551
  else:
12501
12552
 
12553
+ # was the deviceId resolved?
12554
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
12555
+ self._CheckForDeviceNotFound(scDevice, deviceId)
12556
+
12502
12557
  # build spotify web api request parameters.
12503
12558
  urlParms:dict = {}
12504
12559
  if (scDevice is not None):
@@ -12590,10 +12645,11 @@ class SpotifyClient:
12590
12645
  # validations.
12591
12646
  delay = validateDelay(delay, 0.50, 10)
12592
12647
 
12593
- # resolve / activate the device object if needed.
12648
+ # resolve the device object from the device id.
12594
12649
  scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, False)
12595
12650
 
12596
12651
  # is this an active Sonos device?
12652
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
12597
12653
  if (scDevice is not None) and (scDevice.IsSonos):
12598
12654
 
12599
12655
  _logsi.LogVerbose("Issuing command to Sonos device %s: PREVIOUS" % (scDevice.Title))
@@ -12602,6 +12658,10 @@ class SpotifyClient:
12602
12658
 
12603
12659
  else:
12604
12660
 
12661
+ # was the deviceId resolved?
12662
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
12663
+ self._CheckForDeviceNotFound(scDevice, deviceId)
12664
+
12605
12665
  # build spotify web api request parameters.
12606
12666
  urlParms:dict = {}
12607
12667
  if (scDevice is not None):
@@ -12701,10 +12761,11 @@ class SpotifyClient:
12701
12761
  # validations.
12702
12762
  delay = validateDelay(delay, 0.50, 10)
12703
12763
 
12704
- # resolve / activate the device object if needed.
12764
+ # resolve the device object from the device id.
12705
12765
  scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, False)
12706
12766
 
12707
12767
  # is this an active Sonos device?
12768
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
12708
12769
  if (scDevice is not None) and (scDevice.IsSonos):
12709
12770
 
12710
12771
  # get current Spotify Connect player state.
@@ -12730,6 +12791,10 @@ class SpotifyClient:
12730
12791
 
12731
12792
  else:
12732
12793
 
12794
+ # was the deviceId resolved?
12795
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
12796
+ self._CheckForDeviceNotFound(scDevice, deviceId)
12797
+
12733
12798
  # build spotify web api request parameters.
12734
12799
  urlParms:dict = \
12735
12800
  {
@@ -12831,10 +12896,11 @@ class SpotifyClient:
12831
12896
  # validations.
12832
12897
  delay = validateDelay(delay, 0.50, 10)
12833
12898
 
12834
- # resolve / activate the device object if needed.
12899
+ # resolve the device object from the device id.
12835
12900
  scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, False)
12836
12901
 
12837
12902
  # is this an active Sonos device?
12903
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
12838
12904
  if (scDevice is not None) and (scDevice.IsSonos):
12839
12905
 
12840
12906
  # get current Spotify Connect player state.
@@ -12861,6 +12927,10 @@ class SpotifyClient:
12861
12927
 
12862
12928
  else:
12863
12929
 
12930
+ # was the deviceId resolved?
12931
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
12932
+ self._CheckForDeviceNotFound(scDevice, deviceId)
12933
+
12864
12934
  # build spotify web api request parameters.
12865
12935
  urlParms:dict = \
12866
12936
  {
@@ -12961,10 +13031,11 @@ class SpotifyClient:
12961
13031
  # validations.
12962
13032
  delay = validateDelay(delay, 0.50, 10)
12963
13033
 
12964
- # resolve / activate the device object if needed.
13034
+ # resolve the device object from the device id.
12965
13035
  scDevice:SpotifyConnectDevice = self._ResolveDeviceObject(deviceId, False)
12966
13036
 
12967
13037
  # is this an active Sonos device?
13038
+ # Sonos device can still be active, even if there is no active device in Spotify playstate.
12968
13039
  if (scDevice is not None) and (scDevice.IsSonos):
12969
13040
 
12970
13041
  _logsi.LogVerbose("Issuing command to Sonos device %s: VOLUME = %s" % (scDevice.Title, volumePercent))
@@ -12973,6 +13044,10 @@ class SpotifyClient:
12973
13044
 
12974
13045
  else:
12975
13046
 
13047
+ # was the deviceId resolved?
13048
+ # if not, then raise an exception as the Spotify Web API request will fail anyway.
13049
+ self._CheckForDeviceNotFound(scDevice, deviceId)
13050
+
12976
13051
  # build spotify web api request parameters.
12977
13052
  urlParms:dict = \
12978
13053
  {
@@ -13129,7 +13204,7 @@ class SpotifyClient:
13129
13204
  if (scDeviceFrom is not None) and (scDeviceFrom.IsSonos):
13130
13205
  self.PlayerMediaPause(scDeviceFrom)
13131
13206
 
13132
- # resolve / activate the device object if needed.
13207
+ # resolve the device object from the device id; activate if it's dormant.
13133
13208
  # for transfer playback, we will always activate the device.
13134
13209
  scDevice = self._ResolveDeviceObject(deviceId, True)
13135
13210
 
@@ -4,7 +4,7 @@ from .spotifyconnectdirectorytask import SpotifyConnectDirectoryTask
4
4
  from .spotifyconnectzeroconfcastapptask import SpotifyConnectZeroconfCastAppTask
5
5
  from .spotifyconnectzeroconfcastcontroller import SpotifyConnectZeroconfCastController
6
6
  from .spotifyconnectzeroconfcastlistener import SpotifyConnectZeroconfCastListener
7
- from .spotifyconnectzeroconfexceptions import SpotifyConnectZeroconfLaunchError, SpotifyConnectZeroconfPlaybackTransferError
7
+ from .spotifyconnectzeroconfexceptions import SpotifyConnectZeroconfLaunchError, SpotifyConnectZeroconfPlaybackTransferError, SpotifyConnectDeviceNotFound
8
8
  from .spotifyconnectzeroconflistener import SpotifyConnectZeroconfListener
9
9
 
10
10
  # all classes to import when "import *" is specified.
@@ -15,5 +15,5 @@ __all__ = [
15
15
  'SpotifyConnectZeroconfCastListener',
16
16
  'SpotifyConnectDirectoryTask',
17
17
  'SpotifyConnectZeroconfListener',
18
- 'SpotifyConnectZeroconfLaunchError', 'SpotifyConnectZeroconfPlaybackTransferError',
18
+ 'SpotifyConnectZeroconfLaunchError', 'SpotifyConnectZeroconfPlaybackTransferError', 'SpotifyConnectDeviceNotFound',
19
19
  ]