def __init__(self): self.group_call = GroupCall(None, path_to_log_file='') self.chat_id = None self.start_time = None self.playlist = [] self.msg = {}
VC_DB = get_collection("VC_CMDS_TOGGLE") CMDS_FOR_ALL = False MAX_DURATION = int(os.environ.get("MAX_DURATION", 900)) ADMINS = {} PLAYING = False CHAT_NAME = "" CHAT_ID = 0 QUEUE: List[Message] = [] BACK_BUTTON_TEXT = "" CQ_MSG: List[RawMessage] = [] call = GroupCall(petercord, play_on_repeat=False) yt_regex = re.compile( r'(https?://)?(www\.)?' r'(youtube|youtu|youtube-nocookie)\.(com|be)/' r'(watch\?v=|embed/|v/|.+\?v=)?([^&=%?]{11})' ) _SCHEDULED = "[{title}]({link}) Scheduled to QUEUE on #{position} position" def _get_scheduled_text(title: str, link: str) -> str: return _SCHEDULED.format(title=title, link=link, position=len(QUEUE)+1) def vc_chat(func): """ decorator for Voice-Call chat """
VC_DB = get_collection("VC_CMDS_TOGGLE") CMDS_FOR_ALL = False ADMINS = {} PLAYING = False CHAT_NAME = "" CHAT_ID = 0 QUEUE: List[Message] = [] BACK_BUTTON_TEXT = "" CQ_MSG: List[RawMessage] = [] call = GroupCall(userge, play_on_repeat=False) yt_regex = re.compile(r'(https?://)?(www\.)?' r'(youtube|youtu|youtube-nocookie)\.(com|be)/' r'(watch\?v=|embed/|v/|.+\?v=)?([^&=%?]{11})') _SCHEDULED = "[{title}]({link}) Scheduled to QUEUE on #{position} position" def _get_scheduled_text(title: str, link: str) -> str: return _SCHEDULED.format(title=title, link=link, position=len(QUEUE) + 1) def vc_chat(func): """ decorator for Voice-Call chat """ async def checker(msg: Message): if CHAT_ID and msg.chat.id == CHAT_ID:
async def record_audio(client, message: Message): download_dir = os.path.join(client.workdir, DEFAULT_DOWNLOAD_DIR) Path(download_dir).mkdir(parents=True, exist_ok=True) record_raw = os.path.join(download_dir, "output.raw") if message.reply_to_message: duration = 60 else: duration = 15 chat = message.chat if not VOICE_CHATS or chat.id not in VOICE_CHATS: group_call = GroupCall(client) await group_call.start(chat.id, False) VOICE_CHATS[chat.id] = group_call status = ( "\n- Joined the Voice Chat, send the command again to record") await update_userbot_message(message, message.text, status) return status = ("\n- recording...") await update_userbot_message(message, message.text, status) group_call = VOICE_CHATS[chat.id] group_call.output_filename = record_raw time_record = datetime.utcnow() task = asyncio.create_task(asyncio.sleep(duration)) time_spent = 0 while not task.done(): await asyncio.sleep(10) time_spent += 10 await update_userbot_message(message, message.text, f"{status} **{time_spent}/{duration}**") group_call.stop_output() status += "\n- transcoding..." record_opus = os.path.join(download_dir, f"vcrec-{time_record.strftime('%s')}.opus") await update_userbot_message(message, message.text, status) ffmpeg.input(record_raw, format='s16le', acodec='pcm_s16le', ac=2, ar='48k').output(record_opus).overwrite_output().run() # ffmpeg -y -f s16le -ac 2 -ar 48000 -acodec pcm_s16le \ # -i output.raw record.opus duration = int(float(ffmpeg.probe(record_opus)['format']['duration'])) # sox {record_opus} -t raw -r 44100 -e float -c 1 - | bpm -f '%0.0f' # sox -t raw -r 48000 -e signed -b 16 -c 2 \ # output.raw -t raw -r 44100 -e float -c 1 - | bpm -f '%0.0f' bpm = subprocess.getoutput( f"opusdec --quiet --rate 44100 --float {record_opus} - " "| bpm -f '%0.0f'") probe = ffmpeg.probe(record_opus, pretty=None) time_record_readable = time_record.strftime('%Y-%m-%d %H:%M:%S') title = f"[VCREC] {time_record_readable}" caption = (f"- BPM: `{bpm}`\n" f"- Format: `{probe['streams'][0]['codec_name']}`\n" f"- Channel(s): `{str(probe['streams'][0]['channels'])}`\n" f"- Sampling rate: `{probe['streams'][0]['sample_rate']}`\n" f"- Bit rate: `{probe['format']['bit_rate']}`\n" f"- File size: `{probe['format']['size']}`") status += "\n- uploading..." await update_userbot_message(message, message.text, status) thumb = await client.download_media(chat.photo.big_file_id) performer = (f"@{chat.username}" if chat.username else chat.title) await message.reply_audio(record_opus, quote=False, caption=caption, duration=duration, performer=performer, title=title, thumb=thumb) for f in [record_opus, thumb]: os.remove(f) open(record_raw, 'w').close()
from config import SESSION_STRING elif not is_config: from sample_config import SESSION_STRING queue = [] # This is where the whole song queue is stored playing = False # Tells if something is playing or not chat_joined = False # Tell if chat is joined or not # Pyrogram Client if not HEROKU: app = Client("tgvc", api_id=api_id, api_hash=api_hash) else: app = Client(SESSION_STRING, api_id=api_id, api_hash=api_hash) # Pytgcalls Client vc = GroupCall(app, input_filename="input.raw", play_on_repeat=True) # Arq Client arq = ARQ(ARQ_API) @app.on_message(filters.command("start") & filters.chat(sudo_chat_id)) async def start(_, message): await send(START_TEXT) @app.on_message(filters.command("help") & filters.chat(sudo_chat_id)) async def help(_, message): await send(HELP_TEXT)
Requirements (pip): - ffmpeg-python Start the userbot and send !record to a voice chat enabled group chat to start recording for 30 seconds """ import os import asyncio import subprocess from datetime import datetime from pyrogram import Client, filters from pyrogram.types import Message from pytgcalls import GroupCall, GroupCallAction import ffmpeg group_call = GroupCall(None, path_to_log_file='') @Client.on_message(filters.group & filters.text & filters.outgoing & ~filters.edited & filters.regex("^!record$")) async def record_from_voice_chat(client, m: Message): group_call.client = client await group_call.start(m.chat.id) group_call.add_handler( network_status_changed_handler, GroupCallAction.NETWORK_STATUS_CHANGED ) await m.delete()
def __init__(self): self.group_call = GroupCall(USER, path_to_log_file='') self.chat_id = None
elif not is_config: from sample_config import SESSION_STRING queue = [] # This is where the whole song queue is stored playing = False # Tells if something is playing or not # Pyrogram Client if not HEROKU: app = Client("tgvc", api_id=API_ID, api_hash=API_HASH) else: app = Client(SESSION_STRING, api_id=API_ID, api_hash=API_HASH) # Pytgcalls Client vc = GroupCall( client=app, input_filename="input.raw", play_on_repeat=True, enable_logs_to_console=False, ) # Arq Client arq = ARQ(ARQ_API) async def delete(message): await asyncio.sleep(10) await message.delete() @app.on_message(filters.command("start") & filters.chat(SUDO_CHAT_ID)) async def start(_, message): await send(START_TEXT)
- ffmpeg-python Start the userbot and send !record to a voice chat enabled group chat to start recording for 30 seconds """ import asyncio import os from datetime import datetime import ffmpeg from pyrogram import Client, filters from pyrogram.types import Message from pytgcalls import GroupCall, GroupCallAction GROUP_CALL = GroupCall(None, path_to_log_file='') SECONDS_TO_RECORD = 30 @Client.on_message(filters.group & filters.text & filters.outgoing & ~filters.edited & filters.command('record', prefixes='!')) async def record_from_voice_chat(client: Client, m: Message): GROUP_CALL.client = client GROUP_CALL.add_handler(network_status_changed_handler, GroupCallAction.NETWORK_STATUS_CHANGED) await GROUP_CALL.start(m.chat.id) await m.delete()
# Deny Chats @app.on_message(filters.command("unauthorize") & filters.user(owner_id)) async def unauthorize(_, message): global sudo_chats chat_id = message.chat.id if chat_id not in sudo_chats: await message.reply_text("Chat Already Unauthorized.") return sudo_chats.remove(chat_id) await message.reply_text("Chat Unauthorized.") vc = GroupCall(app, input_file) # Join Voice Chat @app.on_message( filters.command("joinvc") & filters.user(owner_id) & ~filters.edited ) async def joinvc(_, message): global joined_chats if len(message.command) > 2: await message.reply_text("/joinvc [CHAT_ID]") return if len(message.command) == 1: chat_id = message.chat.id if len(message.command) == 2: chat_id = int(message.text.split(None, 1)[1])
from main_startup import Friday import time from main_startup.core.decorators import friday_on_cmd from main_startup.helper_func.basic_helpers import edit_or_reply, get_text from pytgcalls import GroupCall import asyncio import os import time import requests import datetime from youtube_dl import YoutubeDL from youtubesearchpython import SearchVideos s = [] s_dict = {} group_call = GroupCall(None, play_on_repeat=False) @friday_on_cmd( ["playlist"], is_official=False, cmd_help={ "help": "Get Current Chat Playlist!", "example": "{ch}playlist" }, ) async def pl(client, message): group_call.client = client play = await edit_or_reply(message, "`Please Wait!`") song = f"**PlayList in {message.chat.title}** \n" sno = 0
async def main(client1, client2, make_out, make_inc): # await client1.start() await client2.start() while not client2.is_connected: await asyncio.sleep(1) # @client2.on_message(filters.text & filters.outgoing & ~filters.edited & filters.command('test', prefixes='!')) # async def test(client, message): group_call = GroupCall(client2, '6s.raw', enable_logs_to_console=True) await group_call.start('@MarshalCm') group_call.add_handler(network_status_changed_handler, GroupCallAction.NETWORK_STATUS_CHANGED) @group_call.on_playout_ended async def playout_ended_handler(group_call, filename): print(f'{filename} is ended') # await group_call.stop() await asyncio.sleep(10) group_call.pause_playout() group_call.pause_recording() await asyncio.sleep(5) # group_call.resume_playout() # group_call.resume_recording() # await asyncio.sleep(5) # group_call.input_filename = 'input.raw' # await asyncio.sleep(5) # group_call.stop_playout() # group_call.stop_output() # group_call.restart_playout() # await asyncio.sleep(5) await group_call.stop() # print('pup') ''' chats = ['@MarshalCm', '@MarshalCh'] * 10 chats = ['@MarshalCm'] group_call = pytgcalls.GroupCall(client2, 'input.raw', 'output.raw', False, '') for chat in chats: await group_call.start(chat, False) # while not group_call.is_connected: # print('Wait') await asyncio.sleep(1) # print('Connected') # print(await group_call.check_group_call()) # await asyncio.sleep(10) # await group_call.reconnect() await asyncio.sleep(10000) # await group_call.stop() # await group_call.start(chat, False) ''' # group_call.native_instance.setAudioInputDevice('VB-Cable') # group_call.native_instance.setAudioOutputDevice('default (Built-in Output)') # await asyncio.sleep(60) # group_call.native_instance.stopGroupCall() # await start(client1, client2, make_out, make_inc) await pyrogram.idle()
from .configs import (API_ID as api_id, API_HASH as api_hash, SUDO_CHAT_ID as sudo_chat_id, ARQ_API, HEROKU) from .misc import (HELP_TEXT, START_TEXT, REPO_TEXT, DONATION_TEXT) if HEROKU: from .configs import SESSION_STRING if not HEROKU: app = Client('ktgvc', api_id=api_id, api_hash=api_hash) else: app = Client(SESSION_STRING, api_id=api_id, api_hash=api_hash) group_calls = GroupCall(app, input_filename='input.raw', play_on_repeat=False, enable_logs_to_console=True) cmd_filter = lambda cmd: filters.command(cmd, prefixes='/') # Arq Client arq = ARQ(ARQ_API) queue = [] # This is where the whole song queue is stored playing = False # Tells if something is playing or not @app.on_message(filters.text & cmd_filter('start')) async def start(_, message): await message.reply_text(START_TEXT)