shazamio / ShazamIO

🎵 Is a free asynchronous library from reverse engineered Shazam API written in Python 3.8+ with asyncio and aiohttp.
MIT License
519 stars 75 forks source link

(Request) - search lyrics #77

Closed Sansekai closed 11 months ago

Sansekai commented 11 months ago

Can add search lyrics?

dotX12 commented 11 months ago

@Sansekai, hello! It's worth considering that not all songs have lyrics, but if they do, this function will find them.

image

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())
dotX12 commented 11 months ago

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 :(