Closed Sansekai closed 11 months ago
@Sansekai, hello! It's worth considering that not all songs have lyrics, but if they do, this function will find them.
import asyncio
from shazamio import Shazam
def find_lyrics(data) -> list[str] | None:
if data.get("track"):
if data["track"].get("sections"):
for element in data["track"]["sections"]:
if element.get("type") == "LYRICS":
return element.get("text")
return None
async def main():
shazam = Shazam()
out = await shazam.recognize_song("data/Joey_Bada_THE_REV3NGE.mp3")
print(find_lyrics(out))
loop = asyncio.get_event_loop_policy().get_event_loop()
loop.run_until_complete(main())
You can always look at the JSON that shazam returns and get the necessary data, for example, the lyrics of a song.
from shazamio import Serialize
was created for simple scenarios; there is not always time to keep it up to date :(
Can add search lyrics?