dragxd commited on
Commit
f92741d
·
1 Parent(s): 410048c

Add /webplay command to play songs in the mini web app only

Browse files
Files changed (1) hide show
  1. DragMusic/plugins/play/play.py +39 -1
DragMusic/plugins/play/play.py CHANGED
@@ -2,7 +2,7 @@ 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
@@ -442,6 +442,44 @@ async def play_commnd(
442
  return await play_logs(message, streamtype=f"URL Searched Inline")
443
 
444
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
445
  @app.on_callback_query(filters.regex("MusicStream") & ~BANNED_USERS)
446
  @languageCB
447
  async def play_music(client, CallbackQuery, _):
 
2
  import string
3
 
4
  from pyrogram import filters
5
+ from pyrogram.types import InlineKeyboardMarkup, InputMediaPhoto, Message, InlineKeyboardButton
6
  from pytgcalls.exceptions import NoActiveGroupCall
7
 
8
  import config
 
442
  return await play_logs(message, streamtype=f"URL Searched Inline")
443
 
444
 
445
+ @app.on_message(filters.command("webplay") & ~BANNED_USERS)
446
+ async def webplay_command(client, message: Message):
447
+ query = None
448
+ if len(message.command) > 1:
449
+ query = " ".join(message.command[1:])
450
+ else:
451
+ await message.reply_text("Please provide a song name or YouTube link to play in the web app.")
452
+ return
453
+ mystic = await message.reply_text("Searching for your song on YouTube...")
454
+ # Search YouTube and get track info
455
+ try:
456
+ details, track_id = await YouTube.track(query)
457
+ except Exception as e:
458
+ await mystic.edit_text(f"Failed to find song: {e}")
459
+ return
460
+ # Download audio
461
+ try:
462
+ file_path, _ = await YouTube.download(details["link"], mystic)
463
+ except Exception as e:
464
+ await mystic.edit_text(f"Failed to download song: {e}")
465
+ return
466
+ # Store in nowplaying
467
+ song_info = {
468
+ "title": details["title"],
469
+ "link": details["link"],
470
+ "path": file_path,
471
+ "dur": details["duration_min"],
472
+ "thumb": details.get("thumb"),
473
+ }
474
+ nowplaying.set_current_song(song_info)
475
+ await mystic.edit_text(
476
+ "Song is ready in the mini web app!",
477
+ reply_markup=InlineKeyboardMarkup(
478
+ [[InlineKeyboardButton("Open Player", url="https://huggingface.co/spaces/dragonxd1/DragMusicV2")]]
479
+ )
480
+ )
481
+
482
+
483
  @app.on_callback_query(filters.regex("MusicStream") & ~BANNED_USERS)
484
  @languageCB
485
  async def play_music(client, CallbackQuery, _):