def stream_ready(self, result):
        if result['status'] == 'success':
            if result.get('use_stream_urls', False):
                url = "stream+%s" % result['url']
                if result.get('auto_open_stream_urls', False):
                    threads.deferToThread(execute_url, url)
                else:
                    def on_dialog_callback(response):
                        if response == Gtk.ResponseType.YES:
                            threads.deferToThread(execute_url, url)

                    dialogs.YesNoDialog('Stream ready', 'Do you want to play the video?').run().addCallback(on_dialog_callback)
            else:
                dialogs.ErrorDialog('Stream ready', 'Copy the link into a media player', details=result['url']).run()
        else:
            dialogs.ErrorDialog('Stream failed', 'Was unable to prepare the stream', details=result).run()
 def on_apply(self, widget):
     try:
         options = self.generate_opts()
         self.gtkui.store[self.item_id][0] = options["urls"][0]
         self.gtkui.trackers[self.item_index]["url"] = options["urls"][0]
     except Exception as err:
         dialogs.ErrorDialog("Error", str(err), self.dialog).run()
 def on_apply(self, event=None):
     try:
         options = self.generate_opts()
         client.autoaddplus.set_options(str(self.watchdir_id), options).addCallbacks(
             self.on_added, self.on_error_show
         )
     except IncompatibleOption as ex:
         dialogs.ErrorDialog(_('Incompatible Option'), str(ex), self.dialog).run()
 def on_add(self, widget):
     try:
         options = self.generate_opts()
         for url in options["urls"]:
             if not self.in_store(url):
                 self.gtkui.store.append([url])
                 self.gtkui.trackers.append({"url": url})
     except Exception as err:
         dialogs.ErrorDialog("Error", str(err), self.dialog).run()
    def on_apply_prefs(self):
        log.debug("applying prefs for Streaming")

        serve_method = 'standalone'
        # if self.builder.get_object("input_serve_standalone").get_active():
        #     serve_method = 'standalone'
        # elif self.builder.get_object("input_serve_webui").get_active():
        #     serve_method = 'webui'

        if self.builder.get_object("input_ssl_cert_daemon").get_active():
            ssl_source = 'daemon'
        elif self.builder.get_object("input_ssl_cert_custom").get_active():
            ssl_source = 'custom'

        config = {
            "ip": self.builder.get_object("input_ip").get_text(),
            "port": int(self.builder.get_object("input_port").get_text()),
            "use_stream_urls": self.builder.get_object("input_use_stream_urls").get_active(),
            "auto_open_stream_urls": self.builder.get_object("input_auto_open_stream_urls").get_active(),
            "aggressive_prioritizing": self.builder.get_object("input_aggressive_prioritizing").get_active(),
            "allow_remote": self.builder.get_object("input_allow_remote").get_active(),
            "download_only_streamed": self.builder.get_object("input_download_only_streamed").get_active(),
            "reverse_proxy_enabled": self.builder.get_object("input_reverse_proxy_enabled").get_active(),
            # "download_in_order": self.builder.get_object("input_download_in_order").get_active(),
            "use_ssl": self.builder.get_object("input_use_ssl").get_active(),
            # "remote_username": self.builder.get_object("input_remote_username").get_text(),
            "reverse_proxy_base_url": self.builder.get_object("input_reverse_proxy_base_url").get_text(),
            "remote_password": self.builder.get_object("input_remote_password").get_text(),
            "ssl_priv_key_path": self.builder.get_object("input_ssl_priv_key_path").get_text(),
            "ssl_cert_path": self.builder.get_object("input_ssl_cert_path").get_text(),
            "serve_method": serve_method,
            "ssl_source": ssl_source,
        }

        result = yield client.streaming.set_config(config)

        if result:
            message_type, message_class, message = result
            if message_type == 'error':
                topic = 'Unknown error type'
                if message_class == 'ssl':
                    topic = 'SSL Failed'

                dialogs.ErrorDialog(topic, message).run()
 def on_error_show(self, result):
     d = dialogs.ErrorDialog(_('Error'), result.value.exception_msg, self.dialog)
     result.cleanFailure()
     d.run()