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:
- zeroconfClient (Zeroconf) A Zeroconf client instance that will be used to discover Spotify Connect devices, or null to create a new instance of Zeroconf. Default is null.
- 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.
A dictionary of discovered device names that were detected by the discovery process.
Dictionary keys will be in the form of "'name' (address:port)", where "name" is the device name, "address" is the device server 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.
An array of ZeroconfDiscoveryResult
items that contain discovery details for
each service that was discovered.
Zeroconf client instance that will be used to discover Spotify Connect devices.
Discover Spotify Connect devices on the local network via the ZeroConf (aka MDNS) service.
Arguments:
- timeout (float): Maximum amount of time to wait (in seconds) for the
discovery to complete.
Default is 2 seconds.
Returns:
A dictionary of
ZeroconfDiscoveryResult
objects.
Sample Code
from spotifywebapipython import *
try:
print("Test Starting\n")
# create a new instance of the discovery class.
# we will print device details to the console as they are discovered.
discovery:SpotifyDiscovery = SpotifyDiscovery(printToConsole=True)
# discover Spotify Connect devices on the network, waiting up to
# 2 seconds for all devices to be discovered.
discovery.DiscoverDevices(timeout=2)
# print all discovered devices.
print("\n%s" % (discovery.ToString(True)))
except Exception as ex:
print(str(ex))
raise
finally:
print("\nTests Completed")