Ejemplo n.º 1
0
 def run(self):
     logs.print_info("Oczekiwanie na handshake...")
     msg = self.conn.read()
     Thread(target=self.__pinger).start()
     buff = ""
     while not self.__was_stopped:
         buff += msg
         self.last_seen = datetime.datetime.now()
         if "\n" in msg:
             esc_string = buff[: buff.index("\n")]
             buff = buff[buff.index("\n") + 1 :]
             data = json.loads(un_escape(esc_string))
             logs.print_debug("RECEIVED: %s" % data)
             if "request" in data:
                 Thread(target=partial(self.binder.handle_message, data, self.conn)).start()
         while not self.__is_connected:
             pass
         try:
             msg = self.conn.read()
         except socket.error as e:
             logs.print_warning("socket.error while waiting for server request: %s" % e)
             self.__is_connected = False
         if not msg:
             logs.print_warning("Serwer zamknął połączenie")
             self.__is_connected = False
Ejemplo n.º 2
0
 def reconnect(self):
     logs.print_info("Próba ponownego nawiązania połączenia")
     try:
         self.conn.close()
     except Exception as e:
         logs.print_debug("exception while closing connection in reconnecting: %s" % e)
     self.conn = ssl.wrap_socket(socket.socket(socket.AF_INET, socket.SOCK_STREAM))
     self.binder.set_connection(self.conn)
     try:
         self.conn.settimeout(10)
         self.conn.connect((config.server_host, config.server_port))
         self.conn.settimeout(None)
         self.__is_connected = True
         self.last_seen = datetime.datetime.now()
         logs.print_info("Nawiązano połączenie ponownie")
     except socket.error as e:
         logs.print_warning("exception while trying to reconnect: %s " % e)
Ejemplo n.º 3
0
    def start_download(self):
        if self.downloader is None:
            try:
                method = self.queue[0].url.split(';')[0]
                url = self.queue[0].url.split(';')[1]
                if method == "youtube-dl":
                    self.downloader = YoutubeDLDownloadThread(url)
                    logs.print_debug("Starting download of %s with youtube-dl" % url)
                else:
                    logs.print_error("Unknown download method %s" % method)
                    return
                self.downloader.start()
            except IndexError as e:
                logs.print_error("Syntax error in URL: %s" % e)

        else:
            logs.print_warning("Download thread already exists")