-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvcplayer.py
More file actions
404 lines (362 loc) · 13.9 KB
/
vcplayer.py
File metadata and controls
404 lines (362 loc) · 13.9 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
# تعريب وتحديث فريق ريبـــثون
# Repthon UsetBot T.me/Repthon
# Devolper Baqir T.me/E_7_V
import asyncio
import logging
from telethon import TelegramClient
from telethon.sessions import StringSession
from telethon.tl.types import User
from repthon import Config, zq_lo
from repthon.core.managers import edit_delete, edit_or_reply
from .helper.stream_helper import Stream
from .helper.tg_downloader import tg_dl
from .helper.vcp_helper import RepVC
plugin_category = "المكالمات"
logging.getLogger("pytgcalls").setLevel(logging.ERROR)
OWNER_ID = zq_lo.uid
vc_session = Config.VC_SESSION
if vc_session:
vc_client = TelegramClient(
StringSession(vc_session), Config.APP_ID, Config.API_HASH
)
else:
vc_client = zq_lo
vc_client.__class__.__module__ = "telethon.client.telegramclient"
vc_player = RepVC(vc_client)
asyncio.create_task(vc_player.start())
@vc_player.app.on_stream_end()
async def handler(_, update):
await vc_player.handle_next(update)
ALLOWED_USERS = set()
@zq_lo.rep_cmd(
pattern="انضمام ?(\S+)? ?(?:ك)? ?(\S+)?",
command=("انضمام", plugin_category),
info={
"header": "لـ الانضمـام الى المحـادثه الصـوتيـه",
"ملاحظـه": "يمكنك اضافة الامر (ك) للامر الاساسي للانضمام الى المحادثه ك قنـاة مع اخفاء هويتك",
"امـر اضافـي": {
"ك": "للانضمام الى المحادثه ك قنـاة",
},
"الاستخـدام": [
"{tr}انضمام",
"{tr}انضمام + ايـدي المجمـوعـه",
"{tr}انضمام ك (peer_id)",
"{tr}انضمام (chat_id) ك (peer_id)",
],
"مثــال :": [
"{tr}انضمام",
"{tr}انضمام -1005895485",
"{tr}انضمام ك -1005895485",
"{tr}انضمام -1005895485 ك -1005895485",
],
},
)
async def joinVoicechat(event):
"لـ الانضمـام الى المحـادثه الصـوتيـه"
chat = event.pattern_match.group(1)
joinas = event.pattern_match.group(2)
await edit_or_reply(event, "**- جـارِ الانضمـام الى المحـادثـه الصـوتيـه ...**")
if chat and chat != "ك":
if chat.strip("-").isnumeric():
chat = int(chat)
else:
chat = event.chat_id
if vc_player.app.active_calls:
return await edit_delete(
event, f"**- انت منضـم مسبقـاً الـى** {vc_player.CHAT_NAME}"
)
try:
vc_chat = await zq_lo.get_entity(chat)
except Exception as e:
return await edit_delete(event, f'**- خطـأ** : \n{e or "UNKNOWN CHAT"}')
if isinstance(vc_chat, User):
return await edit_delete(
event, "**- المحـادثـه الصـوتيـه غيـر مدعومـه هنـا ؟!**"
)
if joinas and not vc_chat.username:
await edit_or_reply(
event, "**- لم استطـع الانضمـام الى الدردشـه الخـاصه .. قم بالانضمـام يدويـاً ...**"
)
joinas = False
out = await vc_player.join_vc(vc_chat, joinas)
await edit_delete(event, out)
@zq_lo.rep_cmd(
pattern="خروج",
command=("خروج", plugin_category),
info={
"header": "لـ المغـادره من المحـادثه الصـوتيـه",
"الاستخـدام": [
"{tr}خروج",
],
},
)
async def leaveVoicechat(event):
"لـ المغـادره من المحـادثه الصـوتيـه"
if vc_player.CHAT_ID:
await edit_or_reply(event, "**- جـارِ مغـادرة المحـادثـة الصـوتيـه ...**")
chat_name = vc_player.CHAT_NAME
await vc_player.leave_vc()
await edit_delete(event, f"**- تم مغـادرة المكـالمـه** {chat_name}")
else:
await edit_delete(event, "**- لم تنضم بعـد للمكالمـه ؟!**")
@zq_lo.rep_cmd(
pattern="قائمة التشغيل",
command=("قائمة التشغيل", plugin_category),
info={
"header": "لـ جلب كـل المقـاطع المضـافه لقائمـة التشغيـل في المكالمـه",
"الاستخـدام": [
"{tr}قائمة التشغيل",
],
},
)
async def get_playlist(event):
"لـ جلب كـل المقـاطع المضـافه لقائمـة التشغيـل في المكالمـه"
await edit_or_reply(event, "**- جـارِ جلب قائمـة التشغيـل ...**")
playl = vc_player.PLAYLIST
if not playl:
await edit_delete(event, "Playlist empty", time=10)
else:
rep = ""
for num, item in enumerate(playl, 1):
if item["stream"] == Stream.audio:
rep += f"{num}- `{item['title']}`\n"
else:
rep += f"{num}- `{item['title']}`\n"
await edit_delete(event, f"**- قائمـة التشغيـل :**\n\n{rep}\n**Enjoy the show**")
@zq_lo.rep_cmd(
pattern="فيد ?(1)? ?([\S ]*)?",
command=("فيد", plugin_category),
info={
"header": "تشغيـل مقـاطع الفيـديـو في المكـالمـات",
"امـر اضافـي": {
"1": "فرض تشغيـل المقطـع بالقـوة",
},
"الاستخـدام": [
"{tr}فيد بالــرد ع فيـديـو",
"{tr}فيد + رابـط",
"{tr}فيد ف + رابـط",
],
"مثــال :": [
"{tr}فيد بالـرد",
"{tr}فيد https://www.youtube.com/watch?v=c05GBLT_Ds0",
"{tr}فيد 1 https://www.youtube.com/watch?v=c05GBLT_Ds0",
],
},
)
async def play_video(event):
"لـ تشغيـل مقـاطع الفيـديـو في المكـالمـات"
con = event.pattern_match.group(1).lower()
flag = event.pattern_match.group(1)
input_str = event.pattern_match.group(2)
if con == "فيديو":
return
if input_str == "" and event.reply_to_msg_id:
input_str = await tg_dl(event)
if not input_str:
return await edit_delete(
event, "**- قـم بـ إدخـال رابـط مقطع الفيديـو للتشغيـل...**", time=20
)
if not vc_player.CHAT_ID:
return await edit_or_reply(event, "**- قـم بالانضمـام اولاً الى المكالمـه عبـر الامـر .انضمام**")
if not input_str:
return await edit_or_reply(event, "**- قـم بـ إدخـال رابـط مقطع الفيديـو للتشغيـل...**")
await edit_or_reply(event, "**╮ جـارِ تشغيـل مقطـٓـع الفيـٓـديو في المكـالمـه... 🎧♥️╰**")
if flag:
resp = await vc_player.play_song(input_str, Stream.video, force=True)
else:
resp = await vc_player.play_song(input_str, Stream.video, force=False)
if resp:
await edit_delete(event, resp, time=30)
@zq_lo.rep_cmd(
pattern="شغل ?(1)? ?([\S ]*)?",
command=("شغل", plugin_category),
info={
"header": "تشغيـل المقـاطع الصـوتيـه في المكـالمـات",
"امـر اضافـي": {
"1": "فرض تشغيـل المقطـع بالقـوة",
},
"الاستخـدام": [
"{tr}شغل بالــرد ع مقطـع صـوتي",
"{tr}شغل + رابـط",
"{tr}شغل 1 + رابـط",
],
"مثــال :": [
"{tr}شغل بالـرد",
"{tr}شغل https://www.youtube.com/watch?v=c05GBLT_Ds0",
"{tr}شغل 1 https://www.youtube.com/watch?v=c05GBLT_Ds0",
],
},
)
async def play_audio(event):
"لـ تشغيـل المقـاطع الصـوتيـه في المكـالمـات"
flag = event.pattern_match.group(1)
input_str = event.pattern_match.group(2)
if input_str == "" and event.reply_to_msg_id:
input_str = await tg_dl(event)
if not input_str:
return await edit_delete(
event, "**- قـم بـ إدخـال رابـط المقطـع الصوتـي للتشغيـل...**", time=20
)
if not vc_player.CHAT_ID:
return await edit_or_reply(event, "**- قـم بالانضمـام اولاً الى المكالمـه عبـر الامـر .انضمام**")
if not input_str:
return await edit_or_reply(event, "**- قـم بـ إدخـال رابـط المقطـع الصوتـي للتشغيـل...**")
await edit_or_reply(event, "**╮ جـارِ تشغيـل المقطـٓـع الصـٓـوتي في المكـالمـه... 🎧♥️╰**")
if flag:
resp = await vc_player.play_song(input_str, Stream.audio, force=True)
else:
resp = await vc_player.play_song(input_str, Stream.audio, force=False)
if resp:
await edit_delete(event, resp, time=30)
@zq_lo.rep_cmd(
pattern="توقف",
command=("توقف", plugin_category),
info={
"header": "لـ ايقـاف تشغيـل للمقطـع مؤقتـاً في المكـالمـه",
"الاستخـدام": [
"{tr}تمهل",
],
},
)
async def pause_stream(event):
"لـ ايقـاف تشغيـل للمقطـع مؤقتـاً في المكـالمـه"
await edit_or_reply(event, "**- جـارِ الايقـاف مؤقتـاً ...**")
res = await vc_player.pause()
await edit_delete(event, res, time=30)
@zq_lo.rep_cmd(
pattern="كمل",
command=("كمل", plugin_category),
info={
"header": "لـ متابعـة تشغيـل المقطـع في المكـالمـه",
"الاستخـدام": [
"{tr}تابع",
],
},
)
async def resume_stream(event):
"لـ متابعـة تشغيـل المقطـع في المكـالمـه"
await edit_or_reply(event, "**- جـار الاستئنـاف ...**")
res = await vc_player.resume()
await edit_delete(event, res, time=30)
@zq_lo.rep_cmd(
pattern="تخطي",
command=("تخطي", plugin_category),
info={
"header": "لـ تخطي تشغيـل المقطـع وتشغيـل المقطـع التالـي في المكـالمـه",
"الاستخـدام": [
"{tr}تخطي",
],
},
)
async def skip_stream(event):
"لـ تخطي تشغيـل المقطـع وتشغيـل المقطـع التالـي في المكـالمـه"
await edit_or_reply(event, "**- جـار التخطـي ...**")
res = await vc_player.skip()
await edit_delete(event, res, time=30)
"""
@zq_lo.rep_cmd(
pattern="a(?:llow)?vc ?([\d ]*)?",
command=("allowvc", plugin_category),
info={
"header": "To allow a user to control VC.",
"الوصـف": "To allow a user to controll VC.",
"الاستخـدام": [
"{tr}allowvc",
"{tr}allowvc (user id)",
],
},
)
async def allowvc(event):
"To allow a user to controll VC."
user_id = event.pattern_match.group(1)
if user_id:
user_id = user_id.split(" ")
if not user_id and event.reply_to_msg_id:
reply = await event.get_reply_message()
user_id = [reply.from_id]
if not user_id:
return await edit_delete(event, "Whom should i Add")
ALLOWED_USERS.update(user_id)
return await edit_delete(event, "Added User to Allowed List")
@zq_lo.rep_cmd(
pattern="d(?:isallow)?vc ?([\d ]*)?",
command=("disallowvc", plugin_category),
info={
"header": "To disallowvc a user to control VC.",
"الوصـف": "To disallowvc a user to controll VC.",
"الاستخـدام": [
"{tr}disallowvc",
"{tr}disallowvc (user id)",
],
},
)
async def disallowvc(event):
"To allow a user to controll VC."
user_id = event.pattern_match.group(1)
if user_id:
user_id = user_id.split(" ")
if not user_id and event.reply_to_msg_id:
reply = await event.get_reply_message()
user_id = [reply.from_id]
if not user_id:
return await edit_delete(event, "Whom should i remove")
ALLOWED_USERS.difference_update(user_id)
return await edit_delete(event, "Removed User to Allowed List")
@zq_lo.on(
events.NewMessage(outgoing=True, pattern=f"{tr}(speak|sp)(h|j)?(?:\s|$)([\s\S]*)")
) #only for zq_lo client
async def speak(event):
"Speak in vc"
r = event.pattern_match.group(2)
input_str = event.pattern_match.group(3)
re = await event.get_reply_message()
if ";" in input_str:
lan, text = input_str.split(";")
else:
if input_str:
text = input_str
elif re and re.text and not input_str:
text = re.message
else:
return await event.delete()
if r == "h":
lan = "hi"
elif r == "j":
lan = "ja"
else:
lan = "en"
text = deEmojify(text.strip())
lan = lan.strip()
if not os.path.isdir("./temp/"):
os.makedirs("./temp/")
file = "./temp/" + "voice.ogg"
try:
tts = gTTS(text, lang=lan)
tts.save(file)
cmd = [
"ffmpeg",
"-i",
file,
"-map",
"0:a",
"-codec:a",
"libopus",
"-b:a",
"100k",
"-vbr",
"on",
file + ".opus",
]
try:
t_response = subprocess.check_output(cmd, stderr=subprocess.STDOUT)
except (subprocess.CalledProcessError, NameError, FileNotFoundError) as exc:
await edit_or_reply(event, str(exc))
else:
os.remove(file)
file = file + ".opus"
await vc_player.play_song(file, Stream.audio, force=False)
await event.delete()
os.remove(file)
except Exception as e:
await edit_or_reply(event, f"**Error:**\n`{e}`")
"""