Ejemplo n.º 1
0
    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)
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
"""
Example code to show how you can start a YouTube movie
whenever the idle screen is shown.
"""
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)
Ejemplo n.º 4
0
 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)
Ejemplo n.º 5
0
"""
Examples of how PyChromecast can be used.
"""
from __future__ import print_function
import time

import pychromecast as pc

cast = pc.get_chromecast()
print(cast.device)
print("Current app:", cast.app)

# 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("kxopViU98Xo", cast=cast)
    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(10)

print("Ramp:", ramp)

print("Toggling play status")
Ejemplo n.º 6
0
#!/usr/bin/python

import time, sys

if (len(sys.argv) > 0):
    video = sys.argv[1]
else:
    video = "REjj1ruFQww"

try:
    import pychromecast
    pychromecast.play_youtube_video(video, pychromecast.PyChromecast().host)
except:
    pass
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
#!/usr/bin/python

import time, sys

if(len(sys.argv) > 0):
    video = sys.argv[1]
else:
    video = "REjj1ruFQww"

try:
    import pychromecast
    pychromecast.play_youtube_video(video, pychromecast.PyChromecast().host)
except:
    pass
Ejemplo n.º 9
0
 def play_youtube_video(self, video_id):
     """ Plays specified video_id on the Chromecast's YouTube channel. """
     pychromecast.play_youtube_video(video_id, self.cast.host)