def torrent_info_callback(message, data) -> None: torrent = qbittorrent_control.get_torrent_info(data=int(data)) progress = torrent.progress * 100 text = "" if progress == 0: text += f"{torrent.name}\n[ ] " \ f"{round(progress, 2)}% completed\n" \ f"State: {torrent.state.capitalize()}\n" \ f"Download Speed: {convert_size(torrent.dlspeed)}/s\n" \ f"Size: {convert_size(torrent.size)}\nETA: " \ f"{convert_eta(int(torrent.eta))}\n\n" elif progress == 100: text += f"{torrent.name}\n[completed] " \ f"{round(progress, 2)}% completed\n" \ f"State: {torrent.state.capitalize()}\n" \ f"Upload Speed: {convert_size(torrent.upspeed)}/s\n\n" else: text += f"{torrent.name}\n[{'=' * int(progress / 10)}" \ f"{' ' * int(12 - (progress / 10))}]" \ f" {round(progress, 2)}% completed\n" \ f"State: {torrent.state.capitalize()} \n" \ f"Download Speed: {convert_size(torrent.dlspeed)}/s\n" \ f"Size: {convert_size(torrent.size)}\nETA: " \ f"{convert_eta(int(torrent.eta))}\n\n" btn = botogram.Buttons() btn[0].callback("⏸ Pause", "pause", data) btn[0].callback("▶️ Resume", "resume", data) btn[1].callback("🗑 Delete", "delete_one", data) btn[2].callback("🔙 Menu", "menu") message.edit(text, attach=btn)
def list_active_torrents(n, chat, message, callback) -> None: torrents = qbittorrent_control.get_torrent_info() if not torrents: btn = botogram.Buttons() btn[0].callback("🔙 Menu", "menu") try: message.edit("There are no torrents", attach=btn) except botogram.api.APIError: chat.send("There are no torrents", attach=btn) return btn = botogram.Buttons() if n == 1: for key, i in enumerate(torrents): btn[key].callback(i.name, callback, str(key)) btn[key + 1].callback("🔙 Menu", "menu") try: message.edit_attach(btn) except botogram.api.APIError: chat.send("Qbitorrent Control", attach=btn) else: for key, i in enumerate(torrents): btn[key].callback(i.name, "torrentInfo", str(key)) btn[key + 1].callback("🔙 Menu", "menu") try: message.edit_attach(btn) except botogram.api.APIError: chat.send("Qbitorrent Control", attach=btn)
def torrent_info_callback(client: Client, callback_query: CallbackQuery) -> None: torrent = qbittorrent_control.get_torrent_info( data=int(callback_query.data.split("#")[1])) progress = torrent.progress * 100 text = "" if progress == 0: text += f"{torrent.name}\n[ ] " \ f"{round(progress, 2)}% completed\n" \ f"State: {torrent.state.capitalize()}\n" \ f"Download Speed: {convert_size(torrent.dlspeed)}/s\n" \ f"Size: {convert_size(torrent.size)}\nETA: " \ f"{convert_eta(int(torrent.eta))}\n" \ f"Category: {torrent.category}\n" elif progress == 100: text += f"{torrent.name}\n[completed] " \ f"{round(progress, 2)}% completed\n" \ f"State: {torrent.state.capitalize()}\n" \ f"Upload Speed: {convert_size(torrent.upspeed)}/s\n" \ f"Category: {torrent.category}\n" else: text += f"{torrent.name}\n[{'=' * int(progress / 10)}" \ f"{' ' * int(12 - (progress / 10))}]" \ f" {round(progress, 2)}% completed\n" \ f"State: {torrent.state.capitalize()} \n" \ f"Download Speed: {convert_size(torrent.dlspeed)}/s\n" \ f"Size: {convert_size(torrent.size)}\nETA: " \ f"{convert_eta(int(torrent.eta))}\n" \ f"Category: {torrent.category}\n" buttons = [[ InlineKeyboardButton("⏸ Pause", f"pause#{callback_query.data.split('#')[1]}") ], [ InlineKeyboardButton( "▶️ Resume", f"resume#{callback_query.data.split('#')[1]}") ], [ InlineKeyboardButton( "🗑 Delete", f"delete_one#{callback_query.data.split('#')[1]}") ], [InlineKeyboardButton("🔙 Menu", "menu")]] app.edit_message_text(callback_query.from_user.id, callback_query.message.message_id, text=text, reply_markup=InlineKeyboardMarkup(buttons))
def torrent_finished(): for i in qbittorrent_control.get_torrent_info(): if i.progress == 1 and \ db_management.read_completed_torrents(i.hash) is None \ and get_configs().notify: for j in get_configs().id: try: bot.chat(j).send(f"torrent {i.name} has " f"finished downloading!") except botogram.api.ChatUnavailableError: pass db_management.write_completed_torrents(i.hash)
def torrent_finished(self): for i in qbittorrent_control.get_torrent_info(): if i.progress == 1 and \ db_management.read_completed_torrents(i.hash) is None \ and NOTIFY: for user_id in AUTHORIZED_IDS: try: self.app.send_message( user_id, f"torrent {i.name} has finished downloading!") except UserIsBlocked: pass db_management.write_completed_torrents(i.hash)
def list_active_torrents(n, chat, message, callback, status_filter: str = None) -> None: torrents = qbittorrent_control.get_torrent_info( status_filter=status_filter) def render_categories_buttons(): return [ InlineKeyboardButton( f"⏳ {'*' if status_filter == 'downloading' else ''} Downloading", "by_status_list#downloading"), InlineKeyboardButton( f"✔️ {'*' if status_filter == 'completed' else ''} Completed", "by_status_list#completed"), InlineKeyboardButton( f"⏸️ {'*' if status_filter == 'paused' else ''} Paused", "by_status_list#paused"), ] categories_buttons = render_categories_buttons() if not torrents: buttons = [ categories_buttons, [InlineKeyboardButton("🔙 Menu", "menu")] ] try: app.edit_message_text(chat, message, "There are no torrents", reply_markup=InlineKeyboardMarkup(buttons)) except MessageIdInvalid: app.send_message(chat, "There are no torrents", reply_markup=InlineKeyboardMarkup(buttons)) return buttons = [categories_buttons] if n == 1: for key, i in enumerate(torrents): buttons.append( [InlineKeyboardButton(i.name, f"{callback}#{key+1}")]) buttons.append([InlineKeyboardButton("🔙 Menu", "menu")]) try: app.edit_message_reply_markup( chat, message, reply_markup=InlineKeyboardMarkup(buttons)) except MessageIdInvalid: app.send_message(chat, "Qbittorrent Control", reply_markup=InlineKeyboardMarkup(buttons)) else: for key, i in enumerate(torrents): buttons.append( [InlineKeyboardButton(i.name, f"torrentInfo#{key+1}")]) buttons.append([InlineKeyboardButton("🔙 Menu", "menu")]) try: app.edit_message_reply_markup( chat, message, reply_markup=InlineKeyboardMarkup(buttons)) except MessageIdInvalid: app.send_message(chat, "Qbittorrent Control", reply_markup=InlineKeyboardMarkup(buttons))