def get_global_speed_limit(self): p = self.preferences() return ( u.get_human_readable(p['dl_limit']) if p['dl_limit'] else None, u.get_human_readable(p['up_limit']) if p['up_limit'] else None )
def get_speed(self): tinfo = self.global_transfer_info return ( u.get_human_readable(tinfo['dl_info_speed']), u.get_human_readable(tinfo['up_info_speed']) )
def get_alt_speed(self, human_readable=True): p = self.preferences() result = dict() if human_readable: result['status'] = 'on' if self.get_alternative_speed_status() else 'off' result['alt_dl_limit'] = u.get_human_readable(p['alt_dl_limit'], 0) if p['alt_dl_limit'] > -1 else 'none' result['alt_up_limit'] = u.get_human_readable(p['alt_up_limit'], 0) if p['alt_up_limit'] > -1 else 'none' else: result['status'] = bool(self.get_alternative_speed_status()) result['alt_dl_limit'] = p['alt_dl_limit'] if p['alt_dl_limit'] > -1 else None result['alt_up_limit'] = p['alt_up_limit'] if p['alt_up_limit'] > -1 else None return result
def get_speed_text(): fdict = {} transfer_info = qb.global_transfer_info fdict['current_download_speed'] = u.get_human_readable( transfer_info['dl_info_speed']) fdict['current_upload_speed'] = u.get_human_readable( transfer_info['up_info_speed']) fdict['session_total_upload'] = u.get_human_readable( transfer_info['up_info_data']) fdict['session_total_download'] = u.get_human_readable( transfer_info['dl_info_data']) if transfer_info['dl_info_data'] > 0: fdict['session_share_rateo'] = round( transfer_info['up_info_data'] / transfer_info['dl_info_data'], 2) else: fdict['session_share_rateo'] = 0 preferences = qb.preferences() fdict['global_down_limit'] = u.get_human_readable( preferences['dl_limit']) if preferences['dl_limit'] else 'none' fdict['global_up_limit'] = u.get_human_readable( preferences['up_limit']) if preferences['up_limit'] else 'none' fdict['alt_speed_status'] = 'on' if qb.get_alternative_speed_status( ) else 'off' fdict['alt_speed_down'] = u.get_human_readable( preferences['alt_dl_limit'], 0) if preferences['alt_dl_limit'] > -1 else 'none' fdict['alt_speed_up'] = u.get_human_readable( preferences['alt_up_limit'], 0) if preferences['alt_up_limit'] > -1 else 'none' fdict['queueing_max_active_downloads'] = preferences[ 'max_active_downloads'] fdict['queueing_max_active_uploads'] = preferences['max_active_uploads'] fdict['queueing_max_active_torrents'] = preferences['max_active_torrents'] fdict['queueing_count_slow_torrents'] = 'no' if preferences[ 'dont_count_slow_torrents'] else 'yes' fdict['queueing_slow_torrent_down_threshold'] = preferences[ 'slow_torrent_dl_rate_threshold'] fdict['queueing_slow_torrent_up_threshold'] = preferences[ 'slow_torrent_ul_rate_threshold'] fdict['queueing_slow_torrent_inactive_timer'] = preferences[ 'slow_torrent_inactive_timer'] fdict['max_ratio_enabled'] = "yes" if preferences[ 'max_ratio_enabled'] else "no" fdict['max_ratio'] = preferences['max_ratio'] fdict['max_seeding_time_enabled'] = "yes" if preferences[ 'max_seeding_time_enabled'] else "no" fdict['max_seeding_time'] = preferences['max_seeding_time'] fdict['max_ratio_act'] = "pause" if preferences[ 'max_ratio_act'] == 0 else "remove" # 0 = pause them, 1 = remove them return TEXT.format(**fdict)
def _enrich_torrent_dict(self): if 'progress' in self._torrent_dict: self._torrent_dict['eta'] = 0 if self._torrent_dict['progress'] == 1 else self._torrent_dict['eta'] # set eta = 0 for completed torrents self._torrent_dict['progress_bar'] = u.build_progress_bar(self._torrent_dict['progress']) if 'hash' in self._torrent_dict: self._torrent_dict['manage_deeplink'] = 'https://t.me/{}?start=manage{}'.format( self._qbt._bot_username, self._torrent_dict['hash'] ) self._torrent_dict['info_deeplink'] = 'https://t.me/{}?start=info{}'.format( self._qbt._bot_username, self._torrent_dict['hash'] ) self._torrent_dict['short_name'] = self._torrent_dict['name'] if len(self._torrent_dict['name']) > 51: self._torrent_dict['short_name'] = self._torrent_dict['name'][:51].strip() + '...' self._torrent_dict['short_name_escaped'] = u.html_escape(self._torrent_dict['short_name']) self._torrent_dict['generic_speed'] = self._torrent_dict['dlspeed'] icon = '▼' if self._torrent_dict['state'] in ('uploading', 'forcedUP', 'stalledUP'): self._torrent_dict['generic_speed'] = self._torrent_dict['upspeed'] icon = '▲' generic_speed_human_readable = u.get_human_readable(self._torrent_dict['generic_speed']) self._torrent_dict['traffic_direction_icon'] = f"{icon}" for k, v in NEW_ATTRS.items(): try: self._torrent_dict[k] = v(self._torrent_dict) except KeyError: # it might be that one of the lambdas uses a key that is not available in the torrent dict, # eg. when get_additional_torrent_properties is not True continue
'downloading': 'downloading', 'allocating': 'allocating disk space', 'stalledDL': 'stalled (downloading)', 'metaDL': 'fetching metadata', 'checkingResumeData': 'startup: checking data', 'moving': 'moving', 'unknown': 'unknown status' } # https://github.com/qbittorrent/qBittorrent/wiki/Web-API-Documentation#get-torrent-list # https://github.com/qbittorrent/qBittorrent/wiki/Web-API-Documentation#get-torrent-generic-properties NEW_ATTRS = { 'state_pretty': lambda t: STATES_DICT.get(t['state'], t['state']), 'size_pretty': lambda t: u.get_human_readable(t['total_size'] ), # already a string apparently 'dl_speed_pretty': lambda t: u.get_human_readable(t['dl_speed']), 'up_speed_pretty': lambda t: u.get_human_readable(t['up_speed']), 'dlspeed_pretty': lambda t: u.get_human_readable(t['dlspeed']), 'upspeed_pretty': lambda t: u.get_human_readable(t['upspeed']), 'generic_speed_pretty': lambda t: u.get_human_readable(t['generic_speed']), 'progress_pretty': lambda t: round(t['progress'] * 100), 'eta_pretty': lambda t: str(datetime.timedelta(seconds=t['eta']) ), # apparently it's already a string?
'metaDL': 'fetching metadata', 'pausedDL': 'paused (download not finished)', 'queuedDL': 'queued for download', 'stalledDL': 'stalled (downloading)', 'checkingDL': 'checking file (downloading)', 'forcedDL': 'forced download', 'checkingResumeData': 'startup: checking data', 'moving': 'moving', 'unknown': 'unknown status' } # https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-list # https://github.com/qbittorrent/qBittorrent/wiki/WebUI-API-(qBittorrent-4.1)#get-torrent-generic-properties NEW_ATTRS = { 'state_pretty': lambda t: STATES_DICT.get(t['state'], t['state']), 'size_pretty': lambda t: u.get_human_readable(t['total_size']), # already a string apparently 'dl_speed_pretty': lambda t: u.get_human_readable(t['dl_speed']), 'up_speed_pretty': lambda t: u.get_human_readable(t['up_speed']), 'dlspeed_pretty': lambda t: u.get_human_readable(t['dlspeed']), 'upspeed_pretty': lambda t: u.get_human_readable(t['upspeed']), 'name_escaped': lambda t: u.html_escape(t['name']), 'generic_speed_pretty': lambda t: u.get_human_readable(t['generic_speed']), 'progress_pretty': lambda t: math.floor(t['progress'] * 100), # eg. 99.9% should be rounded to 99% 'eta_pretty': lambda t: str(datetime.timedelta(seconds=t['eta'])), # apparently it's already a string? 'time_elapsed_pretty': lambda t: str(datetime.timedelta(seconds=t['time_elapsed'])), 'force_start_pretty': lambda t: 'yes' if t['force_start'] else 'no', 'share_ratio_rounded': lambda t: round(t['ratio'], 2), 'dl_limit_pretty': lambda t: 'no limit' if t['dl_limit'] == -1 else u.get_human_readable(t['dl_limit']), 'auto_tmm_string': lambda t: 'yes' if t['auto_tmm'] else 'no', }