How to use the pychromecast.Chromecast 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 shivasiddharth / GassistPi / src / actions.py View on Github external
def chromecast_play_video(phrase):
    # Chromecast declarations
    # Do not rename/change "TV" its a variable
    TV = pychromecast.Chromecast("192.168.1.13") #Change ip to match the ip-address of your Chromecast
    mc = TV.media_controller
    idx1=phrase.find(custom_action_keyword['Dict']['Play'])
    idx2=phrase.find('on chromecast')
    query=phrase[idx1:idx2]
    query=query.replace(custom_action_keyword['Dict']['Play'],'',1)
    query=query.replace('on chromecast','',1)
    query=query.strip()
    youtubelinks=youtube_search(query)
    youtubeurl=youtubelinks[0]
    streams=youtube_stream_link(youtubeurl)
    videostream=streams[1]
    TV.wait()
    time.sleep(1)
    mc.play_media(videostream,'video/mp4')
github shivasiddharth / GassistPi / src / actions.py View on Github external
def chromecast_control(action):
    # Chromecast declarations
    # Do not rename/change "TV" its a variable
    TV = pychromecast.Chromecast("192.168.1.13") #Change ip to match the ip-address of your Chromecast
    mc = TV.media_controller
    if 'pause'.lower() in str(action).lower():
        TV.wait()
        time.sleep(1)
        mc.pause()
    if 'resume'.lower() in str(action).lower():
        TV.wait()
        time.sleep(1)
        mc.play()
    if 'end'.lower() in str(action).lower():
        TV.wait()
        time.sleep(1)
        mc.stop()
    if 'volume'.lower() in str(action).lower():
        if 'up'.lower() in str(action).lower():
            TV.wait()
github Tsjippy / ChromecastPlugin / plugin.py View on Github external
if TrackInfo['items'][0]['context'] != None:
				ContextUri 		= TrackInfo['items'][0]['context']['uri']
				ContextType 	= TrackInfo['items'][0]['context']['type']
				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
github shivasiddharth / pi-gcast-remote / g-cast-controller.py View on Github external
def button_c(button, pressed):
               cast=pychromecast.Chromecast(chromecasts_ip[1])
               mc = cast.media_controller
               cast.wait()
               time.sleep(1)
               mc.stop()
           @buttonshim.on_press(buttonshim.BUTTON_D)
github d8ahazard / FlexTV.bundle / Contents / Code / __init__.py View on Github external
STEPBACKWARD Need to test, not in PHP cast app)
    PREVIOUS
    NEXT
    MUTE
    UNMUTE
    VOLUME - also requires an int representing level from 0-100

    """
    Log.Debug('Recieved a call to control playback')
    params = sort_headers(['Uri', 'Cmd', 'Val'], False)
    status = "Missing paramaters"
    response = "Error"

    if params is not False:
        uri = params['Uri'].split(":")
        cast = pychromecast.Chromecast(uri[0], int(uri[1]))
        cast.wait()
        pc = PlexController(cast)
        Log.Debug("Handler namespace is %s" % pc.namespace)
        cast.register_handler(pc)

        Log.Debug("Handler namespace is %s" % pc.namespace)

        cmd = params['Cmd']
        Log.Debug("Command is " + cmd)

        if cmd == "play":
            pc.play()
        if cmd == "pause":
            pc.pause()
        if cmd == "stop":
            pc.stop()
github shivasiddharth / pi-gcast-remote / g-cast-controller.py View on Github external
def button_b(button, pressed):
               cast=pychromecast.Chromecast(chromecasts_ip[0])
               mc = cast.media_controller
               cast.wait()
               time.sleep(1)
               mc.play()
           @buttonshim.on_press(buttonshim.BUTTON_C)
github skorokithakis / catt / catt / controllers.py View on Github external
def get_chromecast_with_ip(device_ip, port=DEFAULT_PORT):
    try:
        # tries = 1 is necessary in order to stop pychromecast engaging
        # in a retry behaviour when ip is correct, but port is wrong.
        return pychromecast.Chromecast(device_ip, port=port, tries=1)
    except pychromecast.error.ChromecastConnectionError:
        return None
github home-assistant / home-assistant / homeassistant / components / cast / media_player.py View on Github external
def __init__(self, cast_info: ChromecastInfo):
        """Initialize the cast device."""

        self._cast_info = cast_info
        self.services = None
        if cast_info.service:
            self.services = set()
            self.services.add(cast_info.service)
        self._chromecast: Optional[pychromecast.Chromecast] = None
        self.cast_status = None
        self.media_status = None
        self.media_status_received = None
        self._dynamic_group_cast_info: ChromecastInfo = None
        self._dynamic_group_cast: Optional[pychromecast.Chromecast] = None
        self.dynamic_group_media_status = None
        self.dynamic_group_media_status_received = None
        self.mz_media_status = {}
        self.mz_media_status_received = {}
        self.mz_mgr = None
        self._available = False
        self._dynamic_group_available = False
        self._status_listener: Optional[CastStatusListener] = None
        self._dynamic_group_status_listener: Optional[
            DynamicGroupCastStatusListener
        ] = None
        self._hass_cast_controller: Optional[HomeAssistantController] = None

        self._add_remove_handler = None
        self._del_remove_handler = None
        self._cast_view_remove_handler = None
github tizonia / tizonia-openmax-il / clients / chromecast / chromecastproxy / tizchromecastproxy.py View on Github external
def activate(self, cast_status_listener, media_status_listener):
        self.cast = pychromecast.Chromecast(self.name_or_ip, blocking=False)
        self.cast_status_listener = cast_status_listener
        self.media_status_listener = media_status_listener
        self.cast.register_status_listener(self)
        self.cast.media_controller.register_status_listener(self)
        print_nfo("[Chromecast] [{0}] [Activating]" \
                  .format(to_ascii(self.name_or_ip)))
        self.cast.start_app(APP_MEDIA_RECEIVER)
        self.active = True
github keredson / gnomecast / gnomecast.py View on Github external
dialogWindow.set_title('Add a non-local Chromecast')

    dialogBox = dialogWindow.get_content_area()
    userEntry = Gtk.Entry()
#    userEntry.set_size_request(250,0)
    dialogBox.pack_end(userEntry, False, False, 0)

    dialogWindow.show_all()
    response = dialogWindow.run()
    text = userEntry.get_text()
    dialogWindow.destroy()
    if (response == Gtk.ResponseType.OK) and (text != ''):
      print(text)
      try:
        cast = pychromecast.Chromecast(text)
        self.cast_store.append([cast, text])
        self.cast_combo.set_active(len(self.cast_store)-1)
      except pychromecast.error.ChromecastConnectionError:
        dialog = Gtk.MessageDialog(self.win, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CLOSE, "Chromecast Not Found")
        dialog.format_secondary_text("The Chromecast '%s' wasn't found." % text)
        dialog.run()
        dialog.destroy()