spotifywebapiPython 1.0.148__py3-none-any.whl → 1.0.150__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.
- {spotifywebapiPython-1.0.148.dist-info → spotifywebapiPython-1.0.150.dist-info}/METADATA +5 -9
- {spotifywebapiPython-1.0.148.dist-info → spotifywebapiPython-1.0.150.dist-info}/RECORD +38 -29
- spotifywebapipython/__init__.py +0 -2
- spotifywebapipython/const.py +1 -1
- spotifywebapipython/docs/__init__.html +25 -4
- spotifywebapipython/docs/index.html +26 -2
- spotifywebapipython/docs/search.js +1 -1
- spotifywebapipython/docs/spotifywebapipython/const.html +3 -3
- spotifywebapipython/docs/spotifywebapipython/saappmessages.html +2 -2
- spotifywebapipython/docs/spotifywebapipython/sautils.html +8 -8
- spotifywebapipython/docs/spotifywebapipython/spotifyapierror.html +2 -2
- spotifywebapipython/docs/spotifywebapipython/spotifyapimessage.html +2 -2
- spotifywebapipython/docs/spotifywebapipython/spotifyauthtoken.html +2 -2
- spotifywebapipython/docs/spotifywebapipython/spotifyclient.html +514 -741
- spotifywebapipython/docs/spotifywebapipython/spotifydiscovery.html +3 -3
- spotifywebapipython/docs/spotifywebapipython/spotifywebapiauthenticationerror.html +2 -2
- spotifywebapipython/docs/spotifywebapipython/spotifywebapierror.html +2 -2
- spotifywebapipython/docs/spotifywebapipython/spotifywebplayertoken.html +466 -0
- spotifywebapipython/models/spotifyconnectdevice.py +84 -4
- spotifywebapipython/models/spotifyconnectdevices.py +16 -307
- spotifywebapipython/models/zeroconfdiscoveryresult.py +1 -42
- spotifywebapipython/sautils.py +0 -1
- spotifywebapipython/spotifyclient.py +1380 -1834
- spotifywebapipython/spotifyconnect/__init__.py +19 -0
- spotifywebapipython/{spotifyconnectdeviceeventargs.py → spotifyconnect/spotifyconnectdeviceeventargs.py} +1 -1
- spotifywebapipython/spotifyconnect/spotifyconnectdirectorytask.py +1994 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastapptask.py +336 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastcontroller.py +609 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconfcastlistener.py +317 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconfexceptions.py +10 -0
- spotifywebapipython/spotifyconnect/spotifyconnectzeroconflistener.py +335 -0
- spotifywebapipython/spotifydiscovery.py +0 -1
- spotifywebapipython/spotifywebplayertoken.py +344 -0
- spotifywebapipython/zeroconfapi/zeroconfgetinfo.py +4 -52
- spotifywebapipython/zeroconfapi/zeroconfresponse.py +8 -0
- {spotifywebapiPython-1.0.148.dist-info → spotifywebapiPython-1.0.150.dist-info}/LICENSE +0 -0
- {spotifywebapiPython-1.0.148.dist-info → spotifywebapiPython-1.0.150.dist-info}/WHEEL +0 -0
- {spotifywebapiPython-1.0.148.dist-info → spotifywebapiPython-1.0.150.dist-info}/top_level.txt +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
# our package imports.
|
|
4
4
|
from ..sautils import export
|
|
5
5
|
from .zeroconfdiscoveryresult import ZeroconfDiscoveryResult
|
|
6
|
-
from spotifywebapipython.zeroconfapi
|
|
6
|
+
from spotifywebapipython.zeroconfapi import ZeroconfGetInfo, ZeroconfResponse
|
|
7
7
|
|
|
8
8
|
@export
|
|
9
9
|
class SpotifyConnectDevice():
|
|
@@ -21,7 +21,11 @@ class SpotifyConnectDevice():
|
|
|
21
21
|
self._DiscoveryResult:ZeroconfDiscoveryResult = None
|
|
22
22
|
self._DeviceInfo:ZeroconfGetInfo = None
|
|
23
23
|
self._Id:str = None
|
|
24
|
+
self._IsActiveDevice:bool = False
|
|
25
|
+
self._IsInDeviceList:bool = False
|
|
26
|
+
self._IsRestricted:bool = False
|
|
24
27
|
self._Name:str = None
|
|
28
|
+
self._ZeroconfResponseInfo:ZeroconfResponse = ZeroconfResponse()
|
|
25
29
|
self._WasReConnected:bool = False
|
|
26
30
|
|
|
27
31
|
|
|
@@ -80,6 +84,23 @@ class SpotifyConnectDevice():
|
|
|
80
84
|
self._Id = value
|
|
81
85
|
|
|
82
86
|
|
|
87
|
+
@property
|
|
88
|
+
def IsActiveDevice(self) -> bool:
|
|
89
|
+
"""
|
|
90
|
+
Returns True if this device is the currently active Spotify Web API player device;
|
|
91
|
+
otherwise, False.
|
|
92
|
+
"""
|
|
93
|
+
return self._IsActiveDevice
|
|
94
|
+
|
|
95
|
+
@IsActiveDevice.setter
|
|
96
|
+
def IsActiveDevice(self, value:bool):
|
|
97
|
+
"""
|
|
98
|
+
Sets the IsActiveDevice property value.
|
|
99
|
+
"""
|
|
100
|
+
if isinstance(value, bool):
|
|
101
|
+
self._IsActiveDevice = value
|
|
102
|
+
|
|
103
|
+
|
|
83
104
|
@property
|
|
84
105
|
def IsChromeCast(self) -> bool:
|
|
85
106
|
"""
|
|
@@ -90,6 +111,40 @@ class SpotifyConnectDevice():
|
|
|
90
111
|
return False
|
|
91
112
|
|
|
92
113
|
|
|
114
|
+
@property
|
|
115
|
+
def IsInDeviceList(self) -> bool:
|
|
116
|
+
"""
|
|
117
|
+
Returns True if this device is a member of the Spotify Web API player device list;
|
|
118
|
+
otherwise, False.
|
|
119
|
+
"""
|
|
120
|
+
return self._IsInDeviceList
|
|
121
|
+
|
|
122
|
+
@IsInDeviceList.setter
|
|
123
|
+
def IsInDeviceList(self, value:bool):
|
|
124
|
+
"""
|
|
125
|
+
Sets the IsInDeviceList property value.
|
|
126
|
+
"""
|
|
127
|
+
if isinstance(value, bool):
|
|
128
|
+
self._IsInDeviceList = value
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@property
|
|
132
|
+
def IsRestricted(self) -> bool:
|
|
133
|
+
"""
|
|
134
|
+
Returns True if this device is a member of the Spotify Web API player device list;
|
|
135
|
+
otherwise, False.
|
|
136
|
+
"""
|
|
137
|
+
return self._IsRestricted
|
|
138
|
+
|
|
139
|
+
@IsRestricted.setter
|
|
140
|
+
def IsRestricted(self, value:bool):
|
|
141
|
+
"""
|
|
142
|
+
Sets the IsRestricted property value.
|
|
143
|
+
"""
|
|
144
|
+
if isinstance(value, bool):
|
|
145
|
+
self._IsRestricted = value
|
|
146
|
+
|
|
147
|
+
|
|
93
148
|
@property
|
|
94
149
|
def Name(self) -> str:
|
|
95
150
|
"""
|
|
@@ -108,9 +163,9 @@ class SpotifyConnectDevice():
|
|
|
108
163
|
@property
|
|
109
164
|
def Title(self) -> str:
|
|
110
165
|
"""
|
|
111
|
-
Spotify Connect device name and id value (e.g.
|
|
166
|
+
Spotify Connect device name and id value (e.g. "Bose-ST10-1" (30fbc80e35598f3c242f2120413c943dfd9715fe)).
|
|
112
167
|
"""
|
|
113
|
-
return
|
|
168
|
+
return "\"%s\" (%s)" % (self._Name, self._Id)
|
|
114
169
|
|
|
115
170
|
|
|
116
171
|
@property
|
|
@@ -128,6 +183,22 @@ class SpotifyConnectDevice():
|
|
|
128
183
|
self._WasReConnected = value
|
|
129
184
|
|
|
130
185
|
|
|
186
|
+
@property
|
|
187
|
+
def ZeroconfResponseInfo(self) -> ZeroconfResponse:
|
|
188
|
+
"""
|
|
189
|
+
Spotify Zeroconf API Zeroconf response object.
|
|
190
|
+
"""
|
|
191
|
+
return self._ZeroconfResponseInfo
|
|
192
|
+
|
|
193
|
+
@ZeroconfResponseInfo.setter
|
|
194
|
+
def ZeroconfResponseInfo(self, value:ZeroconfResponse):
|
|
195
|
+
"""
|
|
196
|
+
Sets the ZeroconfResponseInfo property value.
|
|
197
|
+
"""
|
|
198
|
+
if isinstance(value, ZeroconfResponse):
|
|
199
|
+
self._ZeroconfResponseInfo = value
|
|
200
|
+
|
|
201
|
+
|
|
131
202
|
def Equals(self, obj) -> bool:
|
|
132
203
|
"""
|
|
133
204
|
Returns true if the specified object instance contains the same argument
|
|
@@ -160,10 +231,14 @@ class SpotifyConnectDevice():
|
|
|
160
231
|
'Id': self._Id,
|
|
161
232
|
'Name': self._Name,
|
|
162
233
|
'Title': self.Title,
|
|
163
|
-
'
|
|
234
|
+
'IsActiveDevice': self._IsActiveDevice,
|
|
164
235
|
'IsChromeCast': self.IsChromeCast,
|
|
236
|
+
'IsInDeviceList': self._IsInDeviceList,
|
|
237
|
+
'IsRestricted': self._IsRestricted,
|
|
238
|
+
'WasReConnected': self._WasReConnected,
|
|
165
239
|
'DeviceInfo': self._DeviceInfo.ToDictionary(),
|
|
166
240
|
'DiscoveryResult': self._DiscoveryResult.ToDictionary(),
|
|
241
|
+
'ZeroconfResponseInfo': self._ZeroconfResponseInfo.ToDictionary(),
|
|
167
242
|
}
|
|
168
243
|
return result
|
|
169
244
|
|
|
@@ -179,10 +254,15 @@ class SpotifyConnectDevice():
|
|
|
179
254
|
msg:str = ''
|
|
180
255
|
if includeTitle:
|
|
181
256
|
msg = 'Device: "%s" (%s)' % (self._Name, self._Id)
|
|
257
|
+
msg = '%s\n IsActiveDevice="%s"' % (msg, str(self._IsActiveDevice))
|
|
258
|
+
msg = '%s\n IsChromecast="%s"' % (msg, str(self.IsChromeCast))
|
|
259
|
+
msg = '%s\n IsInDeviceList="%s"' % (msg, str(self._IsInDeviceList))
|
|
260
|
+
msg = '%s\n IsRestricted="%s"' % (msg, str(self._IsRestricted))
|
|
182
261
|
msg = '%s\n WasReConnected="%s"' % (msg, str(self._WasReConnected))
|
|
183
262
|
msg = '%s\n' % (msg)
|
|
184
263
|
|
|
185
264
|
# build result.
|
|
186
265
|
msg = '%s\n %s\n' % (msg, str(self._DeviceInfo.ToString(True)))
|
|
187
266
|
msg = '%s\n %s\n' % (msg, str(self._DiscoveryResult.ToString(True)))
|
|
267
|
+
msg = '%s\n %s\n' % (msg, str(self._ZeroconfResponseInfo.ToString(True)))
|
|
188
268
|
return msg
|
|
@@ -96,278 +96,6 @@ class SpotifyConnectDevices():
|
|
|
96
96
|
return 0
|
|
97
97
|
|
|
98
98
|
|
|
99
|
-
def AddDynamicDevice(
|
|
100
|
-
self,
|
|
101
|
-
device:Device,
|
|
102
|
-
activeUser:str
|
|
103
|
-
) -> None:
|
|
104
|
-
"""
|
|
105
|
-
Adds a new dynamic device entry to the `Items` collection.
|
|
106
|
-
|
|
107
|
-
Args:
|
|
108
|
-
device (Device):
|
|
109
|
-
Device information to add.
|
|
110
|
-
activeUser (str):
|
|
111
|
-
Currently active user id.
|
|
112
|
-
|
|
113
|
-
Dynamic devices are Spotify Connect devices that are not found in Zeroconf discovery
|
|
114
|
-
process, but still exist in the player device list. These are usually Spotify Player
|
|
115
|
-
client devices (e.g. mobile / web / desktop players) that utilize temporary device id's.
|
|
116
|
-
"""
|
|
117
|
-
# validations.
|
|
118
|
-
if (device is None) or (not isinstance(device, Device)):
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
# build zeroconf discovery result with what we can.
|
|
122
|
-
discoverResult:ZeroconfDiscoveryResult = ZeroconfDiscoveryResult()
|
|
123
|
-
discoverResult.DeviceName = device.Name
|
|
124
|
-
discoverResult.HostIpAddresses.append('127.0.0.1')
|
|
125
|
-
discoverResult.Server = '127.0.0.1'
|
|
126
|
-
discoverResult.HostIpPort = 0
|
|
127
|
-
discoverResult.Name = device.Name
|
|
128
|
-
discoverResult.SpotifyConnectCPath = '/zc'
|
|
129
|
-
discoverResult.SpotifyConnectVersion = '1.0'
|
|
130
|
-
|
|
131
|
-
# build zeroconf getinfo result with what we can.
|
|
132
|
-
info:ZeroconfGetInfo = ZeroconfGetInfo()
|
|
133
|
-
info.ActiveUser = activeUser
|
|
134
|
-
info.DeviceId = device.Id
|
|
135
|
-
info.DeviceType = device.Type
|
|
136
|
-
info.RemoteName = device.Name
|
|
137
|
-
info.SpotifyError = 0
|
|
138
|
-
info.Status = 101
|
|
139
|
-
info.StatusString = 'OK'
|
|
140
|
-
|
|
141
|
-
# populate brand info for popular devices.
|
|
142
|
-
if (device.Name == "Web Player (Chrome)"):
|
|
143
|
-
info.BrandDisplayName = 'Google'
|
|
144
|
-
info.ModelDisplayName = 'Chrome'
|
|
145
|
-
info.ProductId = 'Web Player'
|
|
146
|
-
elif (device.Name == "Web Player (Microsoft Edge)"):
|
|
147
|
-
info.BrandDisplayName = 'Microsoft'
|
|
148
|
-
info.ModelDisplayName = 'Edge'
|
|
149
|
-
info.ProductId = 'Web Player'
|
|
150
|
-
else:
|
|
151
|
-
info.BrandDisplayName = 'unknown'
|
|
152
|
-
info.ModelDisplayName = 'unknown'
|
|
153
|
-
info.ProductId = 'unknown'
|
|
154
|
-
|
|
155
|
-
# add the device.
|
|
156
|
-
scDevice:SpotifyConnectDevice = SpotifyConnectDevice()
|
|
157
|
-
scDevice.Id = info.DeviceId
|
|
158
|
-
scDevice.Name = info.RemoteName
|
|
159
|
-
scDevice.DeviceInfo = info
|
|
160
|
-
scDevice.DiscoveryResult = discoverResult
|
|
161
|
-
self._Items.append(scDevice)
|
|
162
|
-
|
|
163
|
-
# trace.
|
|
164
|
-
_logsi.LogVerbose("Added SpotifyConnectDevices collection entry: \"%s\" - %s" % (scDevice.Title, scDevice.DiscoveryResult.Description), colorValue=SIColors.ForestGreen)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
def GetActiveDevice(
|
|
168
|
-
self,
|
|
169
|
-
) -> SpotifyConnectDevice:
|
|
170
|
-
"""
|
|
171
|
-
Returns a Spotify Connect device if one is currently marked as the active device;
|
|
172
|
-
otherwise, null if there is no active device.
|
|
173
|
-
|
|
174
|
-
Note that this does not perform a real-time Spotify Web API query for the active device.
|
|
175
|
-
It simply checks the devices collection for an entry that was marked as the active device
|
|
176
|
-
by the `UpdatePlayerDevices` method.
|
|
177
|
-
"""
|
|
178
|
-
# find and return the active device if one exists; otherwise, null.
|
|
179
|
-
result:SpotifyConnectDevice = None
|
|
180
|
-
scDevice:SpotifyConnectDevice
|
|
181
|
-
for scDevice in self._Items:
|
|
182
|
-
if (scDevice.DeviceInfo is not None):
|
|
183
|
-
if (scDevice.DeviceInfo.IsActiveDevice):
|
|
184
|
-
result = scDevice
|
|
185
|
-
break
|
|
186
|
-
return result
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
def RemoveDevice(
|
|
190
|
-
self,
|
|
191
|
-
deviceId:str,
|
|
192
|
-
dynamicDeviceOnly:bool=False
|
|
193
|
-
) -> None:
|
|
194
|
-
"""
|
|
195
|
-
Removes existing device entry(s) from the `Items` collection by device id value.
|
|
196
|
-
|
|
197
|
-
Args:
|
|
198
|
-
deviceId (str):
|
|
199
|
-
Device id to remove.
|
|
200
|
-
dynamicDeviceOnly (str):
|
|
201
|
-
True to only remove the device if it's a dynamic device entry;
|
|
202
|
-
otherwise, False to remove the device id regardless.
|
|
203
|
-
Default is False.
|
|
204
|
-
|
|
205
|
-
It's possible to have multiple devices with the same id (e.g. both a dynamic and a
|
|
206
|
-
zeroconf registered device).
|
|
207
|
-
|
|
208
|
-
Dynamic devices are Spotify Connect devices that are not found in Zeroconf discovery
|
|
209
|
-
process, but still exist in the player device list. These are usually Spotify Player
|
|
210
|
-
client devices (e.g. mobile / web / desktop players) that utilize temporary device id's.
|
|
211
|
-
"""
|
|
212
|
-
# validations.
|
|
213
|
-
if (not isinstance(dynamicDeviceOnly,bool)):
|
|
214
|
-
dynamicDeviceOnly = False
|
|
215
|
-
|
|
216
|
-
# remove device from devices collection;
|
|
217
|
-
# the reversed() function creates an iterator that traverses the list in reverse order.
|
|
218
|
-
# this ensures that removing an element doesn't affect the indices of the subsequent
|
|
219
|
-
# elements we're going to iterate over.
|
|
220
|
-
deviceIdCompare:str = "" + deviceId.lower()
|
|
221
|
-
scDevice:SpotifyConnectDevice
|
|
222
|
-
for idx in reversed(range(len(self._Items))):
|
|
223
|
-
|
|
224
|
-
scDevice = self._Items[idx]
|
|
225
|
-
|
|
226
|
-
# did we find a match by device id?
|
|
227
|
-
if (deviceIdCompare == scDevice.Id.lower()):
|
|
228
|
-
|
|
229
|
-
isFound:bool = True
|
|
230
|
-
|
|
231
|
-
# get dynamic device status.
|
|
232
|
-
isDynamic:bool = False
|
|
233
|
-
if (scDevice.DiscoveryResult is not None):
|
|
234
|
-
isDynamic = scDevice.DiscoveryResult.IsDynamicDevice
|
|
235
|
-
|
|
236
|
-
# are we checking for dynamic device? if so, and it's NOT dynamic, then don't delete it!
|
|
237
|
-
if (dynamicDeviceOnly) and (not isDynamic):
|
|
238
|
-
isFound = False
|
|
239
|
-
|
|
240
|
-
# are we deleting this device?
|
|
241
|
-
if (isFound):
|
|
242
|
-
_logsi.LogVerbose("Removing SpotifyConnectDevices collection entry: \"%s\" - %s" % (scDevice.Title, scDevice.DiscoveryResult.Description), colorValue=SIColors.Orange)
|
|
243
|
-
self._Items.pop(idx)
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
def UpdatePlayerDevices(
|
|
247
|
-
self,
|
|
248
|
-
playerDevices:list[Device],
|
|
249
|
-
activeUser:str,
|
|
250
|
-
playerState:PlayerPlayState=None
|
|
251
|
-
) -> SpotifyConnectDevice:
|
|
252
|
-
"""
|
|
253
|
-
Adds a list of dynamic player device entries to the `Items` collection, removes any
|
|
254
|
-
existing dynamic devices from the collection that are not in the `playerDevices` list,
|
|
255
|
-
and updates the currently active device based on playerState.
|
|
256
|
-
|
|
257
|
-
Args:
|
|
258
|
-
playerDevices (list[Device]):
|
|
259
|
-
List of current player devices obtained via a call to `GetPlayerDevices` method.
|
|
260
|
-
activeUser (str):
|
|
261
|
-
Currently active user id.
|
|
262
|
-
playerState (PlayerPlayState):
|
|
263
|
-
Current player state obtained via a call to `GetPlayerPlaybackState` method
|
|
264
|
-
which will be used to set the active device in the `Items` collection;
|
|
265
|
-
otherwise, null to bypass active device set.
|
|
266
|
-
|
|
267
|
-
Returns:
|
|
268
|
-
null if the `playerState` argument was not specified;
|
|
269
|
-
otherwise, the currently active Spotify Player device instance as determined by
|
|
270
|
-
the Spotify Player PlayState.
|
|
271
|
-
|
|
272
|
-
Dynamic devices are Spotify Connect devices that are not found in Zeroconf discovery
|
|
273
|
-
process, but still exist in the player device list. These are usually Spotify Player
|
|
274
|
-
client devices (e.g. mobile / web / desktop players) that utilize temporary device id's.
|
|
275
|
-
"""
|
|
276
|
-
result:SpotifyConnectDevice = None
|
|
277
|
-
|
|
278
|
-
# validations
|
|
279
|
-
if (not isinstance(playerDevices, list)):
|
|
280
|
-
return result
|
|
281
|
-
|
|
282
|
-
# add dynamic devices.
|
|
283
|
-
scDevice:SpotifyConnectDevice
|
|
284
|
-
device:Device
|
|
285
|
-
for device in playerDevices:
|
|
286
|
-
|
|
287
|
-
# is the player device present in the collection? if not, then add it.
|
|
288
|
-
if (not self.ContainsDeviceId(device.Id)):
|
|
289
|
-
self.AddDynamicDevice(device, activeUser)
|
|
290
|
-
|
|
291
|
-
# is the device in the available device list for this user context?
|
|
292
|
-
# if not, then set an indicator so we can re-activate it later if need be.
|
|
293
|
-
for scDevice in self._Items:
|
|
294
|
-
if (scDevice.DeviceInfo.DeviceId == device.Id):
|
|
295
|
-
scDevice.DeviceInfo.IsInDeviceList = True
|
|
296
|
-
break
|
|
297
|
-
|
|
298
|
-
# remove stale dynamic devices from results collection;
|
|
299
|
-
# the reversed() function creates an iterator that traverses the list in reverse order.
|
|
300
|
-
# this ensures that removing an element doesn't affect the indices of the subsequent
|
|
301
|
-
# elements we're going to iterate over.
|
|
302
|
-
for idx in reversed(range(len(self._Items))):
|
|
303
|
-
|
|
304
|
-
# only process dynamic devices.
|
|
305
|
-
scDevice = self._Items[idx]
|
|
306
|
-
if (scDevice.DiscoveryResult.IsDynamicDevice):
|
|
307
|
-
|
|
308
|
-
# process all player devices.
|
|
309
|
-
wasFound:bool = False
|
|
310
|
-
playerDevice:Device
|
|
311
|
-
for playerDevice in playerDevices:
|
|
312
|
-
if (scDevice.Id == playerDevice.Id):
|
|
313
|
-
wasFound = True
|
|
314
|
-
break
|
|
315
|
-
|
|
316
|
-
# if collection entry was not found in the player device list then remove it.
|
|
317
|
-
if (not wasFound):
|
|
318
|
-
_logsi.LogVerbose("Removed dynamic device \"%s\" (%s) from Spotify Connect Devices collection" % (scDevice.Name, scDevice.Id))
|
|
319
|
-
self._Items.pop(idx)
|
|
320
|
-
|
|
321
|
-
# update active device entry.
|
|
322
|
-
# returns null if the `playerState` argument was not specified;
|
|
323
|
-
# otherwise, the currently active Spotify Player device instance as determined by
|
|
324
|
-
# the Spotify Player PlayState (could be null if no active device).
|
|
325
|
-
result = self.UpdateActiveDevice(playerState)
|
|
326
|
-
return result
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
def UpdateActiveDevice(
|
|
330
|
-
self,
|
|
331
|
-
playerState:PlayerPlayState=None
|
|
332
|
-
) -> SpotifyConnectDevice:
|
|
333
|
-
"""
|
|
334
|
-
Updates the currently active device based on playerState.
|
|
335
|
-
|
|
336
|
-
Args:
|
|
337
|
-
playerState (PlayerPlayState):
|
|
338
|
-
Current player state obtained via a call to `GetPlayerPlaybackState` method
|
|
339
|
-
which will be used to set the active device in the `Items` collection;
|
|
340
|
-
otherwise, null to bypass active device set.
|
|
341
|
-
|
|
342
|
-
Returns:
|
|
343
|
-
The currently active Spotify Player device instance as determined by
|
|
344
|
-
the Spotify Player PlayState; could be null if no active device was found.
|
|
345
|
-
"""
|
|
346
|
-
result:SpotifyConnectDevice = None
|
|
347
|
-
|
|
348
|
-
if (isinstance(playerState, PlayerPlayState)):
|
|
349
|
-
|
|
350
|
-
# we do this in case the active device is a "restricted" device; if it is, then it may
|
|
351
|
-
# not show up as the active device (common issue with Sonos devices).
|
|
352
|
-
# in this case, it WILL show up in the player state device property as the active device.
|
|
353
|
-
# if it IS active, then we will set the active flag.
|
|
354
|
-
# note that the PlayerPlayState device is a name and not a device id.
|
|
355
|
-
if playerState.Device is not None:
|
|
356
|
-
|
|
357
|
-
device = playerState.Device
|
|
358
|
-
for scDevice in self._Items:
|
|
359
|
-
scDevice.DeviceInfo.IsActiveDevice = False
|
|
360
|
-
if (device.Name == scDevice.Name):
|
|
361
|
-
_logsi.LogVerbose("Spotify Connect active device detected: \"%s\" (%s)" % (device.Name, device.Id))
|
|
362
|
-
scDevice.DeviceInfo.IsActiveDevice = True
|
|
363
|
-
result = scDevice
|
|
364
|
-
|
|
365
|
-
# returns null if the `playerState` argument was not specified;
|
|
366
|
-
# otherwise, the currently active Spotify Player device instance as determined by
|
|
367
|
-
# the Spotify Player PlayState (could be null if no active device).
|
|
368
|
-
return result
|
|
369
|
-
|
|
370
|
-
|
|
371
99
|
def ContainsDeviceId(self, value:str) -> bool:
|
|
372
100
|
"""
|
|
373
101
|
Returns True if the `Items` collection contains the specified device id value;
|
|
@@ -457,15 +185,17 @@ class SpotifyConnectDevices():
|
|
|
457
185
|
if (scDevice.DeviceInfo.HasAliases):
|
|
458
186
|
scAlias:ZeroconfGetInfoAlias
|
|
459
187
|
for scAlias in scDevice.DeviceInfo.Aliases:
|
|
460
|
-
if (scAlias.Id
|
|
461
|
-
|
|
462
|
-
|
|
188
|
+
if (scAlias.Id is not None):
|
|
189
|
+
if (scAlias.Id.lower() == value):
|
|
190
|
+
result = scDevice
|
|
191
|
+
break
|
|
463
192
|
if result:
|
|
464
193
|
break
|
|
465
194
|
else:
|
|
466
|
-
if (scDevice.DeviceInfo.DeviceId
|
|
467
|
-
|
|
468
|
-
|
|
195
|
+
if (scDevice.DeviceInfo.DeviceId is not None):
|
|
196
|
+
if (scDevice.DeviceInfo.DeviceId.lower() == value):
|
|
197
|
+
result = scDevice
|
|
198
|
+
break
|
|
469
199
|
return result
|
|
470
200
|
|
|
471
201
|
|
|
@@ -489,15 +219,17 @@ class SpotifyConnectDevices():
|
|
|
489
219
|
if (scDevice.DeviceInfo.HasAliases):
|
|
490
220
|
scAlias:ZeroconfGetInfoAlias
|
|
491
221
|
for scAlias in scDevice.DeviceInfo.Aliases:
|
|
492
|
-
if (scAlias.Name
|
|
493
|
-
|
|
494
|
-
|
|
222
|
+
if (scAlias.Name is not None):
|
|
223
|
+
if (scAlias.Name.lower() == value):
|
|
224
|
+
result = scDevice
|
|
225
|
+
break
|
|
495
226
|
if result is not None:
|
|
496
227
|
break
|
|
497
228
|
else:
|
|
498
|
-
if (scDevice.DeviceInfo.RemoteName
|
|
499
|
-
|
|
500
|
-
|
|
229
|
+
if (scDevice.DeviceInfo.RemoteName is not None):
|
|
230
|
+
if (scDevice.DeviceInfo.RemoteName.lower() == value):
|
|
231
|
+
result = scDevice
|
|
232
|
+
break
|
|
501
233
|
return result
|
|
502
234
|
|
|
503
235
|
|
|
@@ -547,29 +279,6 @@ class SpotifyConnectDevices():
|
|
|
547
279
|
return result
|
|
548
280
|
|
|
549
281
|
|
|
550
|
-
def GetDeviceIndexByDiscoveryKey(self, value:str) -> int:
|
|
551
|
-
"""
|
|
552
|
-
Returns the index of the `Items` collection entry that contains
|
|
553
|
-
the specified device zeroconf discovery results key value if found;
|
|
554
|
-
otherwise, -1.
|
|
555
|
-
"""
|
|
556
|
-
result:int = -1
|
|
557
|
-
if value is None:
|
|
558
|
-
return result
|
|
559
|
-
|
|
560
|
-
# convert case for comparison.
|
|
561
|
-
value = value.lower()
|
|
562
|
-
|
|
563
|
-
# process all devices, comparing discovery keys.
|
|
564
|
-
for i in range(len(self._Items)):
|
|
565
|
-
if (self._Items[i].DiscoveryResult is not None):
|
|
566
|
-
if (self._Items[i].DiscoveryResult.Key is not None):
|
|
567
|
-
if (self._Items[i].DiscoveryResult.Key.lower() == value):
|
|
568
|
-
result = i
|
|
569
|
-
break
|
|
570
|
-
return result
|
|
571
|
-
|
|
572
|
-
|
|
573
282
|
def GetDeviceIndexByDiscoveryName(self, value:str) -> int:
|
|
574
283
|
"""
|
|
575
284
|
Returns the index of the `Items` collection entry that contains
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
# external package imports.
|
|
2
|
-
from zeroconf import ServiceInfo
|
|
3
|
-
|
|
4
1
|
# our package imports.
|
|
5
2
|
from ..sautils import export
|
|
6
3
|
from .zeroconfproperty import ZeroconfProperty
|
|
@@ -31,14 +28,12 @@ class ZeroconfDiscoveryResult:
|
|
|
31
28
|
self._Properties:list = []
|
|
32
29
|
self._Server:str = None
|
|
33
30
|
self._ServerKey:str = None
|
|
34
|
-
self._ServiceInfo:ServiceInfo = None
|
|
35
31
|
self._ServiceType:str = None
|
|
36
32
|
self._Weight:int = None
|
|
37
33
|
|
|
38
34
|
# Spotify Connect specific properties:
|
|
39
35
|
self._SpotifyConnectCPath:str = None
|
|
40
36
|
self._SpotifyConnectVersion:str = None
|
|
41
|
-
self._SpotifyConnectIsInDeviceList:bool = False
|
|
42
37
|
|
|
43
38
|
|
|
44
39
|
def __repr__(self) -> str:
|
|
@@ -330,22 +325,6 @@ class ZeroconfDiscoveryResult:
|
|
|
330
325
|
self._ServerKey = value
|
|
331
326
|
|
|
332
327
|
|
|
333
|
-
@property
|
|
334
|
-
def ServiceInfo(self) -> ServiceInfo:
|
|
335
|
-
"""
|
|
336
|
-
Zeroconf Service info object.
|
|
337
|
-
"""
|
|
338
|
-
return self._ServiceInfo
|
|
339
|
-
|
|
340
|
-
@ServiceInfo.setter
|
|
341
|
-
def ServiceInfo(self, value:ServiceInfo):
|
|
342
|
-
"""
|
|
343
|
-
Sets the ServiceInfo property value.
|
|
344
|
-
"""
|
|
345
|
-
if isinstance(value, ServiceInfo):
|
|
346
|
-
self._ServiceInfo = value
|
|
347
|
-
|
|
348
|
-
|
|
349
328
|
@property
|
|
350
329
|
def ServiceType(self) -> str:
|
|
351
330
|
"""
|
|
@@ -397,22 +376,6 @@ class ZeroconfDiscoveryResult:
|
|
|
397
376
|
self._SpotifyConnectCPath = value
|
|
398
377
|
|
|
399
378
|
|
|
400
|
-
@property
|
|
401
|
-
def SpotifyConnectIsInDeviceList(self) -> bool:
|
|
402
|
-
"""
|
|
403
|
-
True if the device is in the Spotify Player active device list; otherwise, False.
|
|
404
|
-
"""
|
|
405
|
-
return self._SpotifyConnectIsInDeviceList
|
|
406
|
-
|
|
407
|
-
@SpotifyConnectIsInDeviceList.setter
|
|
408
|
-
def SpotifyConnectIsInDeviceList(self, value:bool):
|
|
409
|
-
"""
|
|
410
|
-
Sets the SpotifyConnectIsInDeviceList property value.
|
|
411
|
-
"""
|
|
412
|
-
if isinstance(value, bool):
|
|
413
|
-
self._SpotifyConnectIsInDeviceList = value
|
|
414
|
-
|
|
415
|
-
|
|
416
379
|
@property
|
|
417
380
|
def SpotifyConnectVersion(self) -> str:
|
|
418
381
|
"""
|
|
@@ -485,11 +448,9 @@ class ZeroconfDiscoveryResult:
|
|
|
485
448
|
if (self._Weight != obj._Weight): return result
|
|
486
449
|
if (self._SpotifyConnectCPath != obj._SpotifyConnectCPath): return result
|
|
487
450
|
if (self._SpotifyConnectVersion != obj._SpotifyConnectVersion): return result
|
|
488
|
-
if (self._SpotifyConnectIsInDeviceList != obj._SpotifyConnectIsInDeviceList): return result
|
|
489
451
|
|
|
490
452
|
# don't compare the following:
|
|
491
453
|
# self._Properties:list = []
|
|
492
|
-
# self._ServiceInfo:ServiceInfo = None
|
|
493
454
|
|
|
494
455
|
# objects attributes are equal.
|
|
495
456
|
return True
|
|
@@ -528,8 +489,8 @@ class ZeroconfDiscoveryResult:
|
|
|
528
489
|
'HostIpAddresses': [ str(item) for item in self._HostIpAddresses ],
|
|
529
490
|
'HostIpPort': self._HostIpPort,
|
|
530
491
|
'HostTTL': self._HostTTL,
|
|
531
|
-
'IsDynamicDevice': self.IsDynamicDevice,
|
|
532
492
|
'IsChromeCast': self._IsChromeCast,
|
|
493
|
+
'IsDynamicDevice': self.IsDynamicDevice,
|
|
533
494
|
'Key': self._Key,
|
|
534
495
|
'Name': self._Name,
|
|
535
496
|
'Priority': self._Priority,
|
|
@@ -541,7 +502,6 @@ class ZeroconfDiscoveryResult:
|
|
|
541
502
|
'Description': self.Description,
|
|
542
503
|
'Properties': [ item.ToDictionary() for item in self._Properties ],
|
|
543
504
|
'SpotifyConnectCPath': self._SpotifyConnectCPath,
|
|
544
|
-
'SpotifyConnectIsInDeviceList': self._SpotifyConnectIsInDeviceList,
|
|
545
505
|
'SpotifyConnectVersion': self._SpotifyConnectVersion,
|
|
546
506
|
'ZeroconfApiEndpointAddUser': self.ZeroconfApiEndpointAddUser,
|
|
547
507
|
'ZeroconfApiEndpointGetInformation': self.ZeroconfApiEndpointGetInformation,
|
|
@@ -591,7 +551,6 @@ class ZeroconfDiscoveryResult:
|
|
|
591
551
|
if description is not None: msg = '%s\n Description="%s"' % (msg, str(description))
|
|
592
552
|
if self._Properties is not None: msg = '%s\n Properties Count=%s' % (msg, str(len(self._Properties)))
|
|
593
553
|
if self._SpotifyConnectCPath is not None: msg = '%s\n SpotifyConnectCPath="%s"' % (msg, str(self._SpotifyConnectCPath))
|
|
594
|
-
if self._SpotifyConnectIsInDeviceList is not None: msg = '%s\n SpotifyConnectIsInDeviceList="%s"' % (msg, str(self._SpotifyConnectIsInDeviceList))
|
|
595
554
|
if self._SpotifyConnectVersion is not None: msg = '%s\n SpotifyConnectVersion="%s"' % (msg, str(self._SpotifyConnectVersion))
|
|
596
555
|
if zeroconfApiEndpointAddUser is not None: msg = '%s\n ZeroconfApiEndpointAddUser="%s"' % (msg, zeroconfApiEndpointAddUser)
|
|
597
556
|
if zeroconfApiEndpointGetInformation is not None: msg = '%s\n ZeroconfApiEndpointGetInformation="%s"' % (msg, zeroconfApiEndpointGetInformation)
|