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}sample <duration in seconds>`11 Creates Short sample of video..12 13• `{i}vshots <number of shots>`14 Creates screenshot of video..15 16• `{i}vtrim <start time> - <end time> in seconds`17 Crop a Lengthy video..18"""19 20import glob21import os22 23from pyUltroid.fns.tools import set_attributes24 25from . import (26 ULTConfig,27 bash,28 duration_s,29 eod,30 genss,31 get_string,32 mediainfo,33 stdr,34 ultroid_cmd,35)36 37 38@ultroid_cmd(pattern="sample( (.*)|$)")39async def gen_sample(e):40 sec = e.pattern_match.group(1).strip()41 stime = int(sec) if sec and sec.isdigit() else 3042 vido = await e.get_reply_message()43 if vido and vido.media and "video" in mediainfo(vido.media):44 msg = await e.eor(get_string("com_1"))45 file, _ = await e.client.fast_downloader(46 vido.document, show_progress=True, event=msg47 )48 file_name = (file.name).split("/")[-1]49 out = file_name.replace(file_name.split(".")[-1], "_sample.mkv")50 xxx = await msg.edit(f"Generating Sample of `{stime}` seconds...")51 ss, dd = await duration_s(file.name, stime)52 cmd = f'ffmpeg -i "{file.name}" -preset ultrafast -ss {ss} -to {dd} -codec copy -map 0 "{out}" -y'53 await bash(cmd)54 os.remove(file.name)55 attributes = await set_attributes(out)56 mmmm, _ = await e.client.fast_uploader(57 out, show_progress=True, event=xxx, to_delete=True58 )59 caption = f"A Sample Video Of `{stime}` seconds"60 await e.client.send_file(61 e.chat_id,62 mmmm,63 thumb=ULTConfig.thumb,64 caption=caption,65 attributes=attributes,66 force_document=False,67 reply_to=e.reply_to_msg_id,68 )69 await xxx.delete()70 else:71 await e.eor(get_string("audiotools_8"), time=5)72 73 74@ultroid_cmd(pattern="vshots( (.*)|$)")75async def gen_shots(e):76 ss = e.pattern_match.group(1).strip()77 shot = int(ss) if ss and ss.isdigit() else 578 vido = await e.get_reply_message()79 if vido and vido.media and "video" in mediainfo(vido.media):80 msg = await e.eor(get_string("com_1"))81 file, _ = await e.client.fast_downloader(82 vido.document, show_progress=True, event=msg83 )84 xxx = await msg.edit(f"Generating `{shot}` screenshots...")85 await bash("rm -rf ss && mkdir ss")86 cmd = f'ffmpeg -i "{file.name}" -vf fps=0.009 -vframes {shot} "ss/pic%01d.png"'87 await bash(cmd)88 os.remove(file.name)89 pic = glob.glob("ss/*")90 text = f"Uploaded {len(pic)}/{shot} screenshots"91 if not pic:92 text = "`Failed to Take Screenshots..`"93 pic = None94 await e.respond(text, file=pic)95 await bash("rm -rf ss")96 await xxx.delete()97 98 99@ultroid_cmd(pattern="vtrim( (.*)|$)")100async def gen_sample(e):101 sec = e.pattern_match.group(1).strip()102 if not sec or "-" not in sec:103 return await eod(e, get_string("audiotools_3"))104 a, b = sec.split("-")105 if int(a) >= int(b):106 return await eod(e, get_string("audiotools_4"))107 vido = await e.get_reply_message()108 if vido and vido.media and "video" in mediainfo(vido.media):109 msg = await e.eor(get_string("audiotools_5"))110 file, _ = await e.client.fast_downloader(111 vido.document, show_progress=True, event=msg112 )113 file_name = (file.name).split("/")[-1]114 out = file_name.replace(file_name.split(".")[-1], "_trimmed.mkv")115 if int(b) > int(await genss(file.name)):116 os.remove(file.name)117 return await eod(msg, get_string("audiotools_6"))118 ss, dd = stdr(int(a)), stdr(int(b))119 xxx = await msg.edit(f"Trimming Video from `{ss}` to `{dd}`...")120 cmd = f'ffmpeg -i "{file.name}" -preset ultrafast -ss {ss} -to {dd} -codec copy -map 0 "{out}" -y'121 await bash(cmd)122 os.remove(file.name)123 attributes = await set_attributes(out)124 mmmm, _ = await e.client.fast_uploader(125 out, show_progress=True, event=msg, to_delete=True126 )127 caption = f"Trimmed Video From `{ss}` To `{dd}`"128 await e.client.send_file(129 e.chat_id,130 mmmm,131 thumb=ULTConfig.thumb,132 caption=caption,133 attributes=attributes,134 force_document=False,135 reply_to=e.reply_to_msg_id,136 )137 await xxx.delete()138 else:139 await e.eor(get_string("audiotools_8"), time=5)140 