Spaces:
Running
Running
Update DragMusic/plugins/play/play.py
Browse files- DragMusic/plugins/play/play.py +608 -554
DragMusic/plugins/play/play.py
CHANGED
@@ -1,554 +1,608 @@
|
|
1 |
-
import random
|
2 |
-
import string
|
3 |
-
|
4 |
-
from pyrogram import filters
|
5 |
-
from pyrogram.types import InlineKeyboardMarkup, InputMediaPhoto, Message
|
6 |
-
from pytgcalls.exceptions import NoActiveGroupCall
|
7 |
-
|
8 |
-
import config
|
9 |
-
from DragMusic import Apple, Resso, SoundCloud, Spotify, Telegram, YouTube, app
|
10 |
-
from DragMusic.core.call import Drag
|
11 |
-
from DragMusic.utils import seconds_to_min, time_to_seconds
|
12 |
-
from DragMusic.utils.channelplay import get_channeplayCB
|
13 |
-
from DragMusic.utils.decorators.language import languageCB
|
14 |
-
from DragMusic.utils.decorators.play import PlayWrapper
|
15 |
-
from DragMusic.utils.formatters import formats
|
16 |
-
from DragMusic.utils.inline import (
|
17 |
-
botplaylist_markup,
|
18 |
-
livestream_markup,
|
19 |
-
playlist_markup,
|
20 |
-
slider_markup,
|
21 |
-
track_markup,
|
22 |
-
)
|
23 |
-
from DragMusic.utils.logger import play_logs
|
24 |
-
from DragMusic.utils.stream.stream import stream
|
25 |
-
from
|
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 |
-
if
|
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 |
-
await
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
)
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
message.
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
return await
|
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 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
)
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
)
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
515 |
-
|
516 |
-
|
517 |
-
)
|
518 |
-
|
519 |
-
|
520 |
-
|
521 |
-
|
522 |
-
|
523 |
-
|
524 |
-
|
525 |
-
|
526 |
-
|
527 |
-
|
528 |
-
|
529 |
-
|
530 |
-
|
531 |
-
|
532 |
-
|
533 |
-
|
534 |
-
|
535 |
-
|
536 |
-
|
537 |
-
|
538 |
-
|
539 |
-
|
540 |
-
|
541 |
-
|
542 |
-
|
543 |
-
|
544 |
-
|
545 |
-
|
546 |
-
|
547 |
-
|
548 |
-
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
import string
|
3 |
+
|
4 |
+
from pyrogram import filters
|
5 |
+
from pyrogram.types import InlineKeyboardMarkup, InputMediaPhoto, Message, InlineKeyboardButton, WebAppInfo
|
6 |
+
from pytgcalls.exceptions import NoActiveGroupCall
|
7 |
+
|
8 |
+
import config
|
9 |
+
from DragMusic import Apple, Resso, SoundCloud, Spotify, Telegram, YouTube, app
|
10 |
+
from DragMusic.core.call import Drag
|
11 |
+
from DragMusic.utils import seconds_to_min, time_to_seconds
|
12 |
+
from DragMusic.utils.channelplay import get_channeplayCB
|
13 |
+
from DragMusic.utils.decorators.language import languageCB
|
14 |
+
from DragMusic.utils.decorators.play import PlayWrapper
|
15 |
+
from DragMusic.utils.formatters import formats
|
16 |
+
from DragMusic.utils.inline import (
|
17 |
+
botplaylist_markup,
|
18 |
+
livestream_markup,
|
19 |
+
playlist_markup,
|
20 |
+
slider_markup,
|
21 |
+
track_markup,
|
22 |
+
)
|
23 |
+
from DragMusic.utils.logger import play_logs
|
24 |
+
from DragMusic.utils.stream.stream import stream
|
25 |
+
from DragMusic.core import nowplaying
|
26 |
+
from config import BANNED_USERS, lyrical
|
27 |
+
|
28 |
+
|
29 |
+
@app.on_message(
|
30 |
+
filters.command(
|
31 |
+
[
|
32 |
+
"play",
|
33 |
+
"vplay",
|
34 |
+
"cplay",
|
35 |
+
"cvplay",
|
36 |
+
"playforce",
|
37 |
+
"vplayforce",
|
38 |
+
"cplayforce",
|
39 |
+
"cvplayforce",
|
40 |
+
]
|
41 |
+
)
|
42 |
+
& filters.group
|
43 |
+
& ~BANNED_USERS
|
44 |
+
)
|
45 |
+
@PlayWrapper
|
46 |
+
async def play_commnd(
|
47 |
+
client,
|
48 |
+
message: Message,
|
49 |
+
_,
|
50 |
+
chat_id,
|
51 |
+
video,
|
52 |
+
channel,
|
53 |
+
playmode,
|
54 |
+
url,
|
55 |
+
fplay,
|
56 |
+
):
|
57 |
+
mystic = await message.reply_text(
|
58 |
+
_["play_2"].format(channel) if channel else _["play_1"]
|
59 |
+
)
|
60 |
+
plist_id = None
|
61 |
+
slider = None
|
62 |
+
plist_type = None
|
63 |
+
spotify = None
|
64 |
+
user_id = message.from_user.id
|
65 |
+
user_name = message.from_user.first_name
|
66 |
+
audio_telegram = (
|
67 |
+
(message.reply_to_message.audio or message.reply_to_message.voice)
|
68 |
+
if message.reply_to_message
|
69 |
+
else None
|
70 |
+
)
|
71 |
+
video_telegram = (
|
72 |
+
(message.reply_to_message.video or message.reply_to_message.document)
|
73 |
+
if message.reply_to_message
|
74 |
+
else None
|
75 |
+
)
|
76 |
+
if audio_telegram:
|
77 |
+
if audio_telegram.file_size > 104857600:
|
78 |
+
return await mystic.edit_text(_["play_5"])
|
79 |
+
duration_min = seconds_to_min(audio_telegram.duration)
|
80 |
+
if (audio_telegram.duration) > config.DURATION_LIMIT:
|
81 |
+
return await mystic.edit_text(
|
82 |
+
_["play_6"].format(config.DURATION_LIMIT_MIN, app.mention)
|
83 |
+
)
|
84 |
+
file_path = await Telegram.get_filepath(audio=audio_telegram)
|
85 |
+
if await Telegram.download(_, message, mystic, file_path):
|
86 |
+
message_link = await Telegram.get_link(message)
|
87 |
+
file_name = await Telegram.get_filename(audio_telegram, audio=True)
|
88 |
+
dur = await Telegram.get_duration(audio_telegram, file_path)
|
89 |
+
details = {
|
90 |
+
"title": file_name,
|
91 |
+
"link": message_link,
|
92 |
+
"path": file_path,
|
93 |
+
"dur": dur,
|
94 |
+
}
|
95 |
+
# Store current song info for web player
|
96 |
+
nowplaying.set_current_song(details)
|
97 |
+
try:
|
98 |
+
await stream(
|
99 |
+
_,
|
100 |
+
mystic,
|
101 |
+
user_id,
|
102 |
+
details,
|
103 |
+
chat_id,
|
104 |
+
user_name,
|
105 |
+
message.chat.id,
|
106 |
+
streamtype="telegram",
|
107 |
+
forceplay=fplay,
|
108 |
+
)
|
109 |
+
except Exception as e:
|
110 |
+
print(f"Error: {e}")
|
111 |
+
ex_type = type(e).__name__
|
112 |
+
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
|
113 |
+
return await mystic.edit_text(err)
|
114 |
+
return await mystic.delete()
|
115 |
+
return
|
116 |
+
elif video_telegram:
|
117 |
+
if message.reply_to_message.document:
|
118 |
+
try:
|
119 |
+
ext = video_telegram.file_name.split(".")[-1]
|
120 |
+
if ext.lower() not in formats:
|
121 |
+
return await mystic.edit_text(
|
122 |
+
_["play_7"].format(f"{' | '.join(formats)}")
|
123 |
+
)
|
124 |
+
except:
|
125 |
+
return await mystic.edit_text(
|
126 |
+
_["play_7"].format(f"{' | '.join(formats)}")
|
127 |
+
)
|
128 |
+
if video_telegram.file_size > config.TG_VIDEO_FILESIZE_LIMIT:
|
129 |
+
return await mystic.edit_text(_["play_8"])
|
130 |
+
file_path = await Telegram.get_filepath(video=video_telegram)
|
131 |
+
if await Telegram.download(_, message, mystic, file_path):
|
132 |
+
message_link = await Telegram.get_link(message)
|
133 |
+
file_name = await Telegram.get_filename(video_telegram)
|
134 |
+
dur = await Telegram.get_duration(video_telegram, file_path)
|
135 |
+
details = {
|
136 |
+
"title": file_name,
|
137 |
+
"link": message_link,
|
138 |
+
"path": file_path,
|
139 |
+
"dur": dur,
|
140 |
+
}
|
141 |
+
# Store current song info for web player
|
142 |
+
nowplaying.set_current_song(details)
|
143 |
+
try:
|
144 |
+
await stream(
|
145 |
+
_,
|
146 |
+
mystic,
|
147 |
+
user_id,
|
148 |
+
details,
|
149 |
+
chat_id,
|
150 |
+
user_name,
|
151 |
+
message.chat.id,
|
152 |
+
video=True,
|
153 |
+
streamtype="telegram",
|
154 |
+
forceplay=fplay,
|
155 |
+
)
|
156 |
+
except Exception as e:
|
157 |
+
print(f"Error: {e}")
|
158 |
+
ex_type = type(e).__name__
|
159 |
+
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
|
160 |
+
return await mystic.edit_text(err)
|
161 |
+
return await mystic.delete()
|
162 |
+
return
|
163 |
+
elif url:
|
164 |
+
if await YouTube.exists(url):
|
165 |
+
if "playlist" in url:
|
166 |
+
try:
|
167 |
+
details = await YouTube.playlist(
|
168 |
+
url,
|
169 |
+
config.PLAYLIST_FETCH_LIMIT,
|
170 |
+
message.from_user.id,
|
171 |
+
)
|
172 |
+
except:
|
173 |
+
return await mystic.edit_text(_["play_3"])
|
174 |
+
streamtype = "playlist"
|
175 |
+
plist_type = "yt"
|
176 |
+
if "&" in url:
|
177 |
+
plist_id = (url.split("=")[1]).split("&")[0]
|
178 |
+
else:
|
179 |
+
plist_id = url.split("=")[1]
|
180 |
+
img = config.PLAYLIST_IMG_URL
|
181 |
+
cap = _["play_9"]
|
182 |
+
else:
|
183 |
+
try:
|
184 |
+
details, track_id = await YouTube.track(url)
|
185 |
+
except:
|
186 |
+
return await mystic.edit_text(_["play_3"])
|
187 |
+
streamtype = "youtube"
|
188 |
+
img = details["thumb"]
|
189 |
+
cap = _["play_10"].format(
|
190 |
+
details["title"],
|
191 |
+
details["duration_min"],
|
192 |
+
)
|
193 |
+
elif await Spotify.valid(url):
|
194 |
+
spotify = True
|
195 |
+
if not config.SPOTIFY_CLIENT_ID and not config.SPOTIFY_CLIENT_SECRET:
|
196 |
+
return await mystic.edit_text(
|
197 |
+
"» sᴘᴏᴛɪғʏ ɪs ɴᴏᴛ sᴜᴘᴘᴏʀᴛᴇᴅ ʏᴇᴛ.\n\nᴘʟᴇᴀsᴇ ᴛʀʏ ᴀɢᴀɪɴ ʟᴀᴛᴇʀ."
|
198 |
+
)
|
199 |
+
if "track" in url:
|
200 |
+
try:
|
201 |
+
details, track_id = await Spotify.track(url)
|
202 |
+
except:
|
203 |
+
return await mystic.edit_text(_["play_3"])
|
204 |
+
streamtype = "youtube"
|
205 |
+
img = details["thumb"]
|
206 |
+
cap = _["play_10"].format(details["title"], details["duration_min"])
|
207 |
+
elif "playlist" in url:
|
208 |
+
try:
|
209 |
+
details, plist_id = await Spotify.playlist(url)
|
210 |
+
except Exception:
|
211 |
+
return await mystic.edit_text(_["play_3"])
|
212 |
+
streamtype = "playlist"
|
213 |
+
plist_type = "spplay"
|
214 |
+
img = config.SPOTIFY_PLAYLIST_IMG_URL
|
215 |
+
cap = _["play_11"].format(app.mention, message.from_user.mention)
|
216 |
+
elif "album" in url:
|
217 |
+
try:
|
218 |
+
details, plist_id = await Spotify.album(url)
|
219 |
+
except:
|
220 |
+
return await mystic.edit_text(_["play_3"])
|
221 |
+
streamtype = "playlist"
|
222 |
+
plist_type = "spalbum"
|
223 |
+
img = config.SPOTIFY_ALBUM_IMG_URL
|
224 |
+
cap = _["play_11"].format(app.mention, message.from_user.mention)
|
225 |
+
elif "artist" in url:
|
226 |
+
try:
|
227 |
+
details, plist_id = await Spotify.artist(url)
|
228 |
+
except:
|
229 |
+
return await mystic.edit_text(_["play_3"])
|
230 |
+
streamtype = "playlist"
|
231 |
+
plist_type = "spartist"
|
232 |
+
img = config.SPOTIFY_ARTIST_IMG_URL
|
233 |
+
cap = _["play_11"].format(message.from_user.first_name)
|
234 |
+
else:
|
235 |
+
return await mystic.edit_text(_["play_15"])
|
236 |
+
elif await Apple.valid(url):
|
237 |
+
if "album" in url:
|
238 |
+
try:
|
239 |
+
details, track_id = await Apple.track(url)
|
240 |
+
except:
|
241 |
+
return await mystic.edit_text(_["play_3"])
|
242 |
+
streamtype = "youtube"
|
243 |
+
img = details["thumb"]
|
244 |
+
cap = _["play_10"].format(details["title"], details["duration_min"])
|
245 |
+
elif "playlist" in url:
|
246 |
+
spotify = True
|
247 |
+
try:
|
248 |
+
details, plist_id = await Apple.playlist(url)
|
249 |
+
except:
|
250 |
+
return await mystic.edit_text(_["play_3"])
|
251 |
+
streamtype = "playlist"
|
252 |
+
plist_type = "apple"
|
253 |
+
cap = _["play_12"].format(app.mention, message.from_user.mention)
|
254 |
+
img = url
|
255 |
+
else:
|
256 |
+
return await mystic.edit_text(_["play_3"])
|
257 |
+
elif await Resso.valid(url):
|
258 |
+
try:
|
259 |
+
details, track_id = await Resso.track(url)
|
260 |
+
except:
|
261 |
+
return await mystic.edit_text(_["play_3"])
|
262 |
+
streamtype = "youtube"
|
263 |
+
img = details["thumb"]
|
264 |
+
cap = _["play_10"].format(details["title"], details["duration_min"])
|
265 |
+
elif await SoundCloud.valid(url):
|
266 |
+
try:
|
267 |
+
details, track_path = await SoundCloud.download(url)
|
268 |
+
except:
|
269 |
+
return await mystic.edit_text(_["play_3"])
|
270 |
+
duration_sec = details["duration_sec"]
|
271 |
+
if duration_sec > config.DURATION_LIMIT:
|
272 |
+
return await mystic.edit_text(
|
273 |
+
_["play_6"].format(
|
274 |
+
config.DURATION_LIMIT_MIN,
|
275 |
+
app.mention,
|
276 |
+
)
|
277 |
+
)
|
278 |
+
try:
|
279 |
+
await stream(
|
280 |
+
_,
|
281 |
+
mystic,
|
282 |
+
user_id,
|
283 |
+
details,
|
284 |
+
chat_id,
|
285 |
+
user_name,
|
286 |
+
message.chat.id,
|
287 |
+
streamtype="soundcloud",
|
288 |
+
forceplay=fplay,
|
289 |
+
)
|
290 |
+
except Exception as e:
|
291 |
+
print(f"Error: {e}")
|
292 |
+
ex_type = type(e).__name__
|
293 |
+
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
|
294 |
+
return await mystic.edit_text(err)
|
295 |
+
return await mystic.delete()
|
296 |
+
else:
|
297 |
+
try:
|
298 |
+
await Aviax.stream_call(url)
|
299 |
+
except NoActiveGroupCall:
|
300 |
+
await mystic.edit_text(_["black_9"])
|
301 |
+
return await app.send_message(
|
302 |
+
chat_id=config.LOG_GROUP_ID,
|
303 |
+
text=_["play_17"],
|
304 |
+
)
|
305 |
+
except Exception as e:
|
306 |
+
print(f"Error: {e}")
|
307 |
+
return await mystic.edit_text(_["general_2"].format(type(e).__name__))
|
308 |
+
await mystic.edit_text(_["str_2"])
|
309 |
+
try:
|
310 |
+
await stream(
|
311 |
+
_,
|
312 |
+
mystic,
|
313 |
+
message.from_user.id,
|
314 |
+
url,
|
315 |
+
chat_id,
|
316 |
+
message.from_user.first_name,
|
317 |
+
message.chat.id,
|
318 |
+
video=video,
|
319 |
+
streamtype="index",
|
320 |
+
forceplay=fplay,
|
321 |
+
)
|
322 |
+
except Exception as e:
|
323 |
+
print(f"Error: {e}")
|
324 |
+
ex_type = type(e).__name__
|
325 |
+
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
|
326 |
+
return await mystic.edit_text(err)
|
327 |
+
return await play_logs(message, streamtype="M3u8 or Index Link")
|
328 |
+
else:
|
329 |
+
if len(message.command) < 2:
|
330 |
+
buttons = botplaylist_markup(_)
|
331 |
+
return await mystic.edit_text(
|
332 |
+
_["play_18"],
|
333 |
+
reply_markup=InlineKeyboardMarkup(buttons),
|
334 |
+
)
|
335 |
+
slider = True
|
336 |
+
query = message.text.split(None, 1)[1]
|
337 |
+
if "-v" in query:
|
338 |
+
query = query.replace("-v", "")
|
339 |
+
try:
|
340 |
+
details, track_id = await YouTube.track(query)
|
341 |
+
except Exception as e:
|
342 |
+
await mystic.edit_text(f"Failed to fetch video details: {e}")
|
343 |
+
return
|
344 |
+
if not details:
|
345 |
+
await mystic.edit_text("❌ Could not fetch video details. Please try again later.")
|
346 |
+
return
|
347 |
+
streamtype = "youtube"
|
348 |
+
if str(playmode) == "Direct":
|
349 |
+
if not plist_type:
|
350 |
+
if details["duration_min"]:
|
351 |
+
duration_sec = time_to_seconds(details["duration_min"])
|
352 |
+
if duration_sec > config.DURATION_LIMIT:
|
353 |
+
return await mystic.edit_text(
|
354 |
+
_["play_6"].format(config.DURATION_LIMIT_MIN, app.mention)
|
355 |
+
)
|
356 |
+
else:
|
357 |
+
buttons = livestream_markup(
|
358 |
+
_,
|
359 |
+
track_id,
|
360 |
+
user_id,
|
361 |
+
"v" if video else "a",
|
362 |
+
"c" if channel else "g",
|
363 |
+
"f" if fplay else "d",
|
364 |
+
)
|
365 |
+
return await mystic.edit_text(
|
366 |
+
_["play_13"],
|
367 |
+
reply_markup=InlineKeyboardMarkup(buttons),
|
368 |
+
)
|
369 |
+
try:
|
370 |
+
await stream(
|
371 |
+
_,
|
372 |
+
mystic,
|
373 |
+
user_id,
|
374 |
+
details,
|
375 |
+
chat_id,
|
376 |
+
user_name,
|
377 |
+
message.chat.id,
|
378 |
+
video=video,
|
379 |
+
streamtype=streamtype,
|
380 |
+
spotify=spotify,
|
381 |
+
forceplay=fplay,
|
382 |
+
)
|
383 |
+
except Exception as e:
|
384 |
+
print(f"Error: {e}")
|
385 |
+
ex_type = type(e).__name__
|
386 |
+
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
|
387 |
+
return await mystic.edit_text(err)
|
388 |
+
await mystic.delete()
|
389 |
+
return await play_logs(message, streamtype=streamtype)
|
390 |
+
else:
|
391 |
+
if plist_type:
|
392 |
+
ran_hash = "".join(
|
393 |
+
random.choices(string.ascii_uppercase + string.digits, k=10)
|
394 |
+
)
|
395 |
+
lyrical[ran_hash] = plist_id
|
396 |
+
buttons = playlist_markup(
|
397 |
+
_,
|
398 |
+
ran_hash,
|
399 |
+
message.from_user.id,
|
400 |
+
plist_type,
|
401 |
+
"c" if channel else "g",
|
402 |
+
"f" if fplay else "d",
|
403 |
+
)
|
404 |
+
await mystic.delete()
|
405 |
+
await message.reply_photo(
|
406 |
+
photo=img,
|
407 |
+
caption=cap,
|
408 |
+
reply_markup=InlineKeyboardMarkup(buttons),
|
409 |
+
)
|
410 |
+
return await play_logs(message, streamtype=f"Playlist : {plist_type}")
|
411 |
+
else:
|
412 |
+
if slider:
|
413 |
+
buttons = slider_markup(
|
414 |
+
_,
|
415 |
+
track_id,
|
416 |
+
message.from_user.id,
|
417 |
+
query,
|
418 |
+
0,
|
419 |
+
"c" if channel else "g",
|
420 |
+
"f" if fplay else "d",
|
421 |
+
)
|
422 |
+
await mystic.delete()
|
423 |
+
await message.reply_photo(
|
424 |
+
photo=details["thumb"],
|
425 |
+
caption=_["play_10"].format(
|
426 |
+
details["title"].title(),
|
427 |
+
details["duration_min"],
|
428 |
+
),
|
429 |
+
reply_markup=InlineKeyboardMarkup(buttons),
|
430 |
+
)
|
431 |
+
return await play_logs(message, streamtype=f"Searched on Youtube")
|
432 |
+
else:
|
433 |
+
buttons = track_markup(
|
434 |
+
_,
|
435 |
+
track_id,
|
436 |
+
message.from_user.id,
|
437 |
+
"c" if channel else "g",
|
438 |
+
"f" if fplay else "d",
|
439 |
+
)
|
440 |
+
await mystic.delete()
|
441 |
+
await message.reply_photo(
|
442 |
+
photo=img,
|
443 |
+
caption=cap,
|
444 |
+
reply_markup=InlineKeyboardMarkup(buttons),
|
445 |
+
)
|
446 |
+
return await play_logs(message, streamtype=f"URL Searched Inline")
|
447 |
+
|
448 |
+
|
449 |
+
@app.on_message(filters.command("webplay") & ~BANNED_USERS)
|
450 |
+
async def webplay_command(client, message: Message):
|
451 |
+
query = None
|
452 |
+
if len(message.command) > 1:
|
453 |
+
query = " ".join(message.command[1:])
|
454 |
+
else:
|
455 |
+
await message.reply_text("Please provide a song name or YouTube link to play in the web app.")
|
456 |
+
return
|
457 |
+
mystic = await message.reply_text("Searching for your song on YouTube...")
|
458 |
+
# Search YouTube and get track info
|
459 |
+
try:
|
460 |
+
details, track_id = await YouTube.track(query)
|
461 |
+
except Exception as e:
|
462 |
+
await mystic.edit_text(f"Failed to find song: {e}")
|
463 |
+
return
|
464 |
+
if not details:
|
465 |
+
await mystic.edit_text("❌ Could not fetch video details. Please try again later.")
|
466 |
+
return
|
467 |
+
# Download audio
|
468 |
+
try:
|
469 |
+
file_path, _ = await YouTube.download(details["link"], mystic)
|
470 |
+
except Exception as e:
|
471 |
+
await mystic.edit_text(f"Failed to download song: {e}")
|
472 |
+
return
|
473 |
+
# Store in nowplaying
|
474 |
+
song_info = {
|
475 |
+
"title": details["title"],
|
476 |
+
"link": details["link"],
|
477 |
+
"path": file_path,
|
478 |
+
"dur": details["duration_min"],
|
479 |
+
"thumb": details.get("thumb"),
|
480 |
+
}
|
481 |
+
nowplaying.set_current_song(song_info)
|
482 |
+
# Delete the status message before sending the web app button
|
483 |
+
try:
|
484 |
+
await mystic.delete()
|
485 |
+
except:
|
486 |
+
pass
|
487 |
+
await message.reply(
|
488 |
+
"Song is ready in the mini web app!",
|
489 |
+
reply_markup=InlineKeyboardMarkup(
|
490 |
+
[[InlineKeyboardButton("Open Player", web_app=WebAppInfo(url="https://huggingface.co/spaces/dragonxd1/DragMusicV2"))]]
|
491 |
+
)
|
492 |
+
)
|
493 |
+
|
494 |
+
|
495 |
+
@app.on_callback_query(filters.regex("MusicStream") & ~BANNED_USERS)
|
496 |
+
@languageCB
|
497 |
+
async def play_music(client, CallbackQuery, _):
|
498 |
+
callback_data = CallbackQuery.data.strip()
|
499 |
+
callback_request = callback_data.split(None, 1)[1]
|
500 |
+
vidid, user_id, mode, cplay, fplay = callback_request.split("|")
|
501 |
+
if CallbackQuery.from_user.id != int(user_id):
|
502 |
+
try:
|
503 |
+
return await CallbackQuery.answer(_["playcb_1"], show_alert=True)
|
504 |
+
except:
|
505 |
+
return
|
506 |
+
try:
|
507 |
+
chat_id, channel = await get_channeplayCB(_, cplay, CallbackQuery)
|
508 |
+
except:
|
509 |
+
return
|
510 |
+
user_name = CallbackQuery.from_user.first_name
|
511 |
+
try:
|
512 |
+
await CallbackQuery.message.delete()
|
513 |
+
await CallbackQuery.answer()
|
514 |
+
except:
|
515 |
+
pass
|
516 |
+
mystic = await CallbackQuery.message.reply_text(
|
517 |
+
_["play_2"].format(channel) if channel else _["play_1"]
|
518 |
+
)
|
519 |
+
try:
|
520 |
+
details, track_id = await YouTube.track(vidid, True)
|
521 |
+
except:
|
522 |
+
return await mystic.edit_text(_["play_3"])
|
523 |
+
if details["duration_min"]:
|
524 |
+
duration_sec = time_to_seconds(details["duration_min"])
|
525 |
+
if duration_sec > config.DURATION_LIMIT:
|
526 |
+
return await mystic.edit_text(
|
527 |
+
_["play_6"].format(config.DURATION_LIMIT_MIN, app.mention)
|
528 |
+
)
|
529 |
+
else:
|
530 |
+
buttons = livestream_markup(
|
531 |
+
_,
|
532 |
+
track_id,
|
533 |
+
CallbackQuery.from_user.id,
|
534 |
+
mode,
|
535 |
+
"c" if cplay == "c" else "g",
|
536 |
+
"f" if fplay else "d",
|
537 |
+
)
|
538 |
+
return await mystic.edit_text(
|
539 |
+
_["play_13"],
|
540 |
+
reply_markup=InlineKeyboardMarkup(buttons),
|
541 |
+
)
|
542 |
+
video = True if mode == "v" else None
|
543 |
+
ffplay = True if fplay == "f" else None
|
544 |
+
try:
|
545 |
+
await stream(
|
546 |
+
_,
|
547 |
+
mystic,
|
548 |
+
CallbackQuery.from_user.id,
|
549 |
+
details,
|
550 |
+
chat_id,
|
551 |
+
user_name,
|
552 |
+
CallbackQuery.message.chat.id,
|
553 |
+
video,
|
554 |
+
streamtype="youtube",
|
555 |
+
forceplay=ffplay,
|
556 |
+
)
|
557 |
+
except Exception as e:
|
558 |
+
print(f"Error: {e}")
|
559 |
+
ex_type = type(e).__name__
|
560 |
+
err = e if ex_type == "AssistantErr" else _["general_2"].format(ex_type)
|
561 |
+
return await mystic.edit_text(err)
|
562 |
+
return await mystic.delete()
|
563 |
+
|
564 |
+
|
565 |
+
@app.on_callback_query(filters.regex("AnonymousAdmin") & ~BANNED_USERS)
|
566 |
+
async def anonymous_check(client, CallbackQuery):
|
567 |
+
try:
|
568 |
+
await CallbackQuery.answer(
|
569 |
+
"» ʀᴇᴠᴇʀᴛ ʙᴀᴄᴋ ᴛᴏ ᴜsᴇʀ ᴀᴄᴄᴏᴜɴᴛ :\n\nᴏᴘᴇɴ ʏᴏᴜʀ ɢʀᴏᴜᴘ sᴇᴛᴛɪɴɢs.\n-> ᴀᴅᴍɪɴɪsᴛʀᴀᴛᴏʀs\n-> ᴄʟɪᴄᴋ ᴏɴ ʏᴏᴜʀ ɴᴀᴍᴇ\n-> ᴜɴᴄʜᴇᴄᴋ ᴀɴᴏɴʏᴍᴏᴜs ᴀᴅᴍɪɴ ᴘᴇʀᴍɪssɪᴏɴs.",
|
570 |
+
show_alert=True,
|
571 |
+
)
|
572 |
+
except:
|
573 |
+
pass
|
574 |
+
|
575 |
+
|
576 |
+
@app.on_callback_query(filters.regex("AviaxPlaylists") & ~BANNED_USERS)
|
577 |
+
@languageCB
|
578 |
+
async def play_playlists_command(client, CallbackQuery, _):
|
579 |
+
callback_data = CallbackQuery.data.strip()
|
580 |
+
callback_request = callback_data.split(None, 1)[1]
|
581 |
+
(
|
582 |
+
videoid,
|
583 |
+
user_id,
|
584 |
+
ptype,
|
585 |
+
mode,
|
586 |
+
cplay,
|
587 |
+
fplay,
|
588 |
+
) = callback_request.split("|")
|
589 |
+
if CallbackQuery.from_user.id != int(user_id):
|
590 |
+
try:
|
591 |
+
return await CallbackQuery.answer(_["playcb_1"], show_alert=True)
|
592 |
+
except:
|
593 |
+
return
|
594 |
+
try:
|
595 |
+
chat_id, channel = await get_channeplayCB(_, cplay, CallbackQuery)
|
596 |
+
except:
|
597 |
+
return
|
598 |
+
user_name = CallbackQuery.from_user.first_name
|
599 |
+
await CallbackQuery.message.delete()
|
600 |
+
try:
|
601 |
+
await CallbackQuery.answer()
|
602 |
+
except:
|
603 |
+
pass
|
604 |
+
mystic = await CallbackQuery.message.reply_text(
|
605 |
+
_["play_2"].format(channel) if channel else _["play_1"]
|
606 |
+
)
|
607 |
+
videoid = lyrical.get(videoid)
|
608 |
+
video = Tr
|