Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def run(self):
if not self.args["rhost"] and not self.args["name"]:
print_info("Show options, it's necessary to configure onename or rhost")
return
if str(self.args["timeout"]) == "None":
self.args["timeout"] = 6
try:
chromecasts = pychromecast.get_chromecasts(timeout=self.args["timeout"])
cast = next(cc for cc in chromecasts if (cc.device.friendly_name == self.args["name"] or cc.host == self.args["rhost"]))
cast.wait()
print_info("Device found, sending video")
except:
print_error("Device no found")
return
yt = YouTubeController()
cast.register_handler(yt)
yt.play_video(self.args["video"])
print_ok("Done!")
"""
"""
def main_loop():
def callback(chromecast):
print('found', chromecast)
DashboardLauncher(chromecast, dashboard_url='http://192.168.1.132:8080')
pychromecast.get_chromecasts(blocking=False, callback=callback)
while True:
time.sleep(1)
main_loop()
"""
casts = pychromecast.get_chromecasts()
if len(casts) == 0:
print('No Devices Found')
exit()
cast = next(cc for cc in casts if DISPLAY_NAME in (None, '') or cc.device.friendly_name == DISPLAY_NAME)
if not cast:
print('Chromecast with name', DISPLAY_NAME, 'not found')
exit()
DashboardLauncher(cast, dashboard_url=DASHBOARD_URL)
# Keep running
while True:
time.sleep(1)
#!/usr/bin/python3
from __future__ import print_function
import sys; sys.path.insert(0,'/usr/local/lib/python3.6/dist-packages/')
import time
import pychromecast #https://github.com/balloob/pychromecast/tree/master/pychromecast sudo pip3 install pychromecast --upgrade
from gtts import gTTS #https://github.com/pndurette/gTTS sudo pip3 install gTTS --upgrade
#import sys
URL_DOMOTICZ = 'http://192.168.100.248:8080/' # renseigner l'adresse et le port de votre domoticz
for arg in sys.argv:
print(arg)
tts = gTTS(text=arg, lang='fr', slow=False)
tts.save("/home/pi/domoticz/www/notification.mp3")
chromecasts = pychromecast.get_chromecasts()
[cc.device.friendly_name for cc in chromecasts]
['Salon','Bureau'] # mettre le nom de votre chromecast séparé par une virgule ex: ['douche', 'salon', 'cuisine', 'chambre']
cast = next(cc for cc in chromecasts if cc.device.friendly_name == "Salon" )
cast.wait()
mc = cast.media_controller
mc.play_media(URL_DOMOTICZ+'notification.mp3', 'audio/mp3')
mc.block_until_active()
mc.pause()
time.sleep(1)
def setup(self):
if self.isPluginActivated:
return
shell = self.get_property("shell")
player = shell.get_property("shell-player")
self.shell = shell
self.player = player
self.db = shell.get_property("db")
self.chromecast = pychromecast.get_chromecast(friendly_name=Prefs.chromecastName)
self.chromecast.wait()
# self.chromecastPlayer = self.chromecast.media_controller
self.chromecastListeners = ChromecastListeners.ChromecastListeners(self.chromecast)
self.shell_cb_ids = (
self.player.connect('playing-song-changed', self.chromecastListeners.song_changed_cb),
self.player.connect('playing-changed', self.chromecastListeners.player_changed_cb)
)
self.draw_sidebar()
model = self.get_property("query-model")
playing_entry = player.get_playing_entry()
# If the current playing entry is not in the playing source's
def __init__(self, stream_url):
self.stream_url = stream_url
logger.info("Searching for Chromecast devices...")
chromecast_list = pychromecast.get_chromecasts_as_dict().keys()
logger.debug("Found Chromecasts: %s", chromecast_list)
if not chromecast_list:
raise RuntimeError("Unable to find a Chromecast on the local network.")
chromecast_name = chromecast_list[0]
if len(chromecast_list) > 1:
logger.warn("Multiple Chromecast devices detected, using defaulting to Chromecast '%s'", chromecast_name)
logger.info("Connecting to Chromecast '%s'", chromecast_name)
self.chromecast = pychromecast.get_chromecast(
friendly_name=chromecast_name)
self.chromecast.wait()
logger.info("Connected to Chromecast '%s'", chromecast_name)
def server(device):
global cast
global device_name
print('>> trying to connect to {}'.format(device))
device_name = device
cast = pychromecast.get_chromecast(friendly_name=device)
if cast is None:
click.echo("Couldn't find device '{}'".format(device))
sys.exit(-1)
print(repr(cast))
print('connected, starting up...')
app.run('0.0.0.0', 8183)
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')
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()
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
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)