|
@@ -1,42 +1,52 @@
|
|
|
from __future__ import unicode_literals
|
|
from __future__ import unicode_literals
|
|
|
|
|
+from urllib.parse import urlparse
|
|
|
import youtube_dl
|
|
import youtube_dl
|
|
|
from wbb.utils import cust_filter
|
|
from wbb.utils import cust_filter
|
|
|
-from pyrogram import filters
|
|
|
|
|
-from wbb import app, Command
|
|
|
|
|
|
|
+from wbb import app
|
|
|
import os
|
|
import os
|
|
|
-import glob
|
|
|
|
|
|
|
|
|
|
__MODULE__ = "Music"
|
|
__MODULE__ = "Music"
|
|
|
__HELP__ = "/music [link] To Download Music From Various Websites"
|
|
__HELP__ = "/music [link] To Download Music From Various Websites"
|
|
|
|
|
|
|
|
-
|
|
|
|
|
ydl_opts = {
|
|
ydl_opts = {
|
|
|
- 'format': 'bestaudio/best',
|
|
|
|
|
- 'postprocessors': [{
|
|
|
|
|
- 'key': 'FFmpegExtractAudio',
|
|
|
|
|
- 'preferredcodec': 'mp3',
|
|
|
|
|
- 'preferredquality': '320'
|
|
|
|
|
- }],
|
|
|
|
|
- 'postprocessor_args': [
|
|
|
|
|
- '-ar', '16000'
|
|
|
|
|
- ],
|
|
|
|
|
- 'prefer_ffmpeg': True,
|
|
|
|
|
- 'keepvideo': False
|
|
|
|
|
|
|
+ 'format': 'bestaudio',
|
|
|
|
|
+ 'writethumbnail': True
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
@app.on_message(cust_filter.command(commands=("music")))
|
|
@app.on_message(cust_filter.command(commands=("music")))
|
|
|
async def commit(client, message):
|
|
async def commit(client, message):
|
|
|
- app.set_parse_mode("markdown")
|
|
|
|
|
- down = await message.reply_text("```Downloading Media!```")
|
|
|
|
|
|
|
+ await message.reply_chat_action("typing")
|
|
|
|
|
+ app.set_parse_mode("html")
|
|
|
link = (message.text.split(None, 1)[1])
|
|
link = (message.text.split(None, 1)[1])
|
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
|
- ydl.download([link])
|
|
|
|
|
- for filename in glob.glob("*.mp3"):
|
|
|
|
|
- filename_final = filename.split("-")[0]+" - "+filename.split("-")[-2]+".mp3"
|
|
|
|
|
- os.rename(filename, filename_final)
|
|
|
|
|
- await down.edit(f"```Uploading Media!```")
|
|
|
|
|
- m = await message.reply_audio(filename_final)
|
|
|
|
|
- await down.delete()
|
|
|
|
|
- await m.edit_caption(f"[{filename_final}]({link})")
|
|
|
|
|
- os.remove(filename_final)
|
|
|
|
|
|
|
+ info_dict = ydl.extract_info(link, download=False)
|
|
|
|
|
+ audio_file = ydl.prepare_filename(info_dict)
|
|
|
|
|
+ ydl.process_info(info_dict)
|
|
|
|
|
+ # .webm -> .weba
|
|
|
|
|
+ basename = audio_file.rsplit(".", 1)[-2]
|
|
|
|
|
+ thumbnail_url = info_dict['thumbnail']
|
|
|
|
|
+ thumbnail_file = basename + "." + \
|
|
|
|
|
+ get_file_extension_from_url(thumbnail_url)
|
|
|
|
|
+ if info_dict['ext'] == 'webm':
|
|
|
|
|
+ audio_file_weba = basename + ".weba"
|
|
|
|
|
+ os.rename(audio_file, audio_file_weba)
|
|
|
|
|
+ audio_file = audio_file_weba
|
|
|
|
|
+ # info
|
|
|
|
|
+ title = info_dict['title']
|
|
|
|
|
+ webpage_url = info_dict['webpage_url']
|
|
|
|
|
+ performer = info_dict['uploader']
|
|
|
|
|
+ duration = int(float(info_dict['duration']))
|
|
|
|
|
+ caption = f"<b><a href=\"{webpage_url}\">{title}</a></b>"
|
|
|
|
|
+ await message.reply_chat_action("upload_document")
|
|
|
|
|
+ await message.reply_audio(audio_file, caption=caption,
|
|
|
|
|
+ duration=duration, performer=performer,
|
|
|
|
|
+ title=title, thumb=thumbnail_file)
|
|
|
|
|
+ os.remove(audio_file)
|
|
|
|
|
+ os.remove(thumbnail_file)
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
+def get_file_extension_from_url(url):
|
|
|
|
|
+ url_path = urlparse(url).path
|
|
|
|
|
+ basename = os.path.basename(url_path)
|
|
|
|
|
+ return basename.split(".")[-1]
|