async def ff_mpeg_trim_cmd(event): if event.fwd_from: return if not os.path.exists(FF_MPEG_DOWN_LOAD_MEDIA_PATH): reply_message = await event.get_reply_message() if reply_message: start = datetime.now() media = media_type(reply_message) if media not in ["Video", "Audio", "Voice", "Round Video", "Gif"]: return await edit_delete(event, "`Only media files are supported`", 5) catevent = await edit_or_reply(event, "`Saving the file...`") try: c_time = time.time() downloaded_file_name = await event.client.download_media( reply_message, FF_MPEG_DOWN_LOAD_MEDIA_PATH, progress_callback=lambda d, t: asyncio.get_event_loop().create_task( progress(d, t, catevent, c_time, "trying to download") ), ) except Exception as e: await catevent.edit(str(e)) else: end = datetime.now() ms = (end - start).seconds await catevent.edit( f"Saved file to `{downloaded_file_name}` in `{ms}` seconds." ) else: await edit_delete(event, "`Reply to a any media file`") else: await edit_delete( event, f"A media file already exists in path. Please remove the media and try again!\n`.ffmpegclear`", )
async def ff_mpeg_trim_cmd(event): if event.fwd_from: return if not os.path.exists(FF_MPEG_DOWN_LOAD_MEDIA_PATH): await edit_delete( event, f"a media file needs to be download, and save to the following path: `{FF_MPEG_DOWN_LOAD_MEDIA_PATH}`", ) return reply_to_id = await reply_id(event) catevent = await edit_or_reply(event, "`Triming the media...........`") current_message_text = event.raw_text cmt = current_message_text.split(" ") start = datetime.now() out_put_file_name = os.path.join( Config.TMP_DOWNLOAD_DIRECTORY, f"{str(round(time.time()))}.mp3" ) if len(cmt) == 3: # output should be audio cmd, start_time, end_time = cmt o = await cult_small_video( FF_MPEG_DOWN_LOAD_MEDIA_PATH, Config.TMP_DOWNLOAD_DIRECTORY, start_time, end_time, out_put_file_name, ) if o is None: return await edit_delete( catevent, f"**Error : **`Can't complete the process`" ) try: c_time = time.time() await event.client.send_file( event.chat_id, o, caption=" ".join(cmt[1:]), force_document=False, supports_streaming=True, allow_cache=False, reply_to=reply_to_id, progress_callback=lambda d, t: asyncio.get_event_loop().create_task( progress(d, t, catevent, c_time, "trying to upload") ), ) os.remove(o) except Exception as e: return await edit_delete(catevent, f"**Error : **`{e}`") else: await edit_delete(catevent, "RTFM") return end = datetime.now() ms = (end - start).seconds await edit_delete(catevent, f"`Completed Process in {ms} seconds`", 3)