Spaces:
Runtime error
Runtime error
File size: 6,743 Bytes
78b07ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
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
@on_message("song", allow_stan=True)
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
@on_message("video", allow_stan=True)
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
@on_message("lyrics", allow_stan=True)
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()
|