spotifywebapipython.spotifyconnect.spotifyconnectzeroconfcastcontroller

APP_GOOGLE_INTERNAL_RECEIVER = '705D30C6'
APP_SPOTIFY_CONNECT = '531A4F84'
APP_SPOTIFY = 'CC32E753'
APP_SPOTIFY_NAMESPACE = 'urn:x-cast:com.spotify.chromecast.secure.v1'
APP_SPOTIFY_LAUNCH_TIMEOUT = 20.0
TYPE_GET_INFO = 'getInfo'
TYPE_GET_INFO_ERROR = 'getInfoError'
TYPE_GET_INFO_RESPONSE = 'getInfoResponse'
TYPE_ADD_USER = 'addUser'
TYPE_ADD_USER_RESPONSE = 'addUserResponse'
TYPE_ADD_USER_ERROR = 'addUserError'
TYPE_TRANSFER_SUCCESS = 'transferSuccess'
TYPE_TRANSFER_ERROR = 'transferError'
TYPE_LAUNCH_ERROR = 'launchError'
SPOTIFY_WEB_API_DEVICEAUTH_REFRESH = 'https://spclient.wg.spotify.com/device-auth/v1/refresh'
WAIT_INTERVAL: float = 0.5
class SpotifyConnectZeroconfCastController(pychromecast.controllers.BaseController):

Controller to interact with Spotify Connect Zeroconf API.

SpotifyConnectZeroconfCastController( castDevice: pychromecast.Chromecast, accessToken: str = None, expiresAt: int = None, spotifyConnectLoginId: str = None)

Initializes a new instance of the class.

Arguments:
  • castDevice (CastDevice): Chromecast device target.
  • accessToken (str): Access token provided to the Spotify Web Player application.
  • expiresAt (int): DateTime (in epoch seconds) that the authorization token will expire.
  • spotifyConnectLoginId (str): Spotify Connect LoginId value of the connecting user.
accessToken: str
castDevice: pychromecast.Chromecast
clientId: str
expiresAt: int
deviceId: str
isAddUserError: bool
isGetInfoError: bool
isLaunchError: bool
isLaunched: bool
isPlaybackTransferError: bool
isMessageException: bool
spotifyConnectLoginId: str
waitAddUser: threading.Event
waitGetInfo: threading.Event
waitPlaybackTransfer: threading.Event
interactionID
def launch_app(self, timeout: float = 15.0, timeoutTransfer: float = 20.0):

Launch Spotify Cast Application on the remote cast device.

Arguments:
  • timeout (float): Number of seconds to wait for the Spotify cast app to be launched on the Chromecast device.
  • timeoutTransfer (float): Number of seconds to wait for the Spotify cast app to receive playback control on the Chromecast device.

Launches the spotify controller and returns when it's ready. To actually play media, another application using spotify connect is required.

Will raise a SpotifyConnectZeroconfLaunchError exception if there is no response from the Spotify app within timeout seconds.

Will raise a SpotifyConnectZeroconfLaunchError exception if player transfer has not been completed to the Spotify app within timeoutTransfer seconds.

def stop_app(self) -> None:

Stops Spotify Cast Application on the remote cast device.

This will also log the user out of Spotify on the device, as well as cause a remove_cast event to occur.

def receive_message(self, message, data: dict) -> None:

Called when a message is received from the Spotify cast app.

Arguments:
  • message (str): Message header values; typical keys are:
    • "protocol_version": cast protocol version (e.g. "CASTV2_1_0").
    • "source_id": source application uuid (e.g. "a23351 ... 82ff84").
    • "destination_id": destination id (e.g. "sender-0").
    • "namespace": cast app namespace (e.g. "urn:x-cast:com.spotify.chromecast.secure.v1").
    • "payload_type": payload type (e.g. "STRING").
  • data (dict): Message payload dictionary; the important keys are:
    • "type": type of payload (e.g. "getInfoResponse", "addUserResponse", "addUserError", etc).
    • "payload": contains specific fields related to the "type" of message.

Handle the auth flow and active player selection.

def getSpotifyDeviceID(self) -> str:

Retrieve the Spotify deviceID from provided chromecast info

def AddUser(self, timeout: int = 10) -> None:

Calls the addUser Spotify Zeroconf API endpoint to login the user to Spotify Connect.

Arguments:
  • timeout (int): Max time to wait (in seconds) for a response to the request.
    Only applies if the isLaunched=False.
Raises:
  • SpotifyZeroconfApiError: If the Spotify Zeroconf API request response contains error information.

The request will timeout after the specified timeout value, and an exception raised if the device cannot be reached or does not respond within that time frame.

def GetInformation( self, timeout: int = 10) -> spotifywebapipython.zeroconfapi.zeroconfgetinfo.ZeroconfGetInfo:

Calls the getInfo Spotify Zeroconf API endpoint to return information about the device.

Arguments:
  • timeout (int): Max time to wait (in seconds) for a response to the request.
    Only applies if the isLaunched=False.
Returns:

A ZeroconfGetInfo object that indicates success or failure (see notes below), as well as the device information.

Raises:
  • SpotifyZeroconfApiError: If the Spotify Zeroconf API request response contains error information.

The request will timeout after the specified timeout value, and an exception raised if the device cannot be reached or does not respond within that time frame.