mirror of
https://github.com/yasirarism/MissKatyPyro.git
synced 2026-01-07 20:34:52 +00:00
Trying fix ocr and conversrt
This commit is contained in:
parent
4a72e140f2
commit
375be9672c
2 changed files with 47 additions and 45 deletions
|
|
@ -119,29 +119,30 @@ async def ceksub(self: Client, ctx: Message, strings):
|
||||||
@use_chat_lang()
|
@use_chat_lang()
|
||||||
async def convertsrt(self: Client, ctx: Message, strings):
|
async def convertsrt(self: Client, ctx: Message, strings):
|
||||||
reply = ctx.reply_to_message
|
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")):
|
if replied and replied.document and (replied.document.file_name and replied.document.file_name.endswith(".vtt") or replied.document.file_name.endswith(".ass")):
|
||||||
return await ctx.reply_msg(strings("conv_sub_help").format(cmd=ctx.command[0]), del_in=5)
|
msg = await ctx.reply_msg(strings("convert_str"), quote=True)
|
||||||
msg = await ctx.reply_msg(strings("convert_str"), quote=True)
|
if not os.path.exists("downloads"):
|
||||||
if not os.path.exists("downloads"):
|
os.makedirs("downloads")
|
||||||
os.makedirs("downloads")
|
dl = await reply.download(file_name="downloads/")
|
||||||
dl = await reply.download(file_name="downloads/")
|
filename = dl.split("/", 3)[3]
|
||||||
filename = dl.split("/", 3)[3]
|
LOGGER.info(f"ConvertSub: {filename} by {ctx.from_user.first_name if ctx.from_user else ctx.sender_chat.title} [{ctx.from_user.id if ctx.from_user else ctx.sender_chat.id}]")
|
||||||
LOGGER.info(f"ConvertSub: {filename} by {ctx.from_user.first_name if ctx.from_user else ctx.sender_chat.title} [{ctx.from_user.id if ctx.from_user else ctx.sender_chat.id}]")
|
(await shell_exec(f"{FF_MPEG_NAME} -i '{dl}' 'downloads/{filename}.srt'"))[0]
|
||||||
(await shell_exec(f"{FF_MPEG_NAME} -i '{dl}' 'downloads/{filename}.srt'"))[0]
|
c_time = time()
|
||||||
c_time = time()
|
await ctx.reply_document(
|
||||||
await ctx.reply_document(
|
f"downloads/{filename}.srt",
|
||||||
f"downloads/{filename}.srt",
|
caption=strings("capt_conv_sub").format(nf=filename, bot=self.me.username),
|
||||||
caption=strings("capt_conv_sub").format(nf=filename, bot=self.me.username),
|
thumb="assets/thumb.jpg",
|
||||||
thumb="assets/thumb.jpg",
|
progress=progress_for_pyrogram,
|
||||||
progress=progress_for_pyrogram,
|
progress_args=(strings("up_str"), msg, c_time, self.me.dc_id),
|
||||||
progress_args=(strings("up_str"), msg, c_time, self.me.dc_id),
|
)
|
||||||
)
|
await msg.delete_msg()
|
||||||
await msg.delete_msg()
|
try:
|
||||||
try:
|
os.remove(dl)
|
||||||
os.remove(dl)
|
os.remove(f"downloads/{filename}.srt")
|
||||||
os.remove(f"downloads/{filename}.srt")
|
except:
|
||||||
except:
|
pass
|
||||||
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#"))
|
@app.on_callback_query(filters.regex(r"^streamextract#"))
|
||||||
|
|
|
||||||
|
|
@ -30,25 +30,26 @@ __HELP__ = "/ocr [reply to photo] - Read Text From Image"
|
||||||
@use_chat_lang()
|
@use_chat_lang()
|
||||||
async def ocr(self: Client, ctx: Message, strings):
|
async def ocr(self: Client, ctx: Message, strings):
|
||||||
reply = ctx.reply_to_message
|
reply = ctx.reply_to_message
|
||||||
if not reply or not (reply.document and reply.document.mime_type.startswith("image")) or not reply.sticker:
|
if reply and (reply.sticker or reply.photo or reply.document and reply.document.mime_type.startswith("image")):
|
||||||
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)
|
||||||
msg = await ctx.reply_msg(strings("read_ocr"), quote=True)
|
try:
|
||||||
try:
|
file_path = await reply.download()
|
||||||
file_path = await reply.download()
|
if reply.sticker:
|
||||||
if reply.sticker:
|
file_path = await reply.download(f"ocr_{ctx.from_user.id if ctx.from_user else ctx.sender_chat.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)
|
||||||
response = await Telegraph().upload_file(file_path)
|
url = f"https://telegra.ph{response[0]['src']}"
|
||||||
url = f"https://telegra.ph{response[0]['src']}"
|
req = (
|
||||||
req = (
|
await http.get(
|
||||||
await http.get(
|
f"https://script.google.com/macros/s/AKfycbwURISN0wjazeJTMHTPAtxkrZTWTpsWIef5kxqVGoXqnrzdLdIQIfLO7jsR5OQ5GO16/exec?url={url}",
|
||||||
f"https://script.google.com/macros/s/AKfycbwURISN0wjazeJTMHTPAtxkrZTWTpsWIef5kxqVGoXqnrzdLdIQIfLO7jsR5OQ5GO16/exec?url={url}",
|
follow_redirects=True,
|
||||||
follow_redirects=True,
|
)
|
||||||
)
|
).json()
|
||||||
).json()
|
await msg.edit_msg(strings("result_ocr").format(result=req["text"]))
|
||||||
await msg.edit_msg(strings("result_ocr").format(result=req["text"]))
|
if os.path.exists(file_path):
|
||||||
if os.path.exists(file_path):
|
os.remove(file_path)
|
||||||
os.remove(file_path)
|
except Exception as e:
|
||||||
except Exception as e:
|
await msg.edit_msg(str(e))
|
||||||
await msg.edit_msg(str(e))
|
if os.path.exists(file_path):
|
||||||
if os.path.exists(file_path):
|
os.remove(file_path)
|
||||||
os.remove(file_path)
|
else:
|
||||||
|
return await ctx.reply_msg(strings("no_photo").format(cmd=ctx.command[0]), quote=True)
|
||||||
Loading…
Reference in a new issue