Exemple #1
0
    def __init__(self, pack: XDCCPack, retry: bool = False):
        """
        Initializes the XDCC IRC client
        :param pack: The pack to downloadX
        :param retry: Set to true for retried downloads.
        """
        self.logger = Logger()

        # Save us from decoding errors!
        irc.client.ServerConnection.buffer_class.errors = "replace"

        self.user = User()
        self.pack = pack
        self.server = pack.server
        self.downloading = False
        self.xdcc_timestamp = 0
        self.channels = None  # change to list if channel joins are required
        self.message_sent = False
        self.connect_start_time = 0

        # XDCC state variables
        self.peer_address = ""
        self.peer_port = -1
        self.filesize = -1
        self.progress = 0
        self.xdcc_file = None
        self.xdcc_connection = None
        self.retry = retry

        if not self.retry:
            if self.download_limit == -1:
                limit = "\"unlimited\""
            else:
                limit = str(self.download_limit)
            self.logger.info("Download Limit set to: " + limit)

        super().__init__()
Exemple #2
0
    def __init__(self,
                 pack: XDCCPack,
                 retry: bool = False,
                 timeout: int = 120,
                 fallback_channel: Optional[str] = None,
                 throttle: Union[int, str] = -1):
        """
        Initializes the XDCC IRC client
        :param pack: The pack to downloadX
        :param retry: Set to true for retried downloads.
        :param timeout: Sets the timeout time for starting downloads
        :param fallback_channel: A fallback channel for when whois
                                 fails to find a valid channel
        :param throttle: Throttles the download to n bytes per second.
                         If this value is <= 0, the download speed will be
                         unlimited
        """
        self.logger = ColorLogger(logging.getLogger(self.__class__.__name__),
                                  warning_bg=Back.RED,
                                  warning_fg=Fore.BLACK)

        # Save us from decoding errors and excessive logging output!
        irc.client.ServerConnection.buffer_class.errors = "replace"
        irc.client.log.setLevel(logging.ERROR)

        if isinstance(throttle, str):
            self.download_limit = byte_string_to_byte_count(throttle)
        else:
            self.download_limit = throttle
        if self.download_limit <= 0:
            self.download_limit = -1

        self.user = User()
        self.pack = pack
        self.server = pack.server
        self.downloading = False
        self.xdcc_timestamp = 0.0
        self.channels = None  # type: Optional[List[str]]
        self.message_sent = False
        self.connect_start_time = 0.0
        self.timeout = timeout
        self.timed_out = False
        self.fallback_channel = fallback_channel
        self.connected = True
        self.disconnected = False

        # XDCC state variables
        self.peer_address = ""
        self.peer_port = -1
        self.filesize = -1
        self.progress = 0
        self.xdcc_file = None  # type: Optional[IO[Any]]
        self.xdcc_connection = None  # type: Optional[DCCConnection]
        self.retry = retry
        self.struct_format = b"!I"
        self.ack_lock = Lock()

        if not self.retry:
            if self.download_limit == -1:
                limit = "\"unlimited\""
            else:
                limit = str(self.download_limit)
            self.logger.info("Download Limit set to: " + limit)

        self.timeout_watcher_thread = Thread(target=self.timeout_watcher)
        self.progress_printer_thread = Thread(target=self.progress_printer)

        super().__init__()