MCPcopy Create free account
hub / github.com/AsmSafone/VideoPlayerBot / play

Function play

plugins/audio.py:19–150  ·  view source on GitHub ↗
(client, m: Message)

Source from the content-addressed store, hash-verified

17@Client.on_message(filters.command(["play", f"play@{USERNAME}"]) & filters.group & ~filters.edited)
18@authorized_users_only
19async def play(client, m: Message):
20 msg = await m.reply_text("🔄 `Processing ...`")
21 chat_id = m.chat.id
22 media = m.reply_to_message
23 if not media and not ' ' in m.text:
24 await msg.edit("❗ __Send Me An Live Radio Link / YouTube Video Link / Reply To An Audio To Start Audio Streaming!__")
25
26 elif ' ' in m.text:
27 text = m.text.split(' ', 1)
28 query = text[1]
29 if not 'http' in query:
30 return await msg.edit("❗ __Send Me An Live Stream Link / YouTube Video Link / Reply To An Video To Start Video Streaming!__")
31 regex = r"^(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+"
32 match = re.match(regex, query)
33 if match:
34 await msg.edit("🔄 `Starting YouTube Audio Stream ...`")
35 try:
36 meta = ydl.extract_info(query, download=False)
37 formats = meta.get('formats', [meta])
38 for f in formats:
39 ytstreamlink = f['url']
40 link = ytstreamlink
41 except Exception as e:
42 return await msg.edit(f"❌ **YouTube Download Error !** \n\n`{e}`")
43 print(e)
44
45 else:
46 await msg.edit("🔄 `Starting Live Audio Stream ...`")
47 link = query
48
49 vid_call = VIDEO_CALL.get(chat_id)
50 if vid_call:
51 await VIDEO_CALL[chat_id].stop()
52 VIDEO_CALL.pop(chat_id)
53 await sleep(3)
54
55 aud_call = AUDIO_CALL.get(chat_id)
56 if aud_call:
57 await AUDIO_CALL[chat_id].stop()
58 AUDIO_CALL.pop(chat_id)
59 await sleep(3)
60
61 try:
62 await sleep(2)
63 await group_call.join(chat_id)
64 await group_call.start_audio(link, repeat=False)
65 AUDIO_CALL[chat_id] = group_call
66 await msg.delete()
67 await m.reply_text(f"▶️ **Started [Audio Streaming]({query}) In {m.chat.title} !**",
68 reply_markup=InlineKeyboardMarkup(
69 [
70 [
71 InlineKeyboardButton(
72 text="⏸",
73 callback_data="pause_callback",
74 ),
75 InlineKeyboardButton(
76 text="▶️",

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected