Files
Ultroid-fork/plugins/whichsong.py
1Danish-00 6f44b386aa v0.2 11/10/2021
Co-authored-by: New-dev0 <New-dev0@users.noreply.github.com>
Co-authored-by: Amit Sharma <buddhhu@users.noreply.github.com>
Co-authored-by: TechiError <techierror@users.noreply.github.com>
Co-authored-by: Aditya <me@xditya.me>
Co-authored-by: Sonya Nikiforova <Sonniki@users.noreply.github.com>
Co-authored-by: M̲αραт <Marty2509@users.noreply.github.com>
Co-authored-by: Muhamad Risman Aziz <mrismanaziz@users.noreply.github.com>
Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com>
Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com>
Co-authored-by: sppidy <sppidy@users.noreply.github.com>
2021-10-11 00:27:23 +05:30

42 lines
1.2 KiB
Python

# Ultroid - UserBot
# Copyright (C) 2021 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
• `{i}whichsong`
Reply to a song file, to recognise the song.
"""
from os import remove
from shazamio import Shazam
from . import eor, get_string, mediainfo, ultroid_cmd
shazam = Shazam()
@ultroid_cmd(pattern="whichsong$")
async def song_recog(event):
reply = await event.get_reply_message()
if not (reply and mediainfo(reply.media) == "audio"):
return await eor(event, get_string("whs_1"), time=5)
xx = await eor(event, get_string("com_5"))
path_to_song = "./temp/shaazam_cache/unknown.mp3"
await reply.download_media(path_to_song)
await xx.edit(get_string("whs_2"))
try:
res = await shazam.recognize_song(path_to_song)
except Exception as e:
return await eor(xx, str(e), time=10)
remove(path_to_song)
try:
x = res["track"]
await xx.edit(get_string("whs_4").format(x["title"]))
except KeyError:
return await eor(xx, get_string("whs_3"), time=5)