Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def PlayVideo(self):
cast = pc.PyChromecast()
print cast.device
# Make sure an app is running that supports RAMP protocol
if not cast.app or pc.PROTOCOL_RAMP not in cast.app.service_protocols:
pc.play_youtube_video(YOUTUBE_SUFFIX, cast.host)
cast.refresh()
ramp = cast.get_protocol(pc.PROTOCOL_RAMP)
# It can take some time to setup websocket connection
# if we just switched to a new channel
while not ramp:
time.sleep(1)
ramp = cast.get_protocol(pc.PROTOCOL_RAMP)
# Give ramp some time to init
time.sleep(1)
from __future__ import print_function
import time
import pychromecast
if __name__ == "__main__":
cast = pychromecast.get_chromecast(strict=False)
print(u"Monitoring {}".format(cast.device.friendly_name))
while True:
cast.refresh()
if cast.app_id == pychromecast.APP_ID['HOME']:
print("Hey, we are on the home screen :( Starting YouTube..")
pychromecast.play_youtube_video("kxopViU98Xo", cast=cast)
time.sleep(10)
def play_youtube_video_service(service, video_id):
""" Plays specified video_id on the Chromecast's YouTube channel. """
if video_id: # if service.data.get('video') returned None
for entity_id, cast in _service_to_entities(service):
pychromecast.play_youtube_video(video_id, cast.host)
update_chromecast_state(entity_id, cast)