|
@@ -18,39 +18,43 @@ ydl_opts = {
|
|
|
|
|
|
|
|
@app.on_message(cust_filter.command(commands=("music")) & ~filters.edited)
|
|
@app.on_message(cust_filter.command(commands=("music")) & ~filters.edited)
|
|
|
async def music(_, message: Message):
|
|
async def music(_, message: Message):
|
|
|
- await message.reply_chat_action("typing")
|
|
|
|
|
- app.set_parse_mode("html")
|
|
|
|
|
- try:
|
|
|
|
|
- link = (message.text.split(None, 1)[1])
|
|
|
|
|
- except IndexError:
|
|
|
|
|
|
|
+ if len(message.command) != 2:
|
|
|
await message.reply_text(
|
|
await message.reply_text(
|
|
|
- "<code>\"/music\" needs a keyword argument</code>")
|
|
|
|
|
-
|
|
|
|
|
- with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
|
|
|
- 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
|
|
|
|
|
|
|
+ "`/music` needs a link as argument")
|
|
|
|
|
+ return
|
|
|
|
|
+ link = message.text.split(None, 1)[1]
|
|
|
|
|
+ m = await message.reply_text(f"Downloading {link}",
|
|
|
|
|
+ disable_web_page_preview=True)
|
|
|
|
|
+ try:
|
|
|
|
|
+ with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
|
|
|
|
+ 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
|
|
|
|
|
+ except Exception as e:
|
|
|
|
|
+ await m.edit(str(e))
|
|
|
|
|
+ return
|
|
|
# info
|
|
# 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)
|
|
|
|
|
|
|
+ title = info_dict['title']
|
|
|
|
|
+ webpage_url = info_dict['webpage_url']
|
|
|
|
|
+ performer = info_dict['uploader']
|
|
|
|
|
+ duration = int(float(info_dict['duration']))
|
|
|
|
|
+ caption = f"[{title}]({webpage_url})"
|
|
|
|
|
+ await m.delete()
|
|
|
|
|
+ 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):
|
|
def get_file_extension_from_url(url):
|