async def _(event): Man = await edit_or_reply(event, "`Processing...`") if len(event.text.split()) > 1: chat_id = event.text.split()[1] try: chat_id = await event.client.get_peer_id(int(chat_id)) except Exception as e: return await Man.edit(f"**ERROR:** `{e}`") else: chat_id = event.chat_id if chat_id: file = "./userbot/resources/audio-man.mp3" try: await call_py.join_group_call( chat_id, InputStream(InputAudioStream(file, ), ), stream_type=StreamType().local_stream, ) await Man.edit( f"❏ **Berhasil Join Ke Obrolan Suara**\n└ **Chat ID:** `{chat_id}`" ) except AlreadyJoinedError: return await edit_delete( Man, "**INFO:** `akun anda sudah berada di obrolan suara`", 45) except Exception as e: return await Man.edit(f"**INFO:** `{e}`")
async def play_handler(client: Client, message: Message): file = 'input.raw' while not os.path.exists(file): await asyncio.sleep(0.125) call_py.join_group_call( message.chat.id, file, stream_type=StreamType().local_stream, )
async def play_handler2(client: Client, message: Message): file = '../input.raw' while not os.path.exists(file): await asyncio.sleep(0.125) await call_py2.join_group_call( message.chat.id, InputStream(InputAudioStream(file, ), ), stream_type=StreamType().local_stream, )
async def play_audio(file: str, seek: int = None): ffmpeg_parm = f'-ss {seek} -atend -to {CURRENT_SONG["duration"]}' if seek else '' try: await call.change_stream( Vars.CHAT_ID, AudioPiped(file, additional_ffmpeg_parameters=ffmpeg_parm)) except NotInGroupCallError: await call.join_group_call( Vars.CHAT_ID, AudioPiped(file, additional_ffmpeg_parameters=ffmpeg_parm), stream_type=StreamType().pulse_stream, ) if not seek: CURRENT_SONG['start'] = time.time()
async def test_handler(client: Client, message: Message): global proc file = 'input.webm' output_file = 'input_fifo.raw' os.mkfifo(output_file) proc[message.chat.id] = await asyncio.create_subprocess_shell( cmd=('ffmpeg ' '-y -i ' f'{file} ' '-f s16le ' '-ac 1 ' '-ar 48000 ' '-acodec pcm_s16le ' f'{output_file}'), stdin=asyncio.subprocess.PIPE, ) while not os.path.exists(output_file): time.sleep(0.125) await call_py.join_group_call( message.chat.id, InputStream(InputAudioStream(output_file, ), ), stream_type=StreamType().pulse_stream, )
from pyrogram import Client from pytgcalls import idle from pytgcalls import PyTgCalls from pytgcalls import StreamType from pytgcalls.media_devices import MediaDevices from pytgcalls.types import CaptureAudioDevice app = Client( 'py-tgcalls', api_id=123456789, api_hash='abcdef12345', ) call_py = PyTgCalls(app) call_py.start() call_py.join_group_call( -1001234567890, CaptureAudioDevice(MediaDevices.get_audio_devices()[0], ), stream_type=StreamType().pulse_stream, ) idle()
import os import time from pyrogram import Client from pytgcalls import idle from pytgcalls import PyTgCalls from pytgcalls import StreamType from pytgcalls.types.input_stream import InputAudioStream from pytgcalls.types.input_stream import InputStream app = Client( 'py-tgcalls', api_id=123456789, api_hash='abcdef12345', ) call_py = PyTgCalls(app) call_py.start() file = '../input.raw' while not os.path.exists(file): time.sleep(0.125) call_py.join_group_call( -1001234567890, InputStream(InputAudioStream(file, ), ), stream_type=StreamType().local_stream, ) idle()
async def joinvc(msg: Message): """ join video chat """ global CHAT_NAME, CHAT_ID, CONTROL_CHAT_IDS # pylint: disable=global-statement await msg.delete() if CHAT_NAME: return await reply_text(msg, f"`Already joined in {CHAT_NAME}`") flags = msg.flags join_as = flags.get('-as') chat = flags.get('-at') if not chat and msg.chat.type == "private": return await msg.err( "Invalid chat, either use in group / channel or use -at flag.") if chat: if chat.strip("-").isnumeric(): chat = int(chat) try: _chat = await userge.get_chat(chat) except Exception as e: return await reply_text(msg, f'Invalid Join In Chat Specified\n{e}') CHAT_ID = _chat.id CHAT_NAME = _chat.title # Joins video_chat in a remote chat and control it from Saved Messages # / Linked Chat CONTROL_CHAT_IDS.append(userge.id) if _chat.linked_chat: CONTROL_CHAT_IDS.append(_chat.linked_chat.id) else: CHAT_ID = msg.chat.id CHAT_NAME = msg.chat.title if join_as: if join_as.strip("-").isnumeric(): join_as = int(join_as) try: join_as = (await userge.get_chat(join_as)).id except Exception as e: CHAT_ID, CHAT_NAME, CONTROL_CHAT_IDS = 0, '', [] return await reply_text(msg, f'Invalid Join As Chat Specified\n{e}') join_as_peers = await userge.send( functions.phone.GetGroupCallJoinAs( peer=(await userge.resolve_peer(CHAT_ID)))) raw_id = int(str(join_as).replace("-100", "")) if raw_id not in [ getattr(peers, "user_id", None) or getattr(peers, "channel_id", None) for peers in join_as_peers.peers ]: CHAT_ID, CHAT_NAME, CONTROL_CHAT_IDS = 0, '', [] return await reply_text( msg, "You cant join the video chat as this channel.") if join_as: peer = await userge.resolve_peer(join_as) else: peer = await userge.resolve_peer(userge.id) try: # Initialising NodeJS if not call.is_connected: await call.start() # Joining with a dummy audio, since py-tgcalls wont allow joining # without file. await call.join_group_call( CHAT_ID, AudioPiped('http://duramecho.com/Misc/SilentCd/Silence01s.mp3'), join_as=peer, stream_type=StreamType().pulse_stream) except NoActiveGroupCall: try: peer = await userge.resolve_peer(CHAT_ID) await userge.send( functions.phone.CreateGroupCall(peer=peer, random_id=2)) await asyncio.sleep(3) CHAT_ID, CHAT_NAME, CONTROL_CHAT_IDS = 0, '', [] return await joinvc(msg) except Exception as err: CHAT_ID, CHAT_NAME, CONTROL_CHAT_IDS = 0, '', [] return await reply_text(msg, err) except (NodeJSNotInstalled, TooOldNodeJSVersion): return await reply_text( msg, "NodeJs is not installed or installed version is too old.") except AlreadyJoinedError: await call.leave_group_call(CHAT_ID) await asyncio.sleep(3) CHAT_ID, CHAT_NAME, CONTROL_CHAT_IDS = 0, '', [] return await joinvc(msg) except Exception as e: CHAT_ID, CHAT_NAME, CONTROL_CHAT_IDS = 0, '', [] return await reply_text(msg, f'Error during Joining the Call\n`{e}`') await _on_join() await reply_text(msg, "`Joined VideoChat Successfully`", del_in=5)
async def vc_play(event): title = event.pattern_match.group(1) replied = await event.get_reply_message() chat = await event.get_chat() titlegc = chat.title chat_id = event.chat_id from_user = vcmention(event.sender) if ( replied and not replied.audio and not replied.voice and not title or not replied and not title ): return await edit_or_reply(event, "**Silahkan Masukan Judul Lagu**") elif replied and not replied.audio and not replied.voice or not replied: botman = await edit_or_reply(event, "`Searching...`") query = event.text.split(maxsplit=1)[1] search = ytsearch(query) if search == 0: await botman.edit( "**Tidak Dapat Menemukan Lagu** Coba cari dengan Judul yang Lebih Spesifik" ) else: songname = search[0] title = search[0] url = search[1] duration = search[2] thumbnail = search[3] videoid = search[4] titlegc = chat.title ctitle = await CHAT_TITLE(titlegc) thumb = await gen_thumb(thumbnail, title, videoid, ctitle) hm, ytlink = await ytdl(url) if hm == 0: await botman.edit(f"`{ytlink}`") elif chat_id in QUEUE: pos = add_to_queue(chat_id, songname, ytlink, url, "Audio", 0) caption = f"💡 **Lagu Ditambahkan Ke antrian »** `#{pos}`\n\n**🏷 Judul:** [{songname}]({url})\n**⏱ Durasi:** `{duration}`\n🎧 **Atas permintaan:** {from_user}" await botman.delete() await event.client.send_file( chat_id, thumb, caption=caption, reply_to=event.reply_to_msg_id ) else: try: await call_py.join_group_call( chat_id, AudioPiped( ytlink, HighQualityAudio(), ), stream_type=StreamType().pulse_stream, ) add_to_queue(chat_id, songname, ytlink, url, "Audio", 0) caption = f"🏷 **Judul:** [{songname}]({url})\n**⏱ Durasi:** `{duration}`\n💡 **Status:** `Sedang Memutar`\n🎧 **Atas permintaan:** {from_user}" await botman.delete() await event.client.send_file( chat_id, thumb, caption=caption, reply_to=event.reply_to_msg_id ) except AlreadyJoinedError: await call_py.leave_group_call(chat_id) clear_queue(chat_id) await botman.edit( "**ERROR:** `Karena akun sedang berada di obrolan suara`\n\n• Silahkan Coba Play lagi" ) except Exception as ep: clear_queue(chat_id) await botman.edit(f"`{ep}`") else: botman = await edit_or_reply(event, "📥 **Sedang Mendownload**") dl = await replied.download_media() link = f"https://t.me/c/{chat.id}/{event.reply_to_msg_id}" if replied.audio: songname = "Telegram Music Player" elif replied.voice: songname = "Voice Note" if chat_id in QUEUE: pos = add_to_queue(chat_id, songname, dl, link, "Audio", 0) caption = f"💡 **Lagu Ditambahkan Ke antrian »** `#{pos}`\n\n**🏷 Judul:** [{songname}]({link})\n**👥 Chat ID:** `{chat_id}`\n🎧 **Atas permintaan:** {from_user}" await event.client.send_file( chat_id, QUEUE_PIC, caption=caption, reply_to=event.reply_to_msg_id ) await botman.delete() else: try: await call_py.join_group_call( chat_id, AudioPiped( dl, HighQualityAudio(), ), stream_type=StreamType().pulse_stream, ) add_to_queue(chat_id, songname, dl, link, "Audio", 0) caption = f"🏷 **Judul:** [{songname}]({link})\n**👥 Chat ID:** `{chat_id}`\n💡 **Status:** `Sedang Memutar Lagu`\n🎧 **Atas permintaan:** {from_user}" await event.client.send_file( chat_id, PLAY_PIC, caption=caption, reply_to=event.reply_to_msg_id ) await botman.delete() except AlreadyJoinedError: await call_py.leave_group_call(chat_id) clear_queue(chat_id) await botman.edit( "**ERROR:** `Karena akun sedang berada di obrolan suara`\n\n• Silahkan Coba Play lagi" ) except Exception as ep: clear_queue(chat_id) await botman.edit(f"`{ep}`")
async def vc_vplay(event): title = event.pattern_match.group(1) replied = await event.get_reply_message() chat = await event.get_chat() titlegc = chat.title chat_id = event.chat_id from_user = vcmention(event.sender) if ( replied and not replied.video and not replied.document and not title or not replied and not title ): return await edit_or_reply(event, "**Silahkan Masukan Judul Video**") if replied and not replied.video and not replied.document: xnxx = await edit_or_reply(event, "`Searching...`") query = event.text.split(maxsplit=1)[1] search = ytsearch(query) RESOLUSI = 720 hmmm = HighQualityVideo() if search == 0: await xnxx.edit( "**Tidak Dapat Menemukan Video** Coba cari dengan Judul yang Lebih Spesifik" ) else: songname = search[0] title = search[0] url = search[1] duration = search[2] thumbnail = search[3] videoid = search[4] ctitle = await CHAT_TITLE(titlegc) thumb = await gen_thumb(thumbnail, title, videoid, ctitle) hm, ytlink = await ytdl(url) if hm == 0: await xnxx.edit(f"`{ytlink}`") elif chat_id in QUEUE: pos = add_to_queue(chat_id, songname, ytlink, url, "Video", RESOLUSI) caption = f"💡 **Video Ditambahkan Ke antrian »** `#{pos}`\n\n**🏷 Judul:** [{songname}]({url})\n**⏱ Durasi:** `{duration}`\n🎧 **Atas permintaan:** {from_user}" await xnxx.delete() await event.client.send_file( chat_id, thumb, caption=caption, reply_to=event.reply_to_msg_id ) else: try: await call_py.join_group_call( chat_id, AudioVideoPiped( ytlink, HighQualityAudio(), hmmm, ), stream_type=StreamType().pulse_stream, ) add_to_queue(chat_id, songname, ytlink, url, "Video", RESOLUSI) await xnxx.edit( f"**🏷 Judul:** [{songname}]({url})\n**⏱ Durasi:** `{duration}`\n💡 **Status:** `Sedang Memutar Video`\n🎧 **Atas permintaan:** {from_user}", link_preview=False, ) except AlreadyJoinedError: await call_py.leave_group_call(chat_id) clear_queue(chat_id) await xnxx.edit( "**ERROR:** `Karena akun sedang berada di obrolan suara`\n\n• Silahkan Coba Play lagi" ) except Exception as ep: clear_queue(chat_id) await xnxx.edit(f"`{ep}`") elif replied: xnxx = await edit_or_reply(event, "📥 **Sedang Mendownload**") dl = await replied.download_media() link = f"https://t.me/c/{chat.id}/{event.reply_to_msg_id}" if len(event.text.split()) < 2: RESOLUSI = 720 else: pq = event.text.split(maxsplit=1)[1] RESOLUSI = int(pq) if replied.video or replied.document: songname = "Telegram Video Player" if chat_id in QUEUE: pos = add_to_queue(chat_id, songname, dl, link, "Video", RESOLUSI) caption = f"💡 **Video Ditambahkan Ke antrian »** `#{pos}`\n\n**🏷 Judul:** [{songname}]({link})\n**👥 Chat ID:** `{chat_id}`\n🎧 **Atas permintaan:** {from_user}" await event.client.send_file( chat_id, QUEUE_PIC, caption=caption, reply_to=event.reply_to_msg_id ) await xnxx.delete() else: if RESOLUSI == 360: hmmm = LowQualityVideo() elif RESOLUSI == 480: hmmm = MediumQualityVideo() elif RESOLUSI == 720: hmmm = HighQualityVideo() try: await call_py.join_group_call( chat_id, AudioVideoPiped( dl, HighQualityAudio(), hmmm, ), stream_type=StreamType().pulse_stream, ) add_to_queue(chat_id, songname, dl, link, "Video", RESOLUSI) caption = f"🏷 **Judul:** [{songname}]({link})\n**👥 Chat ID:** `{chat_id}`\n💡 **Status:** `Sedang Memutar Video`\n🎧 **Atas permintaan:** {from_user}" await xnxx.delete() await event.client.send_file( chat_id, PLAY_PIC, caption=caption, reply_to=event.reply_to_msg_id ) except AlreadyJoinedError: await call_py.leave_group_call(chat_id) clear_queue(chat_id) await xnxx.edit( "**ERROR:** `Karena akun sedang berada di obrolan suara`\n\n• Silahkan Coba Play lagi" ) except Exception as ep: clear_queue(chat_id) await xnxx.edit(f"`{ep}`") else: xnxx = await edit_or_reply(event, "`Searching...`") query = event.text.split(maxsplit=1)[1] search = ytsearch(query) RESOLUSI = 720 hmmm = HighQualityVideo() if search == 0: await xnxx.edit("**Tidak Menemukan Video untuk Keyword yang Diberikan**") else: songname = search[0] title = search[0] url = search[1] duration = search[2] thumbnail = search[3] videoid = search[4] ctitle = await CHAT_TITLE(titlegc) thumb = await gen_thumb(thumbnail, title, videoid, ctitle) hm, ytlink = await ytdl(url) if hm == 0: await xnxx.edit(f"`{ytlink}`") elif chat_id in QUEUE: pos = add_to_queue(chat_id, songname, ytlink, url, "Video", RESOLUSI) caption = f"💡 **Video Ditambahkan Ke antrian »** `#{pos}`\n\n🏷 **Judul:** [{songname}]({url})\n**⏱ Durasi:** `{duration}`\n🎧 **Atas permintaan:** {from_user}" await xnxx.delete() await event.client.send_file( chat_id, thumb, caption=caption, reply_to=event.reply_to_msg_id ) else: try: await call_py.join_group_call( chat_id, AudioVideoPiped( ytlink, HighQualityAudio(), hmmm, ), stream_type=StreamType().pulse_stream, ) add_to_queue(chat_id, songname, ytlink, url, "Video", RESOLUSI) caption = f"🏷 **Judul:** [{songname}]({url})\n**⏱ Durasi:** `{duration}`\n💡 **Status:** `Sedang Memutar Video`\n🎧 **Atas permintaan:** {from_user}" await xnxx.delete() await event.client.send_file( chat_id, thumb, caption=caption, reply_to=event.reply_to_msg_id ) except AlreadyJoinedError: await call_py.leave_group_call(chat_id) clear_queue(chat_id) await xnxx.edit( "**ERROR:** `Karena akun sedang berada di obrolan suara`\n\n• Silahkan Coba Play lagi" ) except Exception as ep: clear_queue(chat_id) await xnxx.edit(f"`{ep}`")
async def joinvc(msg: Message): """ join video chat """ await msg.delete() if Vars.CHAT_NAME: return await reply_text(msg, f"`Already joined in {Vars.CHAT_NAME}`") flags = msg.flags join_as = flags.get('-as') chat = flags.get('-at') if not chat and msg.chat.type == "private": return await msg.err( "Invalid chat, either use in group / channel or use -at flag.") if chat: if chat.strip("-").isnumeric(): chat = int(chat) try: _chat = await VC_CLIENT.get_chat(chat) except Exception as e: return await reply_text(msg, f'Invalid Join In Chat Specified\n{e}') Vars.CHAT_ID = _chat.id Vars.CHAT_NAME = _chat.title # Joins video_chat in a remote chat and control it from Saved Messages # / Linked Chat CONTROL_CHAT_IDS.append(userge.id) if _chat.linked_chat: CONTROL_CHAT_IDS.append(_chat.linked_chat.id) else: chat_id_ = msg.chat.username or msg.chat.id try: # caching the peer in case of public chats to play without joining for VC_SESSION_STRING await VC_CLIENT.get_chat(chat_id_) except (ChannelInvalid, ChannelPrivate): msg_ = await reply_text( msg, 'You are using VC_SESSION_STRING and it seems that user is ' 'not present in this group.\ntrying to join group.') join = await invite_vc_client(msg) await msg_.delete() if not join: return Vars.CHAT_ID = msg.chat.id Vars.CHAT_NAME = msg.chat.title if join_as: if join_as.strip("-").isnumeric(): join_as = int(join_as) try: join_as = (await VC_CLIENT.get_chat(join_as)).id except Exception as e: Vars.CHAT_ID, Vars.CHAT_NAME = 0, '' CONTROL_CHAT_IDS.clear() return await reply_text(msg, f'Invalid Join As Chat Specified\n{e}') join_as_peers = await VC_CLIENT.send( GetGroupCallJoinAs( peer=(await VC_CLIENT.resolve_peer(Vars.CHAT_ID)))) raw_id = int(str(join_as).replace("-100", "")) if raw_id not in [ getattr(peers, "user_id", None) or getattr(peers, "channel_id", None) for peers in join_as_peers.peers ]: Vars.CHAT_ID, Vars.CHAT_NAME = 0, '' CONTROL_CHAT_IDS.clear() return await reply_text( msg, "You cant join the video chat as this channel.") if join_as: peer = await VC_CLIENT.resolve_peer(join_as) else: peer = await VC_CLIENT.resolve_peer('me') try: if not call.is_connected: await call.start() await call.join_group_call( Vars.CHAT_ID, AudioPiped('http://duramecho.com/Misc/SilentCd/Silence01s.mp3'), join_as=peer, stream_type=StreamType().pulse_stream) except NoActiveGroupCall: try: peer = await VC_CLIENT.resolve_peer(Vars.CHAT_ID) await VC_CLIENT.send(CreateGroupCall(peer=peer, random_id=2)) await asyncio.sleep(3) Vars.CHAT_ID, Vars.CHAT_NAME = 0, '' CONTROL_CHAT_IDS.clear() return await joinvc(msg) except Exception as err: Vars.CHAT_ID, Vars.CHAT_NAME = 0, '' CONTROL_CHAT_IDS.clear() return await reply_text(msg, str(err)) except (NodeJSNotInstalled, TooOldNodeJSVersion): return await reply_text( msg, "NodeJs is not installed or installed version is too old.") except AlreadyJoinedError: await call.leave_group_call(Vars.CHAT_ID) await asyncio.sleep(3) Vars.CHAT_ID, Vars.CHAT_NAME = 0, '' CONTROL_CHAT_IDS.clear() return await joinvc(msg) except Exception as e: Vars.CHAT_ID, Vars.CHAT_NAME = 0, '' CONTROL_CHAT_IDS.clear() return await reply_text(msg, f'Error during Joining the Call\n`{e}`') await on_join() await reply_text(msg, "`Joined VideoChat Successfully`", del_in=5)