azils3/bash
0
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7"""8✘ Commands Available -9 10• `{i}mediainfo <reply to media>/<file path>/<url>`11 To get info about it.12 13• `{i}rotate <degree/angle> <reply to media>`14 Rotate any video/photo/media..15 Note : for video it should be angle of 90's16"""17import os18import time19from datetime import datetime as dt20 21from pyUltroid.fns.misc import rotate_image22from pyUltroid.fns.tools import make_html_telegraph23 24from . import (25 LOGS,26 Telegraph,27 bash,28 downloader,29 get_string,30 upload_file,31 is_url_ok,32 mediainfo,33 ultroid_cmd,34)35 36try:37 import cv238except ImportError:39 LOGS.info("WARNING: 'cv2' not found!")40 cv2 = None41 42 43@ultroid_cmd(pattern="mediainfo( (.*)|$)")44async def mi(e):45 r = await e.get_reply_message()46 match = e.pattern_match.group(1).strip()47 taime = time.time()48 extra = ""49 if r and r.media:50 xx = mediainfo(r.media)51 murl = r.media.stringify()52 url = await make_html_telegraph("Mediainfo", f"<pre>{murl}</pre>")53 extra = f"**[{xx}]({url})**\n\n"54 e = await e.eor(f"{extra}`Loading More...`", link_preview=False)55 56 if hasattr(r.media, "document"):57 file = r.media.document58 mime_type = file.mime_type59 filename = r.file.name60 if not filename:61 if "audio" in mime_type:62 filename = "audio_" + dt.now().isoformat("_", "seconds") + ".ogg"63 elif "video" in mime_type:64 filename = "video_" + dt.now().isoformat("_", "seconds") + ".mp4"65 dl = await downloader(66 f"resources/downloads/{filename}",67 file,68 e,69 taime,70 f"{extra}`Loading More...`",71 )72 73 naam = dl.name74 else:75 naam = await r.download_media()76 elif match and (77 os.path.isfile(match)78 or (match.startswith("https://") and (await is_url_ok(match)))79 ):80 naam, xx = match, "file"81 else:82 return await e.eor(get_string("cvt_3"), time=5)83 out, er = await bash(f"mediainfo '{naam}'")84 if er:85 LOGS.info(er)86 out = extra or str(er)87 return await e.edit(out, link_preview=False)88 makehtml = ""89 if naam.endswith((".jpg", ".png")):90 if os.path.exists(naam):91 med = upload_file(naam)92 else:93 med = match94 makehtml += f"<img src='{med}'><br>"95 for line in out.split("\n"):96 line = line.strip()97 if not line:98 makehtml += "<br>"99 elif ":" not in line:100 makehtml += f"<h3>{line}</h3>"101 else:102 makehtml += f"<p>{line}</p>"103 try:104 urll = await make_html_telegraph("Mediainfo", makehtml)105 except Exception as er:106 LOGS.exception(er)107 return108 await e.eor(f"{extra}[{get_string('mdi_1')}]({urll})", link_preview=False)109 if not match:110 os.remove(naam)111 112 113@ultroid_cmd(pattern="rotate( (.*)|$)")114async def rotate_(ult):115 match = ult.pattern_match.group(1).strip()116 if not ult.is_reply:117 return await ult.eor("`Reply to a media...`")118 if match:119 try:120 match = int(match)121 except ValueError:122 match = None123 if not match:124 return await ult.eor("`Please provide a valid angle to rotate media..`")125 reply = await ult.get_reply_message()126 msg = await ult.eor(get_string("com_1"))127 photo = reply.game.photo if reply.game else None128 if reply.video:129 media = await reply.download_media()130 file = f"{media}.mp4"131 await bash(132 f'ffmpeg -i "{media}" -c copy -metadata:s:v:0 rotate={match} "{file}" -y'133 )134 elif photo or reply.photo or reply.sticker:135 media = await ult.client.download_media(photo or reply)136 img = cv2.imread(media)137 new_ = rotate_image(img, match)138 file = "ult.png"139 cv2.imwrite(file, new_)140 else:141 return await msg.edit("`Unsupported Media..\nReply to Photo/Video`")142 if os.path.exists(file):143 await ult.client.send_file(144 ult.chat_id, file=file, video_note=bool(reply.video_note), reply_to=reply.id145 )146 os.remove(media)147 await msg.try_delete()148 