def on_text(client: Client, message: Message) -> None: action = db_management.read_support(message.from_user.id) if "magnet" in action: if message.text.startswith("magnet:?xt"): magnet_link = message.text.split("\n") category = db_management.read_support( message.from_user.id).split("#")[1] qbittorrent_control.add_magnet(magnet_link=magnet_link, category=category) send_menu(message.message_id, message.from_user.id) db_management.write_support("None", message.from_user.id) else: message.reply_text("This magnet link is invalid! Retry") elif "torrent" in action and message.document: if ".torrent" in message.document.file_name: with tempfile.TemporaryDirectory() as tempdir: name = f"{tempdir}/{message.document.file_name}" category = db_management.read_support( message.from_user.id).split("#")[1] message.download(name) qbittorrent_control.add_torrent(file_name=name, category=category) send_menu(message.message_id, message.from_user.id) db_management.write_support("None", message.from_user.id) else: message.reply_text("This is not a torrent file! Retry") elif action == "category_name": db_management.write_support(f"category_dir#{message.text}", message.from_user.id) message.reply_text( f"now send me the path for the category {message.text}") elif "category_dir" in action: if os.path.exists(message.text): name = db_management.read_support( message.from_user.id).split("#")[1] if "modify" in action: qbittorrent_control.edit_category(name=name, save_path=message.text) send_menu(message.message_id, message.from_user.id) return qbittorrent_control.create_category(name=name, save_path=message.text) send_menu(message.message_id, message.from_user.id) else: message.reply_text("The path entered does not exist! Retry")
def add_task(message: Message): try: msg = message.reply_text("```Downloading video...```", quote=True) filepath = message.download(file_name=download_dir) msg.edit("```Encoding video...```") new_file = encode(filepath) if new_file: msg.edit("```Video Encoded, getting metadata...```") duration = get_duration(new_file) thumb = get_thumbnail(new_file, download_dir, duration / 4) width, height = get_width_height(new_file) msg.edit("```Uploading video...```") message.reply_video(new_file, quote=True, supports_streaming=True, thumb=thumb, duration=duration, width=width, height=height) os.remove(new_file) os.remove(thumb) msg.edit("```Video Encoded to x265```") else: msg.edit( "```Something wents wrong while encoding your file. Make sure it is not already in HEVC format.```" ) os.remove(filepath) except Exception as e: msg.edit(f"```{e}```") on_task_complete()
def get_image( msg: Message, name="".join(random.choices(string.ascii_letters, k=50)) ) -> PIL.Image.Image: path = f"tmp/{name}" msg.download(file_name=path) return PIL.Image.open(path)