Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
colors.important("Information about ")
+ " "
+ colors.success(self.cast_to)
)
print(" ")
print(self.cast.device)
print(" ")
print(
colors.important("Status of device ")
+ " "
+ colors.success(self.cast_to)
)
print(" ")
print(self.cast.status)
print(" ")
except pychromecast.error.NoChromecastFoundError:
print(
colors.error(
"No Chromecasts matching filter criteria" " were found!"
)
)
if self.platform == "Darwin":
inputint()
outputint()
elif self.platform == "Linux":
remove_sink()
# In the case that the tray is used, we don't kill the
# application
if self.tray is False:
print(colors.error("Finishing the application..."))
terminate()
exit()
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
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()
"""
Creates and returns a RAMP client based on the supplied app status.
Will return None if RAMP client is not supported.
Will raise ValueError if unable to retrieve the websocket url.
"""
# Check if current app has no service url or no protocols.
if not app_status.service_url or not app_status.service_protocols:
return None
req = requests.post(app_status.service_url,
data="{}".encode("ascii"),
headers={"Content-Type": "application/json"})
if req.status_code != 200:
raise error.ChromecastConnectionError(
"Could not retrieve websocket url ({}).".format(req.status_code))
conn_data = json.loads(req.text)
client = ChromecastWebSocketClient(conn_data['URL'],
app_status.service_protocols)
client.connect()
atexit.register(_clean_open_clients)
return client
def wait_for(self, states: list, invert: bool = False, fail: bool = False, timeout: Optional[int] = None) -> bool:
media_listener = MediaStatusListener(
self._cast.media_controller.status.player_state, states, invert=invert, fail=fail
)
self._cast.media_controller.register_status_listener(media_listener)
try:
return media_listener.wait_for_states(timeout=timeout)
except pychromecast.error.UnsupportedNamespace:
raise CastError("Chromecast app operation was interrupted")
# Only certain applications make sense to scrobble.
if current_app not in self.app_whitelist:
return
# Certain operating modes do not support the
# `media_controller.update_status()` call. Placing a device into a cast
# group is one such case. When running in this config, the cast.app_id
# is reported as 'MultizoneLeader'. Ensure we skip.
if self.cast.app_id in UNSUPPORTED_MODES:
return
# This can raise an exception when device is part of a multizone group
# (apparently `app_id` isn't sufficient)
try:
self.cast.media_controller.update_status()
except pychromecast.error.UnsupportedNamespace:
return
status = self.cast.media_controller.status
# Ignore when the player is paused.
if not status.player_is_playing:
return
# Triggered when we poll in between songs (see issue #6)
if status.current_time is None or status.duration is None or \
status.duration <= 0:
return
# Triggered when song is repeated and starting again after the first
# time
if status.duration < self.current_time:
self.reset_audio()
try:
self.kill_child()
except psutil.NoSuchProcess:
pass
checkmktmp()
self.search_cast()
# This is to retry when stopping and
# pychromecast.error.NotConnected raises.
if chromecast:
while True:
try:
self.cast.quit_app()
except pychromecast.error.NotConnected:
continue
except AttributeError:
# This is for sonos. The thing is that if we are at this
# point, user requested an stop or cast failed.
self.cast.stop()
break
self.stopped = True
self.read_config()
if platform == "Darwin" and self.notifications == "enabled":
if self.pcastfailed is True:
stop = [
"./notifier/terminal-notifier.app/Contents/MacOS/terminal-notifier",
"-group",
"cast",