How to use the pychromecast.controllers.spotify.SpotifyController function in PyChromecast

To help you get started, we’ve selected a few PyChromecast examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github balloob / pychromecast / examples / spotify_example.py View on Github external
spotify_device_id = None

# Create a spotify token
data = st.start_session(args.user, args.password)
access_token = data[0]
expires = data[1] - int(time.time())

# Create a spotify client
client = spotipy.Spotify(auth=access_token)
if args.show_debug:
    spotipy.trace = True
    spotipy.trace_out = True

# Launch the spotify app on the cast we want to cast to
sp = SpotifyController(access_token, expires)
cast.register_handler(sp)
sp.launch_app()

if not sp.is_launched and not sp.credential_error:
    print('Failed to launch spotify controller due to timeout')
    sys.exit(1)
if not sp.is_launched and sp.credential_error:
    print('Failed to launch spotify controller due to credential error')
    sys.exit(1)

# Query spotify for active devices
devices_available = client.devices()

# Match active spotify devices with the spotify controller's device id
for device in devices_available['devices']:
    if device['id'] == sp.device:
github guirem / plugin-googlecast / resources / pychromecast / examples / spotify_example.py View on Github external
spotify_device_id = None

# Create a spotify token
data = st.start_session(args.user, args.password)
access_token = data[0]
expires = data[1] - int(time.time())

# Create a spotify client
client = spotipy.Spotify(auth=access_token)
if args.show_debug:
    spotipy.trace = True
    spotipy.trace_out = True

# Launch the spotify app on the cast we want to cast to
sp = SpotifyController(access_token, expires)
cast.register_handler(sp)
sp.launch_app()

if not sp.is_launched and not sp.credential_error:
    print('Failed to launch spotify controller due to timeout')
    sys.exit(1)
if not sp.is_launched and sp.credential_error:
    print('Failed to launch spotify controller due to credential error')
    sys.exit(1)

# Query spotify for active devices
devices_available = client.devices()

# Match active spotify devices with the spotify controller's device id
for device in devices_available['devices']:
    if device['id'] == sp.device:
github Tsjippy / ChromecastPlugin / plugin.py View on Github external
Offset 			= {"uri": TrackInfo['items'][0]['track']['uri']}
			else:
				TrackId 		= [TrackInfo['items'][0]['track']['uri']]
		elif ContextUri != None:
				Offset 			= {"uri": TrackId}
				TrackId 		= None
		elif TrackId != None and ContextUri == None:
			TrackId 			= [TrackId]

		#Connect to chromecast
		ip 		= uri.split(":")[0]
		port 	= int(uri.split(":")[1])
		cc 		= pychromecast.Chromecast(ip,port)
		cc.start()
		cc.wait()
		sp 		= SpotifyController(_plugin.SpotifyAccessToken, _plugin.SpotifyExpiryTime)
		cc.register_handler(sp)

		#Launch spotify app on chromecast and find device id
		device_id = None
		sp.launch_app()
		if _plugin.Debug == True:
			q.put("Spotify started.")
		devices_available = _plugin.SpotifyClient.devices()
		for device in devices_available['devices']:
		    if device['name'] == cc.name:
		        device_id = device['id']
		        break


		if ContextUri != None:
			if _plugin.Debug == True:
github fondberg / spotcast / custom_components / spotcast / __init__.py View on Github external
def startSpotifyController(self, access_token, expires):
        from pychromecast.controllers.spotify import SpotifyController

        sp = SpotifyController(access_token, expires)
        self.castDevice.register_handler(sp)
        sp.launch_app()

        if not sp.is_launched and not sp.credential_error:
            raise HomeAssistantError("Failed to launch spotify controller due to timeout")
        if not sp.is_launched and sp.credential_error:
            raise HomeAssistantError("Failed to launch spotify controller due to credentials error")

        self.spotifyController = sp
github balloob / pychromecast / pychromecast / controllers / spotify.py View on Github external
def __init__(self, access_token, expires):
        super(SpotifyController, self).__init__(APP_NAMESPACE, APP_SPOTIFY)
        if access_token is None or expires is None:
            raise ValueError("access_token and expires cannot be empty")

        self.logger = logging.getLogger(__name__)
        self.session_started = False
        self.access_token = access_token
        self.expires = expires
        self.is_launched = False
        self.device = None
        self.credential_error = False
        self.waiting = threading.Event()