Trying fix ocr and conversrt

This commit is contained in:
yasirarism 2023-05-29 14:17:45 +00:00 committed by GitHub
parent 4a72e140f2
commit 375be9672c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 45 deletions

View file

@ -119,8 +119,7 @@ async def ceksub(self: Client, ctx: Message, strings):
@use_chat_lang()
async def convertsrt(self: Client, ctx: Message, strings):
reply = ctx.reply_to_message
if not reply or not reply.document and not (reply.document.file_name.endswith(".vtt") or reply.document.file_name.endswith(".ass")):
return await ctx.reply_msg(strings("conv_sub_help").format(cmd=ctx.command[0]), del_in=5)
if replied and replied.document and (replied.document.file_name and replied.document.file_name.endswith(".vtt") or replied.document.file_name.endswith(".ass")):
msg = await ctx.reply_msg(strings("convert_str"), quote=True)
if not os.path.exists("downloads"):
os.makedirs("downloads")
@ -142,6 +141,8 @@ async def convertsrt(self: Client, ctx: Message, strings):
os.remove(f"downloads/{filename}.srt")
except:
pass
else:
return await ctx.reply_msg(strings("conv_sub_help").format(cmd=ctx.command[0]), del_in=6)
@app.on_callback_query(filters.regex(r"^streamextract#"))

View file

@ -30,8 +30,7 @@ __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.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)
if reply and (reply.sticker or reply.photo or reply.document and reply.document.mime_type.startswith("image")):
msg = await ctx.reply_msg(strings("read_ocr"), quote=True)
try:
file_path = await reply.download()
@ -52,3 +51,5 @@ async def ocr(self: Client, ctx: Message, strings):
await msg.edit_msg(str(e))
if os.path.exists(file_path):
os.remove(file_path)
else:
return await ctx.reply_msg(strings("no_photo").format(cmd=ctx.command[0]), quote=True)