def fill( self, jobinfo ): self.hash_code = jobinfo["hash"] self.trackers = jobinfo["trackers"].strip().split( "\r\n\r\n" ) self.ulrate = jobinfo["ulrate"] self.ulrate_h = utorrent.human_size( self.ulrate ) + "/s" self.dlrate = jobinfo["dlrate"] self.dlrate_h = utorrent.human_size( self.dlrate ) + "/s" self.superseed = jobinfo["superseed"] self.dht = jobinfo["dht"] self.pex = jobinfo["pex"] self.seed_override = jobinfo["seed_override"] self.seed_ratio = jobinfo["seed_ratio"] self.seed_time = jobinfo["seed_time"]
def progress( loaded, total ): global bar_width, increm, start_time progr = int( round( loaded / increm ) ) if increm > 0 else 1 delta = datetime.datetime.now( ) - start_time delta = delta.seconds + delta.microseconds / 1000000 if opts.verbose: print_console( "[{}{}] {} {}/s eta: {}{}".format( "*" * progr, "_" * ( bar_width - progr ), utorrent_module.human_size( total ), utorrent_module.human_size( loaded / delta ), utorrent_module.human_time_delta( ( total - loaded ) / ( loaded / delta ) if loaded > 0 else 0 ), " " * 25 ), sep = "", end = "" ) print_console( "\b" * ( bar_width + 70 ), end = "" ) sys.stdout.flush( )
def progress(range_start, loaded, total): global bar_width, tick_size, start_time if range_start is None: range_start = 0 progr = int(round((range_start + loaded) / tick_size)) if tick_size > 0 else 1 delta = datetime.datetime.now() - start_time delta = delta.seconds + delta.microseconds / 1000000 if opts.verbose: print_console("[{}{}] {} {}/s eta: {}{}".format( "*" * progr, "_" * (bar_width - progr), utorrent_module.human_size(total), utorrent_module.human_size(loaded / delta), utorrent_module.human_time_delta( (total - loaded) / (loaded / delta) if loaded > 0 else 0), " " * 25), sep="", end="") print_console("\b" * (bar_width + 70), end="") sys.stdout.flush()
def fill( self, torrent ): self.hash_code, status, self.name, self.size, progress, self.downloaded, \ self.uploaded, ratio, self.ul_speed, self.dl_speed, self.eta, self.label, \ self.peers_connected, self.peers_total, self.seeds_connected, self.seeds_total, \ self.availability, self.queue_order, self.dl_remain = torrent self._utorrent.check_hash( self.hash_code ) self.progress = progress / 10. self.ratio = ratio / 1000. self.status = TorrentStatus( status, self.progress ) self.size_h = utorrent.human_size( self.size ) self.uploaded_h = utorrent.human_size( self.uploaded ) self.downloaded_h = utorrent.human_size( self.downloaded ) self.ul_speed_h = utorrent.human_size( self.ul_speed ) + "/s" self.dl_speed_h = utorrent.human_size( self.dl_speed ) + "/s" self.eta_h = utorrent.human_time_delta( self.eta ) self.availability_h = self.availability / 65535. self.dl_remain_h = utorrent.human_size( self.dl_remain )
for h, t in sorted( utorrent.torrent_list( ).items( ), key = lambda x: getattr( x[1], opts.sort_field ), reverse = opts.sort_desc ): if not opts.active or opts.active and ( t.ul_speed > 0 or t.dl_speed > 0 ): # handle --active if opts.label is None or opts.label == t.label: # handle --label count += 1 if opts.limit > 0 and count > opts.limit: break total_size += t.progress / 100 * t.size if opts.verbose: print_console( t.verbose_str( opts.format ) ) total_ul += t.ul_speed total_dl += t.dl_speed else: print_console( t ) if opts.verbose: print_console( "Total speed: D:{}/s U:{}/s count: {} size: {}".format( utorrent_module.human_size( total_dl ), utorrent_module.human_size( total_ul ), count, utorrent_module.human_size( total_size ) ) ) elif opts.action == "add_file": for i in args: print_console( "Submitting {}...".format( i ) ) hsh = utorrent.torrent_add_file( i, opts.download_dir ) print_console( level1 + "Info hash = {}".format( hsh ) ) if opts.force: print_console( level1 + "Forcing start..." ) utorrent.torrent_start( hsh, True ) elif opts.action == "add_url": for i in args: print_console( "Submitting {}...".format( i ) )
t.ul_speed > 0 or t.dl_speed > 0): # handle --active if opts.label is None or opts.label == t.label: # handle --label count += 1 if opts.limit > 0 and count > opts.limit: break total_size += t.progress / 100 * t.size if opts.verbose: print_console(t.verbose_str(opts.format)) total_ul += t.ul_speed total_dl += t.dl_speed else: print_console(t) if opts.verbose: print_console( "Total speed: D:{}/s U:{}/s count: {} size: {}".format( utorrent_module.human_size(total_dl), utorrent_module.human_size(total_ul), count, utorrent_module.human_size(total_size))) elif opts.action == "add_file": for i in args: print_console("Submitting {}...".format(i)) hsh = utorrent.torrent_add_file(i, opts.download_dir) print_console(level1 + "Info hash = {}".format(hsh)) if opts.force: print_console(level1 + "Forcing start...") utorrent.torrent_start(hsh, True) elif opts.action == "add_url": for i in args: print_console("Submitting {}...".format(i))
def get_stats(self, time_frame='1d'): res = self._conn.xfer_history_get() try: excl_local = self._conn.settings_get()["net.limit_excludeslocal"] except self._conn.uTorrentError: return "Failed to fetch Statistics." torrents = self._conn.torrent_list() today_start = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) period = len(res["daily_download"]) period_start = today_start - datetime.timedelta(days=period - 1) down_total_local = sum(res["daily_local_download"]) down_total = sum( res["daily_download"]) - (down_total_local if excl_local else 0) up_total_local = sum(res["daily_local_upload"]) up_total = sum( res["daily_upload"]) - (down_total_local if excl_local else 0) period_added_torrents = { k: v for k, v in torrents.items() if v.added_on >= period_start } period_completed_torrents = { k: v for k, v in torrents.items() if v.completed_on >= period_start } stat_msg = "" if time_frame == '31d': stat_msg += "Last {} days:\n".format(period) stat_msg += level1 + "Downloaded: {} (+{} local)\n".format( utorrent_module.human_size(down_total), utorrent_module.human_size(down_total_local)) stat_msg += level1 + " Uploaded: {} (+{} local)\n".format( utorrent_module.human_size(up_total), utorrent_module.human_size(up_total_local)) stat_msg += level1 + " Total: {} (+{} local)\n".format( utorrent_module.human_size(down_total + up_total), utorrent_module.human_size(down_total_local + up_total_local)) stat_msg += level1 + "Ratio: {:.2f}\n".format( up_total / down_total) stat_msg += level1 + "Added torrents: {}\n".format( len(period_added_torrents)) stat_msg += level1 + "Completed torrents: {}\n".format( len(period_completed_torrents)) elif time_frame == '1d': down_day_local = res["daily_local_download"][0] down_day = res["daily_download"][0] - (down_day_local if excl_local else 0) up_day_local = res["daily_local_upload"][0] up_day = res["daily_upload"][0] - (up_day_local if excl_local else 0) today_added_torrents = { k: v for k, v in torrents.items() if v.added_on >= today_start } today_completed_torrents = { k: v for k, v in torrents.items() if v.completed_on >= today_start } stat_msg += "Today:" stat_msg += level1 + "Downloaded: {} (+{} local)\n".format( utorrent_module.human_size(down_day), utorrent_module.human_size(down_day_local)) stat_msg += level1 + " Uploaded: {} (+{} local)\n".format( utorrent_module.human_size(up_day), utorrent_module.human_size(up_day_local)) stat_msg += level1 + " Total: {} (+{} local)\n".format( utorrent_module.human_size(down_day + up_day), utorrent_module.human_size(down_day_local + up_day_local)) stat_msg += level1 + "Ratio: {:.2f}\n".format(up_day / down_day) stat_msg += level1 + "Added torrents: {}\n".format( len(today_added_torrents)) stat_msg += level1 + "Completed torrents: {}\n".format( len(today_completed_torrents)) return stat_msg
def get_stats(self, time_frame='1d'): res = self._conn.xfer_history_get() try: excl_local = self._conn.settings_get()["net.limit_excludeslocal"] except self._conn.uTorrentError: return "Failed to fetch Statistics." torrents = self._conn.torrent_list() today_start = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) period = len(res["daily_download"]) period_start = today_start - datetime.timedelta(days=period - 1) down_total_local = sum(res["daily_local_download"]) down_total = sum(res["daily_download"]) - (down_total_local if excl_local else 0) up_total_local = sum(res["daily_local_upload"]) up_total = sum(res["daily_upload"]) - (down_total_local if excl_local else 0) period_added_torrents = {k: v for k, v in torrents.items() if v.added_on >= period_start} period_completed_torrents = {k: v for k, v in torrents.items() if v.completed_on >= period_start} stat_msg = "" if time_frame == '31d': stat_msg += "Last {} days:\n".format(period) stat_msg += level1 + "Downloaded: {} (+{} local)\n".format(utorrent_module.human_size(down_total), utorrent_module.human_size(down_total_local)) stat_msg += level1 + " Uploaded: {} (+{} local)\n".format(utorrent_module.human_size(up_total), utorrent_module.human_size(up_total_local)) stat_msg += level1 + " Total: {} (+{} local)\n".format( utorrent_module.human_size(down_total + up_total), utorrent_module.human_size( down_total_local + up_total_local)) stat_msg += level1 + "Ratio: {:.2f}\n".format(up_total / down_total) stat_msg += level1 + "Added torrents: {}\n".format(len(period_added_torrents)) stat_msg += level1 + "Completed torrents: {}\n".format(len(period_completed_torrents)) elif time_frame == '1d': down_day_local = res["daily_local_download"][0] down_day = res["daily_download"][0] - (down_day_local if excl_local else 0) up_day_local = res["daily_local_upload"][0] up_day = res["daily_upload"][0] - (up_day_local if excl_local else 0) today_added_torrents = {k: v for k, v in torrents.items() if v.added_on >= today_start} today_completed_torrents = {k: v for k, v in torrents.items() if v.completed_on >= today_start} stat_msg += "Today:" stat_msg += level1 + "Downloaded: {} (+{} local)\n".format(utorrent_module.human_size(down_day), utorrent_module.human_size(down_day_local)) stat_msg += level1 + " Uploaded: {} (+{} local)\n".format(utorrent_module.human_size(up_day), utorrent_module.human_size(up_day_local)) stat_msg += level1 + " Total: {} (+{} local)\n".format(utorrent_module.human_size(down_day + up_day), utorrent_module.human_size( down_day_local + up_day_local)) stat_msg += level1 + "Ratio: {:.2f}\n".format(up_day / down_day) stat_msg += level1 + "Added torrents: {}\n".format(len(today_added_torrents)) stat_msg += level1 + "Completed torrents: {}\n".format(len(today_completed_torrents)) return stat_msg