def on_torrents_list_selection(update: Update, context: CallbackContext): logger.info('torrents list menu button from %s: %s', update.message.from_user.first_name, context.match[0]) qbfilter = context.match[0].replace("/", "") logger.info('torrents status: %s', qbfilter) update.message.reply_html( f"Listing torrents with status <code>{qbfilter}</code> (migth take some seconds):" ) torrents = qb.torrents(filter=qbfilter, sort='dlspeed', reverse=False, get_torrent_generic_properties=False) or [] logger.info('qbittirrent request returned %d torrents', len(torrents)) if not torrents: update.message.reply_html( 'There is no torrent to be listed for <i>{}</i>'.format(qbfilter)) return if qbfilter == 'completed': base_string = TORRENT_STRING_COMPLETED # use a shorter string with less info for completed torrents else: base_string = TORRENT_STRING_COMPACT strings_list = [ base_string.format(**torrent.dict()) for torrent in torrents ] for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk))
def on_torrents_list_selection(update: Update, context: CallbackContext): logger.info('torrents list menu button from %s: %s', update.message.from_user.first_name, context.match[0]) qbfilter = context.match[0] if qbfilter.startswith('/'): # remove the "/" if the category has been used as command qbfilter = qbfilter.replace('/', '') logger.info('torrents status: %s', qbfilter) torrents = qb.torrents(filter=qbfilter, sort='dlspeed', reverse=False) or [] if qbfilter == 'tostart': all_torrents = qb.torrents(filter='all') completed_torrents = [t.hash for t in qb.torrents(filter='completed')] active_torrents = [t.hash for t in qb.torrents(filter='active')] torrents = [t for t in all_torrents if t.hash not in completed_torrents and t.hash not in active_torrents] logger.info('qbittirrent request returned %d torrents', len(torrents)) if not torrents: update.message.reply_html('There is no torrent to be listed for <i>{}</i>'.format(qbfilter)) return if qbfilter == 'completed': base_string = TORRENT_STRING_COMPLETED # use a shorter string with less info for completed torrents else: base_string = TORRENT_STRING_COMPACT strings_list = [base_string.format(**torrent.dict()) for torrent in torrents] for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk))
def on_settings_command(update: Update, context: CallbackContext): logger.info('/settings from %s', update.effective_user.first_name) preferences = qb.preferences() lines = sorted(['{}: <code>{}</code>'.format(k, v) for k, v in preferences.items()]) for strings_chunk in u.split_text(lines): update.message.reply_html('\n'.join(strings_chunk), disable_web_page_preview=True)
def on_filter_command(update: Update, context: CallbackContext): logger.info('/filter command used by %s (query: %s)', update.effective_user.first_name, context.args) if not context.args[0:]: update.message.reply_text('Please provide a search term') return query = ' '.join(context.args[0:]) torrents = qb.filter(query) if not torrents: update.message.reply_text('No results for "{}"'.format(query)) return strings_list = [torrent.string() for torrent in torrents] for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk))
def on_filter_command(update: Update, context: CallbackContext): logger.info('/filter command used by %s (query: %s)', update.effective_user.first_name, context.args) if not context.args[0:]: update.message.reply_text('Please provide a search term') return query = ' '.join(context.args[0:]) torrents = qb.filter(query) if not torrents: update.message.reply_text('No results for "{}"'.format(query)) return base_string = "• <code>{short_name_escaped}</code> ({size_pretty}, {share_ratio_rounded}, {state_pretty}) [<a href=\"{info_deeplink}\">info</a>]" strings_list = [torrent.string(base_string=base_string) for torrent in torrents] for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk))
def on_priorities_command(update: Update, context: CallbackContext): logger.info('/priorities from %s', update.effective_user.first_name) torrents = qb.torrents(sort='priority', reverse=False) # filter out paused completed torrents non_completed_torrents = list() for torrent in torrents: if torrent.state in ('pausedUP', ): continue non_completed_torrents.append(torrent) if len(non_completed_torrents) == 25: # list must contain 25 torrents max break lines = [TORRENT_STRING.format(t=t) for t in non_completed_torrents] for strings_chunk in u.split_text(lines): update.message.reply_html('\n'.join(strings_chunk))
def on_atm_list_command(update: Update, context: CallbackContext): logger.info('/atmyes or /atmno command used by %s', update.effective_user.first_name) torrents = qb.torrents() atm_enabled = update.message.text.lower().endswith("atmyes") base_string = "• <code>{short_name}</code> ({size_pretty}, {state_pretty}) [<a href=\"{info_deeplink}\">info</a>]" strings_list = [torrent.string(base_string=base_string) for torrent in torrents if torrent['auto_tmm'] is atm_enabled] update.message.reply_html( f"There are <b>{len(strings_list)}/{len(torrents)}</b> torrents with " f"Automatic Torrent Management {'enabled' if atm_enabled else 'disabled'}:" ) if not strings_list: update.message.reply_text("-") return for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk))
def on_filter_command(_, update, args): logger.info('/filter command used by %s (query: %s)', update.effective_user.first_name, args) if not args[0:]: update.message.reply_text('Please provide a search term') return query = ' '.join(args[0:]) torrents = qb.filter(query) if not torrents: update.message.reply_text('No results for "{}"'.format(query)) return strings_list = [torrent.string() for torrent in torrents] for strings_chunk in u.split_text(strings_list): update.message.reply_html('\n'.join(strings_chunk), disable_web_page_preview=True)