2022-01-31 12:41:47 +00:00
|
|
|
# Copyright (C) 2021 By Veez Music-Project
|
|
|
|
|
2022-02-21 08:56:05 +00:00
|
|
|
import wget
|
|
|
|
import yt_dlp
|
2022-02-13 06:27:09 +00:00
|
|
|
import traceback
|
2022-02-21 08:56:05 +00:00
|
|
|
import requests
|
2022-01-31 12:41:47 +00:00
|
|
|
import lyricsgenius
|
|
|
|
|
|
|
|
from pyrogram import Client, filters
|
|
|
|
from pyrogram.types import Message
|
|
|
|
from youtube_search import YoutubeSearch
|
|
|
|
from yt_dlp import YoutubeDL
|
|
|
|
|
|
|
|
from config import BOT_USERNAME as bn
|
2022-02-14 05:38:16 +00:00
|
|
|
from driver.decorators import check_blacklist
|
2022-02-21 08:56:05 +00:00
|
|
|
from driver.filters import command
|
2022-02-13 06:43:13 +00:00
|
|
|
from driver.utils import remove_if_exists
|
2022-01-31 12:41:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
@Client.on_message(command(["song", f"song@{bn}"]) & ~filters.edited)
|
2022-02-14 05:38:16 +00:00
|
|
|
@check_blacklist()
|
2022-02-06 14:30:13 +00:00
|
|
|
async def song_downloader(_, message):
|
2022-02-08 04:05:45 +00:00
|
|
|
await message.delete()
|
2022-01-31 12:41:47 +00:00
|
|
|
query = " ".join(message.command[1:])
|
2022-02-06 14:49:48 +00:00
|
|
|
m = await message.reply("🔎 finding song...")
|
2022-02-06 13:15:26 +00:00
|
|
|
ydl_ops = {
|
|
|
|
'format': 'bestaudio[ext=m4a]',
|
2022-02-19 02:29:48 +00:00
|
|
|
'geo-bypass': True,
|
|
|
|
'noprogress': True,
|
|
|
|
'user-agent': 'Mozilla/5.0 (Linux; Android 7.0; k960n_mt6580_32_n) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36',
|
|
|
|
'extractor-args': 'youtube:player_client=all',
|
|
|
|
'nocheckcertificate': True,
|
2022-02-06 13:15:26 +00:00
|
|
|
'outtmpl': '%(title)s.%(ext)s',
|
|
|
|
'quite': True,
|
|
|
|
}
|
2022-01-31 12:41:47 +00:00
|
|
|
try:
|
|
|
|
results = YoutubeSearch(query, max_results=1).to_dict()
|
|
|
|
link = f"https://youtube.com{results[0]['url_suffix']}"
|
|
|
|
title = results[0]["title"][:40]
|
|
|
|
thumbnail = results[0]["thumbnails"][0]
|
|
|
|
thumb_name = f"{title}.jpg"
|
|
|
|
thumb = requests.get(thumbnail, allow_redirects=True)
|
|
|
|
open(thumb_name, "wb").write(thumb.content)
|
|
|
|
duration = results[0]["duration"]
|
|
|
|
|
|
|
|
except Exception as e:
|
2022-02-06 14:49:48 +00:00
|
|
|
await m.edit("❌ song not found.\n\n» Give me a valid song name !")
|
2022-01-31 12:41:47 +00:00
|
|
|
print(str(e))
|
|
|
|
return
|
2022-02-06 14:49:48 +00:00
|
|
|
await m.edit("📥 downloading song...")
|
2022-01-31 12:41:47 +00:00
|
|
|
try:
|
|
|
|
with yt_dlp.YoutubeDL(ydl_ops) as ydl:
|
|
|
|
info_dict = ydl.extract_info(link, download=False)
|
|
|
|
audio_file = ydl.prepare_filename(info_dict)
|
|
|
|
ydl.process_info(info_dict)
|
|
|
|
rep = f"• uploader @{bn}"
|
2022-02-01 09:58:05 +00:00
|
|
|
host = str(info_dict["uploader"])
|
2022-01-31 12:41:47 +00:00
|
|
|
secmul, dur, dur_arr = 1, 0, duration.split(":")
|
|
|
|
for i in range(len(dur_arr) - 1, -1, -1):
|
|
|
|
dur += int(float(dur_arr[i])) * secmul
|
|
|
|
secmul *= 60
|
2022-02-06 14:49:48 +00:00
|
|
|
await m.edit("📤 uploading song...")
|
|
|
|
await message.reply_audio(
|
2022-01-31 12:41:47 +00:00
|
|
|
audio_file,
|
|
|
|
caption=rep,
|
2022-02-01 09:58:05 +00:00
|
|
|
performer=host,
|
2022-01-31 12:41:47 +00:00
|
|
|
thumb=thumb_name,
|
|
|
|
parse_mode="md",
|
|
|
|
title=title,
|
|
|
|
duration=dur,
|
|
|
|
)
|
2022-02-06 14:49:48 +00:00
|
|
|
await m.delete()
|
|
|
|
|
2022-01-31 12:41:47 +00:00
|
|
|
except Exception as e:
|
2022-02-06 14:49:48 +00:00
|
|
|
await m.edit("❌ error, wait for bot owner to fix")
|
2022-01-31 12:41:47 +00:00
|
|
|
print(e)
|
|
|
|
try:
|
2022-02-13 06:43:13 +00:00
|
|
|
remove_if_exists(audio_file)
|
|
|
|
remove_if_exists(thumb_name)
|
2022-01-31 12:41:47 +00:00
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
|
|
@Client.on_message(
|
|
|
|
command(["vsong", f"vsong@{bn}", "video", f"video@{bn}"]) & ~filters.edited
|
|
|
|
)
|
2022-02-14 05:38:16 +00:00
|
|
|
@check_blacklist()
|
2022-02-06 12:57:21 +00:00
|
|
|
async def video_downloader(_, message):
|
2022-02-08 04:05:45 +00:00
|
|
|
await message.delete()
|
2022-01-31 12:41:47 +00:00
|
|
|
ydl_opts = {
|
|
|
|
"format": "best",
|
|
|
|
"keepvideo": True,
|
2022-02-19 02:29:48 +00:00
|
|
|
"prefer-ffmpeg": False,
|
|
|
|
"geo-bypass": True,
|
|
|
|
"noprogress": True,
|
|
|
|
"user-agent": "Mozilla/5.0 (Linux; Android 7.0; k960n_mt6580_32_n) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.101 Safari/537.36",
|
|
|
|
"extractor-args": "youtube:player_client=all",
|
|
|
|
"nocheckcertificate": True,
|
2022-01-31 12:41:47 +00:00
|
|
|
"outtmpl": "%(title)s.%(ext)s",
|
|
|
|
"quite": True,
|
|
|
|
}
|
|
|
|
query = " ".join(message.command[1:])
|
|
|
|
try:
|
|
|
|
results = YoutubeSearch(query, max_results=1).to_dict()
|
|
|
|
link = f"https://youtube.com{results[0]['url_suffix']}"
|
|
|
|
title = results[0]["title"][:40]
|
|
|
|
thumbnail = results[0]["thumbnails"][0]
|
|
|
|
thumb_name = f"{title}.jpg"
|
|
|
|
thumb = requests.get(thumbnail, allow_redirects=True)
|
|
|
|
open(thumb_name, "wb").write(thumb.content)
|
|
|
|
results[0]["duration"]
|
|
|
|
results[0]["url_suffix"]
|
|
|
|
results[0]["views"]
|
|
|
|
message.from_user.mention
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
try:
|
2022-02-01 09:31:45 +00:00
|
|
|
msg = await message.reply("📥 downloading video...")
|
2022-01-31 12:41:47 +00:00
|
|
|
with YoutubeDL(ydl_opts) as ytdl:
|
|
|
|
ytdl_data = ytdl.extract_info(link, download=True)
|
|
|
|
file_name = ytdl.prepare_filename(ytdl_data)
|
|
|
|
except Exception as e:
|
2022-02-13 06:27:09 +00:00
|
|
|
traceback.print_exc()
|
2022-02-01 09:31:45 +00:00
|
|
|
return await msg.edit(f"🚫 error: `{e}`")
|
2022-01-31 12:41:47 +00:00
|
|
|
preview = wget.download(thumbnail)
|
2022-02-01 09:31:45 +00:00
|
|
|
await msg.edit("📤 uploading video...")
|
2022-01-31 12:41:47 +00:00
|
|
|
await message.reply_video(
|
|
|
|
file_name,
|
|
|
|
duration=int(ytdl_data["duration"]),
|
|
|
|
thumb=preview,
|
|
|
|
caption=ytdl_data["title"],
|
|
|
|
)
|
|
|
|
try:
|
2022-02-13 06:43:13 +00:00
|
|
|
remove_if_exists(file_name)
|
2022-01-31 12:41:47 +00:00
|
|
|
await msg.delete()
|
|
|
|
except Exception as e:
|
|
|
|
print(e)
|
|
|
|
|
|
|
|
|
|
|
|
@Client.on_message(command(["lyric", f"lyric@{bn}", "lyrics"]))
|
2022-02-14 05:38:16 +00:00
|
|
|
@check_blacklist()
|
2022-01-31 12:41:47 +00:00
|
|
|
async def get_lyric_genius(_, message: Message):
|
|
|
|
if len(message.command) < 2:
|
|
|
|
return await message.reply_text("**usage:**\n\n/lyrics (song name)")
|
|
|
|
m = await message.reply_text("🔍 Searching lyrics...")
|
|
|
|
query = message.text.split(None, 1)[1]
|
|
|
|
x = "OXaVabSRKQLqwpiYOn-E4Y7k3wj-TNdL5RfDPXlnXhCErbcqVvdCF-WnMR5TBctI"
|
|
|
|
y = lyricsgenius.Genius(x)
|
|
|
|
y.verbose = False
|
|
|
|
S = y.search_song(query, get_full_info=False)
|
|
|
|
if S is None:
|
|
|
|
return await m.edit("❌ `404` lyrics not found")
|
|
|
|
xxx = f"""
|
|
|
|
**Song Name:** __{query}__
|
|
|
|
**Artist Name:** {S.artist}
|
|
|
|
**__Lyrics:__**
|
|
|
|
{S.lyrics}"""
|
|
|
|
if len(xxx) > 4096:
|
|
|
|
await m.delete()
|
|
|
|
filename = "lyrics.txt"
|
|
|
|
with open(filename, "w+", encoding="utf8") as out_file:
|
|
|
|
out_file.write(str(xxx.strip()))
|
|
|
|
await message.reply_document(
|
|
|
|
document=filename,
|
2022-02-06 14:49:48 +00:00
|
|
|
caption=f"**OUTPUT:**\n\n`attached lyrics text`",
|
2022-01-31 12:41:47 +00:00
|
|
|
quote=False,
|
|
|
|
)
|
2022-02-13 06:43:13 +00:00
|
|
|
remove_if_exists(filename)
|
2022-01-31 12:41:47 +00:00
|
|
|
else:
|
|
|
|
await m.edit(xxx)
|