Spaces:
Runtime error
Runtime error
import os | |
import time | |
import requests | |
from lyricsgenius import Genius | |
from pyrogram import Client | |
from pyrogram.errors import MessageTooLong | |
from pyrogram.types import Message | |
from yt_dlp import YoutubeDL | |
from Hellbot.core import ENV | |
from Hellbot.functions.driver import YoutubeDriver | |
from Hellbot.functions.paste import post_to_telegraph | |
from Hellbot.functions.tools import progress | |
from . import HelpMenu, Symbols, db, hellbot, on_message | |
async def dwlSong(_, message: Message): | |
if len(message.command) < 2: | |
return await hellbot.delete(message, "Provide a song name to download.") | |
query = await hellbot.input(message) | |
hell = await hellbot.edit(message, f"π __π£ππππ ππΊπ½πππ π²πππ__ `{query}`...") | |
ytSearch = YoutubeDriver(query, 1).to_dict()[0] | |
upload_text = f"**β¬οΈ π΄ππ ππΊπ½πππ π²πππ ...** \n\n**{Symbols.anchor} π³πππ πΎ:** `{ytSearch['title'][:50]}`\n**{Symbols.anchor} π’ππΊπππΎπ :** `{ytSearch['channel']}`" | |
try: | |
url = f"https://www.youtube.com{ytSearch['url_suffix']}" | |
with YoutubeDL(YoutubeDriver.song_options()) as ytdl: | |
yt_data = ytdl.extract_info(url, False) | |
yt_file = ytdl.prepare_filename(yt_data) | |
ytdl.process_info(yt_data) | |
await hell.edit(upload_text) | |
resp = requests.get(ytSearch["thumbnail"]) | |
with open(f"{yt_file}.jpg", "wb") as thumbnail: | |
thumbnail.write(resp.content) | |
start_time = time.time() | |
await message.reply_audio( | |
f"{yt_file}.mp3", | |
caption=f"**π§ π³πππ πΎ:** {ytSearch['title']} \n\n**π π΅ππΎππ:** `{ytSearch['views']}` \n**β π£πππΊππππ:** `{ytSearch['duration']}`", | |
duration=int(yt_data["duration"]), | |
performer="[ΡΠ½Ρ Π½ΡββΠ²ΟΡ]", | |
title=ytSearch["title"], | |
thumb=f"{yt_file}.jpg", | |
progress=progress, | |
progress_args=( | |
hell, | |
start_time, | |
upload_text, | |
), | |
) | |
await hell.delete() | |
except Exception as e: | |
return await hellbot.delete(hell, f"**π π²πππ πππ π£ππππ ππΊπ½πΎπ½:** `{e}`") | |
try: | |
os.remove(f"{yt_file}.mp3") | |
os.remove(f"{yt_file}.jpg") | |
except: | |
pass | |
async def dwlSong(_, message: Message): | |
if len(message.command) < 2: | |
return await hellbot.delete(message, "Provide a song name to download.") | |
query = await hellbot.input(message) | |
hell = await hellbot.edit(message, f"π __π£ππππ ππΊπ½πππ π΅ππ½πΎπ π²πππ__ `{query}`...") | |
ytSearch = YoutubeDriver(query, 1).to_dict()[0] | |
upload_text = f"**β¬οΈ π΄ππ ππΊπ½πππ π΅ππ½πΎπ π²πππ ...** \n\n**{Symbols.anchor} π³πππ πΎ:** `{ytSearch['title'][:50]}`\n**{Symbols.anchor} π’ππΊπππΎπ :** `{ytSearch['channel']}`" | |
try: | |
url = f"https://www.youtube.com{ytSearch['url_suffix']}" | |
with YoutubeDL(YoutubeDriver.video_options()) as ytdl: | |
yt_data = ytdl.extract_info(url, True) | |
yt_file = yt_data["id"] | |
await hell.edit(upload_text) | |
resp = requests.get(ytSearch["thumbnail"]) | |
with open(f"{yt_file}.jpg", "wb") as thumbnail: | |
thumbnail.write(resp.content) | |
start_time = time.time() | |
await message.reply_video( | |
f"{yt_file}.mp4", | |
caption=f"**π§ π³πππ πΎ:** {ytSearch['title']} \n\n**π π΅ππΎππ:** `{ytSearch['views']}` \n**β π£πππΊππππ:** `{ytSearch['duration']}`", | |
duration=int(yt_data["duration"]), | |
thumb=f"{yt_file}.jpg", | |
progress=progress, | |
progress_args=( | |
hell, | |
start_time, | |
upload_text, | |
), | |
) | |
await hell.delete() | |
except Exception as e: | |
return await hellbot.delete(hell, f"**π π΅ππ½πΎπ π²πππ πππ π£ππππ ππΊπ½πΎπ½:** `{e}`") | |
try: | |
os.remove(f"{yt_file}.mp4") | |
os.remove(f"{yt_file}.jpg") | |
except: | |
pass | |
async def getlyrics(_, message: Message): | |
if len(message.command) < 2: | |
return await hellbot.delete(message, "Provide a song name to fetch lyrics.") | |
api = await db.get_env(ENV.lyrics_api) | |
if not api: | |
return await hellbot.delete(message, "Lyrics API not found.") | |
query = await hellbot.input(message) | |
if "-" in query: | |
artist, song = query.split("-") | |
else: | |
artist, song = "", query | |
hell = await hellbot.edit(message, f"π __π«ππππΌπ π²πππ__ `{query}`...") | |
genius = Genius( | |
api, | |
verbose=False, | |
remove_section_headers=True, | |
skip_non_songs=True, | |
excluded_terms=["(Remix)", "(Live)"], | |
) | |
song = genius.search_song(song, artist) | |
if not song: | |
return await hellbot.delete(hell, "No results found.") | |
title = song.full_title | |
image = song.song_art_image_url | |
artist = song.artist | |
lyrics = song.lyrics | |
outStr = f"<b>{Symbols.anchor} Title:</b> <code>{title}</code>\n<b>{Symbols.anchor} Artist:</b> <code>{artist}</code>\n\n<code>{lyrics}</code>" | |
try: | |
await hell.edit(outStr, disable_web_page_preview=True) | |
except MessageTooLong: | |
content = f"<img src='{image}'/>\n\n{outStr}" | |
url = post_to_telegraph(title, content) | |
await hell.edit( | |
f"**{Symbols.anchor} Title:** `{title}`\n**{Symbols.anchor} Artist:** `{artist}`\n\n**{Symbols.anchor} Lyrics:** [Click Here]({url})", | |
disable_web_page_preview=True, | |
) | |
HelpMenu("songs").add( | |
"song", | |
"<song name>", | |
"Download the given audio song from Youtube!", | |
"song believer", | |
).add( | |
"video", | |
"<song name>", | |
"Download the given video song from Youtube!", | |
"song believer", | |
).add( | |
"lyrics", | |
"<song name>", | |
"Get the lyrics of the given song! Give artist name after - to get accurate results.", | |
"lyrics believer - imagine dragons", | |
"Need to setup Lyrics Api key from https://genius.com/developers", | |
).info( | |
"Song and Lyrics" | |
).done() | |