forked from AsmSafone/VideoPlayerBot
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaudio.py
More file actions
162 lines (148 loc) · 5.67 KB
/
Copy pathaudio.py
File metadata and controls
162 lines (148 loc) · 5.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import os
import re
import sys
import ffmpeg
import asyncio
import subprocess
from asyncio import sleep
from pyrogram import Client, filters
from pyrogram.types import Message
from helpers.bot_utils import USERNAME
from config import AUDIO_CALL, VIDEO_CALL
from plugins.video import ydl, group_call
from helpers.decorators import authorized_users_only, sudo_users_only
from pyrogram.types import InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery
@Client.on_message(filters.command(["play", f"play@{USERNAME}"]) & filters.group & ~filters.edited)
@authorized_users_only
async def play(client, m: Message):
msg = await m.reply_text("🔄 `Processing ...`")
chat_id = m.chat.id
media = m.reply_to_message
if not media and not ' ' in m.text:
await msg.edit("❗ __Send Me An Live Radio Link / YouTube Video Link / Reply To An Audio To Start Audio Streaming!__")
elif ' ' in m.text:
text = m.text.split(' ', 1)
query = text[1]
if not 'http' in query:
return await msg.edit("❗ __Send Me An Live Stream Link / YouTube Video Link / Reply To An Video To Start Video Streaming!__")
regex = r"^(https?\:\/\/)?(www\.youtube\.com|youtu\.?be)\/.+"
match = re.match(regex, query)
if match:
await msg.edit("🔄 `Starting YouTube Audio Stream ...`")
try:
meta = ydl.extract_info(query, download=False)
formats = meta.get('formats', [meta])
for f in formats:
ytstreamlink = f['url']
link = ytstreamlink
except Exception as e:
return await msg.edit(f"❌ **YouTube Download Error !** \n\n`{e}`")
print(e)
else:
await msg.edit("🔄 `Starting Live Audio Stream ...`")
link = query
vid_call = VIDEO_CALL.get(chat_id)
if vid_call:
await VIDEO_CALL[chat_id].stop()
VIDEO_CALL.pop(chat_id)
await sleep(3)
aud_call = AUDIO_CALL.get(chat_id)
if aud_call:
await AUDIO_CALL[chat_id].stop()
AUDIO_CALL.pop(chat_id)
await sleep(3)
try:
await sleep(2)
await group_call.join(chat_id)
await group_call.start_audio(link, repeat=False)
AUDIO_CALL[chat_id] = group_call
await msg.delete()
await m.reply_text(f"▶️ **Started [Audio Streaming]({query}) In {m.chat.title} !**",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="⏸",
callback_data="pause_callback",
),
InlineKeyboardButton(
text="▶️",
callback_data="resume_callback",
),
InlineKeyboardButton(
text="⏹️",
callback_data="end_callback",
),
],
]),
)
except Exception as e:
await msg.edit(f"❌ **An Error Occoured !** \n\nError: `{e}`")
return await group_call.stop()
elif media.audio or media.document:
await msg.edit("🔄 `Downloading ...`")
audio = await client.download_media(media)
vid_call = VIDEO_CALL.get(chat_id)
if vid_call:
await VIDEO_CALL[chat_id].stop()
VIDEO_CALL.pop(chat_id)
await sleep(3)
aud_call = AUDIO_CALL.get(chat_id)
if aud_call:
await AUDIO_CALL[chat_id].stop()
AUDIO_CALL.pop(chat_id)
await sleep(3)
try:
await sleep(2)
await group_call.join(chat_id)
await group_call.start_audio(audio, repeat=False)
AUDIO_CALL[chat_id] = group_call
await msg.delete()
await m.reply_text(f"▶️ **Started [Audio Streaming](https://t.me/AsmSafone) In {m.chat.title} !**",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
text="⏸",
callback_data="pause_callback",
),
InlineKeyboardButton(
text="▶️",
callback_data="resume_callback",
),
InlineKeyboardButton(
text="⏹️",
callback_data="end_callback",
),
],
]),
)
except Exception as e:
await msg.edit(f"❌ **An Error Occoured !** \n\nError: `{e}`")
return await group_call.stop()
else:
await msg.edit(
"💁🏻♂️ Do you want to search for a YouTube song?",
reply_markup=InlineKeyboardMarkup(
[
[
InlineKeyboardButton(
"✅ Yes", switch_inline_query_current_chat=""
),
InlineKeyboardButton(
"No ❌", callback_data="close"
)
]
]
)
)
@Client.on_message(filters.command(["restart", f"restart@{USERNAME}"]))
@sudo_users_only
async def restart(client, m: Message):
k = await m.reply_text("🔄 `Restarting ...`")
await sleep(3)
os.execl(sys.executable, sys.executable, *sys.argv)
try:
await k.edit("✅ **Restarted Successfully! \nJoin @AsmSafone For More!**")
except:
pass