__version__ = (1, 4, 8, 8) # This file is a part of Hikka Userbot # Code is NOT licensed under CC-BY-NC-ND 4.0 unless otherwise specified. # 🌐 https://github.com/hikariatama/Hikka # You CAN edit this file without direct permission from the author. # You can redistribute this file with any modifications. # meta developer: @yg_modules # scope: hikka_only # scope: hikka_min 1.6.3 # scope: ffmpeg # █▄█ █░█ █▀▄▀█ █▀▄▀█ █▄█   █▀▄▀█ █▀█ █▀▄ █▀ # ░█░ █▄█ █░▀░█ █░▀░█ ░█░   █░▀░█ █▄█ █▄▀ ▄█ import os import uuid from .. import loader, utils @loader.tds class VoiceModule(loader.Module): """Converts music and video (required ffmpeg)""" strings = {"name": "yg_vm"} async def m2vcmd(self, message): """Convert music to voice message""" reply = await message.get_reply_message() if not reply or not reply.file: await utils.answer(message, "❌ Reply to audio file") return media = reply.file mime_type = media.mime_type.split('/')[0] if '/' in media.mime_type else 'audio' if mime_type == 'audio': await utils.answer(message, "🫥 Converting audio...") voice_message = await self.convert_audio(reply) else: await utils.answer(message, "❌ Unsupported file type") return await message.delete() await message.client.send_file(message.to_id, voice_message, voice_note=True, reply_to=reply) async def convert_audio(self, message): tmp_filename = "tmp_audio.ogg" await message.download_media(file=tmp_filename) os.system(f"ffmpeg -y -i {tmp_filename} -c:a libopus {tmp_filename}.ogg") os.remove(tmp_filename) return f"{tmp_filename}.ogg" async def v2acmd(self, message): """Convert video to audio""" reply = await message.get_reply_message() if not reply or not reply.file: await utils.answer(message, "❌ Reply to video file") return media = reply.file mime_type = media.mime_type.split('/')[0] if '/' in media.mime_type else 'video' if mime_type == 'video': await utils.answer(message, "🫥 Converting video to audio...") audio_message = await self.convert_video_to_mp3(reply) else: await utils.answer(message, "❌ Unsupported file type") return await message.delete() await message.client.send_file(message.to_id, audio_message, reply_to=reply) async def convert_video_to_mp3(self, message): tmp_filename = f"{uuid.uuid4().hex}.mp4" await message.download_media(file=tmp_filename) audio_filename = f"{uuid.uuid4().hex}.mp3" os.system(f"ffmpeg -y -i {tmp_filename} -vn -acodec libmp3lame -ab 192k -ar 44100 -ac 2 {audio_filename}") os.remove(tmp_filename) return audio_filename