From 26844048f358c301a687054809005b09c57669f2 Mon Sep 17 00:00:00 2001 From: X-Gorn Date: Mon, 10 Jun 2024 11:22:58 +0900 Subject: [PATCH] fix: ffile not found --- Bot/functions/dl_button.py | 8 ++------ Bot/functions/youtube_dl_button.py | 13 +++++++++---- Bot/translation.py | 3 +-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Bot/functions/dl_button.py b/Bot/functions/dl_button.py index 8131805..37ca7fe 100644 --- a/Bot/functions/dl_button.py +++ b/Bot/functions/dl_button.py @@ -163,9 +163,6 @@ async def ddl_call_back(bot: Client, update: CallbackQuery): audio=download_directory, caption=description, duration=duration, - # performer=response_json["uploader"], - # title=response_json["title"], - # reply_markup=reply_markup, thumb=thumb_image_path, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, @@ -181,7 +178,6 @@ async def ddl_call_back(bot: Client, update: CallbackQuery): document=download_directory, thumb=thumb_image_path, caption=description, - # reply_markup=reply_markup, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, progress_args=( @@ -214,7 +210,6 @@ async def ddl_call_back(bot: Client, update: CallbackQuery): width=width, height=height, supports_streaming=True, - # reply_markup=reply_markup, thumb=thumb_image_path, reply_to_message_id=update.message.reply_to_message.id, progress=progress_for_pyrogram, @@ -229,7 +224,8 @@ async def ddl_call_back(bot: Client, update: CallbackQuery): await media.copy(client.config.DUMP_ID, caption=f'User Name: {update.from_user.first_name}\nUser ID: {update.from_user.id}\nLink: {youtube_dl_url}') os.remove(download_directory) if not client.custom_thumbnail.get(update.from_user.id): - os.remove(thumb_image_path) + if thumb_image_path and os.path.isfile(thumb_image_path): + os.remove(thumb_image_path) time_taken_for_download = (end_one - start).seconds time_taken_for_upload = (end_two - end_one).seconds await bot.edit_message_text( diff --git a/Bot/functions/youtube_dl_button.py b/Bot/functions/youtube_dl_button.py index 915587a..fe3e9ae 100644 --- a/Bot/functions/youtube_dl_button.py +++ b/Bot/functions/youtube_dl_button.py @@ -168,7 +168,12 @@ async def youtube_dl_call_back(bot: Client, update: CallbackQuery): try: file_size = os.stat(download_directory).st_size except FileNotFoundError: - download_directory = download_directory + "." + "mkv" + if os.path.isfile(download_directory + "." + "mkv"): + download_directory = download_directory + "." + "mkv" + elif os.path.isfile(download_directory + "." + "webm"): + download_directory = download_directory + "." + "webm" + else: + return await update.message.edit(text='File not found in the directory.') # https://stackoverflow.com/a/678242/4723940 file_size = os.stat(download_directory).st_size if file_size > client.config.TG_MAX_FILE_SIZE: @@ -313,14 +318,13 @@ async def youtube_dl_call_back(bot: Client, update: CallbackQuery): media_album_p: list[InputMediaPhoto] = [] if images: i = 0 - caption = "@xurluploaderbot" for image in images: if os.path.exists(str(image)): if i == 0: media_album_p.append( InputMediaPhoto( media=image, - caption=caption, + caption=bot.me.first_name, parse_mode=enums.ParseMode.HTML ) ) @@ -343,7 +347,8 @@ async def youtube_dl_call_back(bot: Client, update: CallbackQuery): os.remove(photo.media) os.remove(download_directory) if not client.custom_thumbnail.get(update.from_user.id): - os.remove(thumb_image_path) + if thumb_image_path and os.path.isfile(thumb_image_path): + os.remove(thumb_image_path) await bot.edit_message_text( text=client.translation.AFTER_SUCCESSFUL_UPLOAD_MSG_WITH_TS.format( time_taken_for_download, time_taken_for_upload), diff --git a/Bot/translation.py b/Bot/translation.py index 0421d18..090b4d3 100644 --- a/Bot/translation.py +++ b/Bot/translation.py @@ -7,8 +7,7 @@ class Translation(object): DOWNLOAD_START = "Downloading..." UPLOAD_START = "Uploading..." RCHD_TG_API_LIMIT = "Downloaded in {} seconds.\nDetected File Size: {}\nSorry. But, I cannot upload files greater than 2GB due to Telegram API limitations." - AFTER_SUCCESSFUL_UPLOAD_MSG = "Thanks for using @xurluploaderbot)" - AFTER_SUCCESSFUL_UPLOAD_MSG_WITH_TS = "Downloaded in {} seconds.\nUploaded in {} seconds.\n\n@xurluploaderbot" + AFTER_SUCCESSFUL_UPLOAD_MSG_WITH_TS = "Downloaded in {} seconds.\nUploaded in {} seconds." SAVED_CUSTOM_THUMB_NAIL = "Custom video / file thumbnail saved. This image will be used in the video / file." DEL_ETED_CUSTOM_THUMB_NAIL = "✅ Custom thumbnail cleared succesfully." CUSTOM_CAPTION_UL_FILE = "{}"