music.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from __future__ import unicode_literals
  2. import youtube_dl
  3. from wbb.utils import cust_filter
  4. from pyrogram import filters
  5. from wbb import app, Command
  6. import os
  7. import glob
  8. __MODULE__ = "Music"
  9. __HELP__ = "/music [link] To Download Music From Various Websites"
  10. ydl_opts = {
  11. 'format': 'bestaudio/best',
  12. 'postprocessors': [{
  13. 'key': 'FFmpegExtractAudio',
  14. 'preferredcodec': 'mp3',
  15. 'preferredquality': '320'
  16. }],
  17. 'postprocessor_args': [
  18. '-ar', '16000'
  19. ],
  20. 'prefer_ffmpeg': True,
  21. 'keepvideo': False
  22. }
  23. @app.on_message(cust_filter.command(commands=("music")))
  24. async def commit(client, message):
  25. app.set_parse_mode("markdown")
  26. down = await message.reply_text("```Downloading Media!```")
  27. link = (message.text.split(None, 1)[1])
  28. with youtube_dl.YoutubeDL(ydl_opts) as ydl:
  29. ydl.download([link])
  30. for filename in glob.glob("*.mp3"):
  31. filename_final = filename.split("-")[0]+" - "+filename.split("-")[-2]+".mp3"
  32. os.rename(filename, filename_final)
  33. await down.edit(f"```Uploading Media!```")
  34. m = await message.reply_audio(filename_final)
  35. await down.delete()
  36. await m.edit_caption(f"[{filename_final}]({link})")
  37. os.remove(filename_final)