fixes & formatter

This commit is contained in:
levina 2022-02-06 21:49:48 +07:00 committed by GitHub
parent 910684a97e
commit cc05484cbd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,24 +23,14 @@ from driver.filters import command, other_filters
from driver.database.dbpunish import is_gbanned_user from driver.database.dbpunish import is_gbanned_user
is_downloading = False
@Client.on_message(command(["song", f"song@{bn}"]) & ~filters.edited) @Client.on_message(command(["song", f"song@{bn}"]) & ~filters.edited)
async def song_downloader(_, message): async def song_downloader(_, message):
global is_downloading
user_id = message.from_user.id user_id = message.from_user.id
if await is_gbanned_user(user_id): if await is_gbanned_user(user_id):
message.reply("❗️ **You've blocked from using this bot!**") await message.reply("❗️ **You've blocked from using this bot!**")
return return
query = " ".join(message.command[1:]) query = " ".join(message.command[1:])
if is_downloading: m = await message.reply("🔎 finding song...")
message.reply(
"» Other download is in progress, please try again after some time !"
)
return
is_downloading = True
m = message.reply("🔎 finding song...")
ydl_ops = { ydl_ops = {
'format': 'bestaudio[ext=m4a]', 'format': 'bestaudio[ext=m4a]',
'keepvideo': True, 'keepvideo': True,
@ -60,10 +50,10 @@ async def song_downloader(_, message):
duration = results[0]["duration"] duration = results[0]["duration"]
except Exception as e: except Exception as e:
m.edit("❌ song not found.\n\n» Give me a valid song name !") await m.edit("❌ song not found.\n\n» Give me a valid song name !")
print(str(e)) print(str(e))
return return
m.edit("📥 downloading song...") await m.edit("📥 downloading song...")
try: try:
with yt_dlp.YoutubeDL(ydl_ops) as ydl: with yt_dlp.YoutubeDL(ydl_ops) as ydl:
info_dict = ydl.extract_info(link, download=False) info_dict = ydl.extract_info(link, download=False)
@ -75,8 +65,8 @@ async def song_downloader(_, message):
for i in range(len(dur_arr) - 1, -1, -1): for i in range(len(dur_arr) - 1, -1, -1):
dur += int(float(dur_arr[i])) * secmul dur += int(float(dur_arr[i])) * secmul
secmul *= 60 secmul *= 60
m.edit("📤 uploading song...") await m.edit("📤 uploading song...")
message.reply_audio( await message.reply_audio(
audio_file, audio_file,
caption=rep, caption=rep,
performer=host, performer=host,
@ -85,12 +75,11 @@ async def song_downloader(_, message):
title=title, title=title,
duration=dur, duration=dur,
) )
m.delete() await m.delete()
is_downloading = False
except Exception as e:
m.edit("❌ error, wait for bot owner to fix")
print(e)
except Exception as e:
await m.edit("❌ error, wait for bot owner to fix")
print(e)
try: try:
os.remove(audio_file) os.remove(audio_file)
os.remove(thumb_name) os.remove(thumb_name)
@ -102,7 +91,6 @@ async def song_downloader(_, message):
command(["vsong", f"vsong@{bn}", "video", f"video@{bn}"]) & ~filters.edited command(["vsong", f"vsong@{bn}", "video", f"video@{bn}"]) & ~filters.edited
) )
async def video_downloader(_, message): async def video_downloader(_, message):
global is_downloading
user_id = message.from_user.id user_id = message.from_user.id
if await is_gbanned_user(user_id): if await is_gbanned_user(user_id):
await message.reply_text("❗️ **You've blocked from using this bot!**") await message.reply_text("❗️ **You've blocked from using this bot!**")
@ -116,11 +104,6 @@ async def video_downloader(_, message):
"quite": True, "quite": True,
} }
query = " ".join(message.command[1:]) query = " ".join(message.command[1:])
if is_downloading:
return await message.reply(
"» Other download is in progress, please try again after some time !"
)
is_downloading = True
try: try:
results = YoutubeSearch(query, max_results=1).to_dict() results = YoutubeSearch(query, max_results=1).to_dict()
link = f"https://youtube.com{results[0]['url_suffix']}" link = f"https://youtube.com{results[0]['url_suffix']}"
@ -150,7 +133,6 @@ async def video_downloader(_, message):
thumb=preview, thumb=preview,
caption=ytdl_data["title"], caption=ytdl_data["title"],
) )
is_downloading = False
try: try:
os.remove(file_name) os.remove(file_name)
await msg.delete() await msg.delete()
@ -186,7 +168,7 @@ async def get_lyric_genius(_, message: Message):
out_file.write(str(xxx.strip())) out_file.write(str(xxx.strip()))
await message.reply_document( await message.reply_document(
document=filename, document=filename,
caption=f"**OUTPUT:**\n\n`Lyrics Text`", caption=f"**OUTPUT:**\n\n`attached lyrics text`",
quote=False, quote=False,
) )
os.remove(filename) os.remove(filename)