spotifywebapipython.spotifydiscovery
This class contains methods used to dicover Spotify Connect devices on a local network. The ZeroConf (aka MDNS, etc) service is used to detect devices, and adds them to a device list as they are discovered.
Click the Sample Code links in the individual methods for sample code examples.
Initializes a new instance of the class.
Arguments:
- spotifyClient (SpotifyClient): A SpotifyClient instance that will be used to verify discovered devices.
This can be null if the areDevicesVerified argument is False.
This argument is required if the areDevicesVerified argument is True. - areDevicesVerified (bool): True to create a
SpotifyClient
instance for discovered devices, which verifies that the device can be accessed and basic information obtained about its capabilities; otherwise, False to just identify the IPV4 Address, Port, and Device Name.
Default is False. - printToConsole (bool): True to print discovered device information to the console as the devices are discovered; otherwise, False to not print anything to the console. Default is False.
Specify False for the areDevicesVerified
argument if you want to speed up
device discovery, as it takes extra time to verify device connections as they
are discovered.
Determines if a Device
object is created for devices that are
discovered. This property is set by what is passed to the class constructor.
If False, then the VerifiedDevices
property will be empty;
If True, then the VerifiedDevices
property will contain a Device
instance for each device that was detected as part of the discovery process
and was found in the Spotify User's player devices list.
A dictionary of discovered device names that were detected by the discovery process.
Dictionary keys will be in the form of "address:port", where "address" is the device ipv4 address and the "port" is the ipv4 port number the Spotify Connect device is listening on.
Dictionary values will be the device names (e.g. "Web Player (Chrome)", etc.). This SHOULD match the name of the device as displayed in the Spotify App, but is not guaranteed.
A dictionary of discovered Device
instances that were detected on the network.
This property is only populated if the AreDevicesVerified
property is True.
Dictionary keys will be in the form of "address:port", where "address" is the device ipv4 address and the "port" is the ipv4 port number the Spotify Connect device is listening on.
Dictionary values will be Device
instances that represent the discovered
device.
Discover Spotify Connect devices on the local network via the ZeroConf (aka MDNS) service.
Arguments:
- timeout (int): Maximum amount of time to wait (in seconds) for the
discovery to complete.
Default is 5 seconds.
Returns:
A dictionary of discovered
SpotifyClient
objects.
Sample Code
from spotifywebapipython import *
try:
print("Test Starting\n")
# create a new instance of the discovery class.
# we will verify device connections, as well as print device details
# to the console as they are discovered.
discovery:SpotifyDiscovery = SpotifyDiscovery(True, printToConsole=True)
# discover Spotify Connect devices on the network, waiting up to
# 5 seconds for all devices to be discovered.
discovery.DiscoverDevices(timeout=5)
# print all discovered devices.
print("\n%s" % (discovery.ToString(True)))
except Exception as ex:
print(str(ex))
raise
finally:
print("\nTests Completed")