forked from TeamUltroid/UltroidAddons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
whichsong.py
41 lines (34 loc) · 1.2 KB
/
whichsong.py
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
# Ultroid - UserBot
# Copyright (C) 2021-2022 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 event.eor(get_string("whs_1"), time=5)
xx = await event.eor(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)