raitonoberu / sptlrx

Synchronized lyrics in your terminal
MIT License
354 stars 14 forks source link

Local lyrics source #29

Closed emiham closed 6 months ago

emiham commented 9 months ago

As mentioned in https://github.com/raitonoberu/sptlrx/pull/22#issuecomment-1380747847, downloading lyrics is a bit out of scope for this application, but since it was mentioned there are other ways to do this, would it be reasonable to allow for this application to show downloaded lyrics, forgoing an API? I think it would provide a lot of peace of mind knowing that the lyrics will always be there for you. From the name I'm guessing this project started out only for Spotify, but for people who use MPD or other local players I think this is a not too uncommon concern.

raitonoberu commented 8 months ago

This can certainly be implemented by applying some kind of fuzzy search in a directory with .lrc files. I'll take a closer look at this and will most likely add it in the next update.

emiham commented 8 months ago

After looking a bit more into this myself: Generally .lrc files seem to be directly coupled with audio files, either embedded in a tag or in the same folder with identical filenames (apart from the extension), or possibly in a separate lyrics folder with the same filenames. Not sure how you feel about reading from tags, but the other two at least probably make sense for this project. Personally I like tags the best, but it seems the most far off from the Spotify use case.

raitonoberu commented 7 months ago

Well, I implemented it... kind of. You can check the local branch.

The current implementation goes through the specified folder, finds the .lrc files and creates an index of these files. Each file is presented as a list of words in its name. Then, for each query, for each file in the index, it calculates a "score" - how many words in the query are equal to the words in the file name. The file with the maximum score is used.

The complexity is O(N*n*m), where N - number of indexed files, n - length of indexed names (average), m - length of the query. However, this is fast enough: indexing of 1000 files takes ~2ms and querying takes ~200µs.

It works fine on all the tracks I've tested it on. But testing is required to find all the edge cases. And it would be great to find a more effective algorithm.

Fxzzi commented 1 month ago

Liking the .lrc support, however why not just parse from the lyrics tag in the file? Can use a script like https://github.com/TheRedSpy15/lrcput to embed all your .lrc files, and then there's no guessing!