dragonxd1 commited on
Commit
209a6a6
·
verified ·
1 Parent(s): 7e3be9b

Update DragMusic/plugins/play/play.py

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