moehmeni / syncedlyrics

Get an LRC format (synchronized) lyrics for your music
MIT License
188 stars 18 forks source link

Get provider #23

Closed raffaem closed 4 months ago

raffaem commented 5 months ago

I would like to get the provider for the lyrics, but I don't know how without breaking the API.

Maybe have another function, and the existing function calling the new function and returning just the lyrics out of it?

moehmeni commented 5 months ago

You mean the the name of the provider when you get the lyrics? If so, you can capture the provider name from the logs.

import io
import logging
import syncedlyrics

syncedlyrics.logger.setLevel(logging.INFO)
stream = io.StringIO()
syncedlyrics.logger.addHandler(logging.StreamHandler(stream))

syncedlyrics.search("...")

provider = stream.getvalue().split("on ")[1].strip()
print(provider)
stream.close()
raffaem commented 4 months ago

I think this is slower.

What about a new class Lyrics that holds both lyrics and provider, a function lookup that return Lyrics, and the search function just call lookup and return just the lyrics?

moehmeni commented 4 months ago

I know it's a bit messy but I don't want to break the simple API since the main goal is to get the lyrics. It's not slow either if you benchmark it.

t1 = time.time()
provider = stream.getvalue().split("on ")[1].strip()
t2 = time.time()

print(round(t2 - t1, 5))
print(provider)
0.0
Musixmatch