diff --git a/locales/en-US/sub_extractor.json b/locales/en-US/sub_extractor.json index bb15631d..75f0dfc9 100644 --- a/locales/en-US/sub_extractor.json +++ b/locales/en-US/sub_extractor.json @@ -3,7 +3,6 @@ "conv_sub_help": "Use command /{cmd} by reply to .ass or .vtt file, to convert subtitle from .ass or .vtt to srt.", "progress_str": "⏳ Processing your request..", "convert_str": "⏳ Converting...", - "val_sec": " second", "unauth_cb": "⚠️ Access Denied!", "cancel_btn": "❌ Cancel", "invalid_cb": "⚠️ DONT DELETE YOUR MESSAGE!", diff --git a/locales/id-ID/sub_extractor.json b/locales/id-ID/sub_extractor.json index 73fc1743..99afa61b 100644 --- a/locales/id-ID/sub_extractor.json +++ b/locales/id-ID/sub_extractor.json @@ -2,8 +2,7 @@ "sub_extr_help": "Harap gunakan perintah /{cmd} [tautan] untuk memeriksa teks film atau audio dalam berkas video.", "conv_sub_help": "Gunakan perintah /{cmd} dengan membalas berkas .ass atau .vtt, untuk mengonversi teks film dari .ass atau .vtt ke srt.", "progress_str": "⏳ Memproses permintaan Anda..", - "convert_str": "⏳ Mengonversi...", - "val_sec": " detik", + "convert_str": "⏳ Mengkonversi...", "unauth_cb": "⚠️ Akses Ditolak!", "batal_btn": "❌ Batal", "invalid_cb": "⚠️ JANGAN HAPUS PESAN ANDA!", diff --git a/locales/id-JW/sub_extractor.json b/locales/id-JW/sub_extractor.json index 09d1ef39..693e28c2 100644 --- a/locales/id-JW/sub_extractor.json +++ b/locales/id-JW/sub_extractor.json @@ -3,9 +3,8 @@ "conv_sub_help": "Gunakake printah /{cmd} kanthi mbales berkas .ass utawa .vtt, kanggo ngowahi subtitle saka .ass utawa .vtt dadi srt.", "progress_str": "⏳ Ngolah panjalukmu..", "convert_str": "⏳ Ngonversi...", - "val_sec": "Kapindho", "unauth_cb": "⚠️ Akses Ditolak!", - "cancel_btn": "❌ Batal", + "cancel_btn": "❌ Rasido", "invalid_cb": "⚠️ AJA Mbusak PESAN!", "up_str": "Ngunggahaké berkas..", "press_btn_msg": "Pencet tombol ing ngisor iki kanggo ngekstrak subtitle/audio. Mung ndhukung link langsung saiki.\nDiproses ing {timelog}", diff --git a/misskaty/helper/pyro_progress.py b/misskaty/helper/pyro_progress.py index 86f755e6..bc3c7572 100644 --- a/misskaty/helper/pyro_progress.py +++ b/misskaty/helper/pyro_progress.py @@ -9,7 +9,7 @@ import time from pyrogram.errors import FloodWait, MessageNotModified, MessageIdInvalid -async def progress_for_pyrogram(current, total, ud_type, message, start): +async def progress_for_pyrogram(current, total, ud_type, message, start, dc_id): """generic progress display for Telegram Upload / Download status""" now = time.time() diff = now - start @@ -32,10 +32,11 @@ async def progress_for_pyrogram(current, total, ud_type, message, start): round(percentage, 2), ) - tmp = progress + "{0} of {1}\nSpeed: {2}/s\nETA: {3}\n".format( + tmp = progress + "{0} of {1}\nSpeed: {2}/s\nDC ID: {3}\nETA: {4}\n".format( humanbytes(current), humanbytes(total), humanbytes(speed), + dc_id, estimated_total_time if estimated_total_time != "" else "0 s", ) try: diff --git a/misskaty/plugins/afk.py b/misskaty/plugins/afk.py index 3dc3c5bd..2d22930f 100644 --- a/misskaty/plugins/afk.py +++ b/misskaty/plugins/afk.py @@ -214,7 +214,7 @@ async def afk_state(self: Client, ctx: Message, strings): group=1, ) @use_chat_lang() -async def chat_watcher_func(self: Client, ctx: Message, strings): +async def afk_watcher_func(self: Client, ctx: Message, strings): if ctx.sender_chat: return userid = ctx.from_user.id diff --git a/misskaty/plugins/download_upload.py b/misskaty/plugins/download_upload.py index e61d6e36..f44fa166 100644 --- a/misskaty/plugins/download_upload.py +++ b/misskaty/plugins/download_upload.py @@ -6,6 +6,7 @@ from datetime import datetime from logging import getLogger from pyrogram import filters +from pyrogram.file_id import FileId from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup from pySmartDL import SmartDL @@ -35,16 +36,16 @@ __HELP__ = """ async def upload(bot, message): if not message.reply_to_message: return await message.reply("Please reply to media file.") - if message.reply_to_message is not None: - vid = [message.reply_to_message.video, message.reply_to_message.document] - for v in vid: - if v is not None: - break + vid = [message.reply_to_message.video, message.reply_to_message.document, message.reply_to_message.audio, message.reply_to_message.photo] + media = next((v for v in vid if v is not None), None) + if not media: + return await message.reply("Unsupported media type..") m = await message.reply("Download your file to my Server...") now = time.time() + dc_id = FileId.decode(media.file_id).dc_id fileku = await message.reply_to_message.download( progress=progress_for_pyrogram, - progress_args=("Trying to download, please wait..", m, now), + progress_args=("Trying to download, please wait..", m, now, dc_id), ) try: files = {"file": open(fileku, "rb")} @@ -67,10 +68,15 @@ async def download(client, message): if message.reply_to_message is not None: start_t = datetime.now() c_time = time.time() + vid = [message.reply_to_message.video, message.reply_to_message.document, message.reply_to_message.audio, message.reply_to_message.photo] + media = next((v for v in vid if v is not None), None) + if not media: + return await pesan.edit_msg("Unsupported media type..") + dc_id = FileId.decode(media.file_id).dc_id the_real_download_location = await client.download_media( message=message.reply_to_message, progress=progress_for_pyrogram, - progress_args=("trying to download, sabar yakk..", pesan, c_time), + progress_args=("Trying to download, sabar yakk..", pesan, c_time, dc_id), ) end_t = datetime.now() ms = (end_t - start_t).seconds diff --git a/misskaty/plugins/genss.py b/misskaty/plugins/genss.py index 776fdec1..a5403769 100644 --- a/misskaty/plugins/genss.py +++ b/misskaty/plugins/genss.py @@ -13,6 +13,7 @@ from logging import getLogger from pyrogram import enums, filters, Client from pyrogram.errors import FloodWait +from pyrogram.file_id import FileId from pyrogram.types import InlineKeyboardMarkup, Message, CallbackQuery from misskaty import app @@ -62,10 +63,11 @@ async def genss(self: Client, ctx: Message, strings): if media.file_size > 2097152000: return await process.edit_msg(strings("limit_dl")) c_time = time.time() + dc_id = FileId.decode(media.file_id).dc_id dl = await replied.download( file_name="/downloads/", progress=progress_for_pyrogram, - progress_args=(strings("dl_progress"), process, c_time), + progress_args=(strings("dl_progress"), process, c_time, dc_id), ) the_real_download_location = os.path.join("/downloads/", os.path.basename(dl)) if the_real_download_location is not None: diff --git a/misskaty/plugins/sub_extractor.py b/misskaty/plugins/media_extractor.py similarity index 91% rename from misskaty/plugins/sub_extractor.py rename to misskaty/plugins/media_extractor.py index 38ae31e0..62020eb5 100644 --- a/misskaty/plugins/sub_extractor.py +++ b/misskaty/plugins/media_extractor.py @@ -9,7 +9,7 @@ import os from logging import getLogger from re import I from re import split as ngesplit -from time import perf_counter, time +from time import time from urllib.parse import unquote from pyrogram import filters, Client @@ -22,6 +22,7 @@ from misskaty.core.misskaty_patch.listen.listen import ListenerTimeout from misskaty.helper.pyro_progress import progress_for_pyrogram from misskaty.helper.tools import get_random_string from misskaty.helper.localization import use_chat_lang +from misskaty.helper.human_read import get_readable_time from misskaty.plugins.dev import shell_exec from misskaty.vars import COMMAND_HANDLER @@ -57,8 +58,8 @@ def get_subname(lang, url, format): fragment_removed = url.split("#")[0] # keep to left of first # query_string_removed = fragment_removed.split("?")[0] scheme_removed = query_string_removed.split("://")[-1].split(":")[-1] - if scheme_removed.find("/") == -1: - return f"[{lang.upper()}] MissKatySub_{get_random_string(4)}.{format}" + if scheme_removed.find("/") == -1 or not get_base_name(os.path.basename(unquote(scheme_removed))): + return f"[{lang.upper()}] MissKatySub{get_random_string(4)}.{format}" return f"[{lang.upper()}] {get_base_name(os.path.basename(unquote(scheme_removed)))}.{format}" @@ -69,7 +70,7 @@ async def ceksub(self: Client, ctx: Message, strings): if len(ctx.command) == 1: return await ctx.reply_msg(strings("sub_extr_help").format(cmd=ctx.command[0]), quote=True, del_in=5) link = ctx.command[1] - start_time = perf_counter() + start_time = time() pesan = await ctx.reply_msg(strings("progress_str"), quote=True) try: res = (await shell_exec(f"ffprobe -loglevel 0 -print_format json -show_format -show_streams {link}"))[0] @@ -96,11 +97,10 @@ async def ceksub(self: Client, ctx: Message, strings): ) ] ) - end_time = perf_counter() - timelog = "{:.2f}".format(end_time - start_time) + strings("val_sec") + timelog = time() - start_time buttons.append([InlineKeyboardButton(strings("cancel_btn"), f"close#{ctx.from_user.id}")]) msg = await pesan.edit_msg( - strings("press_btn_msg").format(timelog=timelog), + strings("press_btn_msg").format(timelog=get_readable_time(timelog)), reply_markup=InlineKeyboardMarkup(buttons), ) await msg.wait_for_click( @@ -134,7 +134,7 @@ async def convertsrt(self: Client, ctx: Message, strings): caption=strings("capt_conv_sub").format(nf=filename, bot=self.me.username), thumb="assets/thumb.jpg", progress=progress_for_pyrogram, - progress_args=(strings("up_str"), msg, c_time), + progress_args=(strings("up_str"), msg, c_time, self.me.dc_id), ) await msg.delete_msg() try: @@ -166,21 +166,20 @@ async def stream_extract(self: Client, update: CallbackQuery, strings): format = "eac3" else: format = "srt" - start_time = perf_counter() + start_time = time() namafile = get_subname(lang, link, format) try: LOGGER.info(f"ExtractSub: {namafile} by {update.from_user.first_name} [{update.from_user.id}]") (await shell_exec(f"mediaextract -i {link} -map {map} '{namafile}'"))[0] - end_time = perf_counter() - timelog = "{:.2f}".format(end_time - start_time) + strings("val_sec") + timelog = time() - start_time c_time = time() await update.message.reply_document( namafile, - caption=strings("capt_extr_sub").format(nf=namafile, bot=self.me.username, timelog=timelog), + caption=strings("capt_extr_sub").format(nf=namafile, bot=self.me.username, timelog=get_readable_time(timelog)), reply_to_message_id=usr.id, thumb="assets/thumb.jpg", progress=progress_for_pyrogram, - progress_args=(strings("up_str"), update.message, c_time), + progress_args=(strings("up_str"), update.message, c_time, self.me.dc_id), ) await update.message.delete_msg() try: diff --git a/misskaty/plugins/mediainfo.py b/misskaty/plugins/mediainfo.py index 21467b2c..b6edad91 100644 --- a/misskaty/plugins/mediainfo.py +++ b/misskaty/plugins/mediainfo.py @@ -11,6 +11,7 @@ import time from os import remove as osremove, path from pyrogram import filters, Client +from pyrogram.file_id import FileId from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, Message from misskaty import app @@ -36,10 +37,11 @@ async def mediainfo(self: Client, ctx: Message, strings): if (ctx.reply_to_message.video and ctx.reply_to_message.video.file_size > 2097152000) or (ctx.reply_to_message.document and ctx.reply_to_message.document.file_size > 2097152000): return await process.edit_msg(strings("dl_limit_exceeded"), del_in=6) c_time = time.time() + dc_id = FileId.decode(file_info.file_id).dc_id dl = await ctx.reply_to_message.download( file_name="/downloads/", progress=progress_for_pyrogram, - progress_args=(strings("dl_args_text"), process, c_time), + progress_args=(strings("dl_args_text"), process, c_time, dc_id), ) file_path = path.join("/downloads/", path.basename(dl)) output_ = await runcmd(f'mediainfo "{file_path}"') diff --git a/misskaty/plugins/ocr.py b/misskaty/plugins/ocr.py index a5a03022..bdd3bad8 100644 --- a/misskaty/plugins/ocr.py +++ b/misskaty/plugins/ocr.py @@ -30,13 +30,13 @@ __HELP__ = "/ocr [reply to photo] - Read Text From Image" @use_chat_lang() async def ocr(self: Client, ctx: Message, strings): reply = ctx.reply_to_message - if not reply or not reply.photo and (reply.document and not reply.document.mime_type.startswith("image")) and not reply.sticker: + if not reply and not reply.photo or not (reply.document and reply.document.mime_type.startswith("image")) or not reply.sticker: return await ctx.reply_msg(strings("no_photo").format(cmd=ctx.command[0]), quote=True, del_in=6) msg = await ctx.reply_msg(strings("read_ocr"), quote=True) try: file_path = await reply.download() if reply.sticker: - file_path = await reply.download(f"ocr_{ctx.from_user.id}.jpg") + file_path = await reply.download(f"ocr_{ctx.from_user.id if ctx.from_user else ctx.sender_chat.id}.jpg") response = await Telegraph().upload_file(file_path) url = f"https://telegra.ph{response[0]['src']}" req = ( @@ -46,7 +46,13 @@ async def ocr(self: Client, ctx: Message, strings): ) ).json() await msg.edit_msg(strings("result_ocr").format(result=req["text"])) - os.remove(file_path) + try: + os.remove(file_path) + except: + pass except Exception as e: await msg.edit_msg(str(e)) - os.remove(file_path) + try: + os.remove(file_path) + except: + pass