Skip to content

[lrclib_lyrics] different file naming scheme for unsynced files + caching improvements - #434

Open
oakrotka wants to merge 5 commits into
metabrainz:2.0from
oakrotka:2.0
Open

oakrotka wants to merge 5 commits into
metabrainz:2.0from
oakrotka:2.0

Conversation

@oakrotka

Copy link
Copy Markdown

This PR contains two functionalities regarding the lrclib_lyrics plugin:

  • As per [lrclib_lyrics] Option to save unsynced files as .txt rather than .lrc #433, unsynced lyrics are now by default saved with a .txt extension instead of .lrc. This follows a common convention, adopted for example by LRCGET, which is the program for downloading lyrics from lrclib listed on the lrclib website itself. Also, custom filename patterns for lyrics are now different for synced and unsynced files.
  • Caching of lyrics is now done for a more complex key, instead of just the track's title. Previously, if you loaded two tracks of the same title (e.g. "Intro"), the one that would get the (possibly incorrect) lyrics would be the first one saved. With this PR, this situation is made very unlikely.

@oakrotka

Copy link
Copy Markdown
Author

Just realized that the plugin has the problem that when a track's name is changed during tagging (and now also the artist, album, and track number), the synchronized lyrics are lost and only unsynchronized ones are written ://. I am not familiar enough with picard to know how to fix this, as this would require getting a key for a track that will stay the exact same after tagging.

@Sophist-UK

Copy link
Copy Markdown
Contributor
  1. I think you should probably use the Track MBID as the key for the cache and not any other metadata. That will then stay the same if the track gets renamed. (This assumes that you only retrieve lyrics for tracks which have been tagged using MB data.

  2. Because your cache key is just track details and doesn't include the synced/unsynced flag, the cache can currently store only one of synced or unsynced lyrics and not both. If you store both you can only retrieve the last one stored. I would recommend that you include this flag in the key, and rework the cache getter so you can specify Synced / Unsynced / Any to retrieve.

  3. You can access both old and new metadata so when the file is saved, you can scan lyric files for a filename that contains the old track title and scan the music files for files that contain the new track title, and then rename the files accordingly. Its messy but it should work.

@oakrotka

Copy link
Copy Markdown
Author

I did not know that the metadata object contains information about the file path. I have rewritten the logic to use the music file's original path as the key and it seems to work wonders.

As per point 2, this is not needed as the music cache is used only to save the lyrics to a file after the user has chosen to save the file, and synchronized lyrics are always preferred over unsynchronized as per the label for the EXPORT_LRC option. There is also no way that the configuration will change between fetching the lyrics and saving them, as the ADD_(UN)SYNCED_LYRICS options are only for music file metadata.

@Sophist-UK

Sophist-UK commented Aug 16, 2026 •

Copy link
Copy Markdown
Contributor

I did not know that the metadata object contains information about the file path. I have rewritten the logic to use the music file's original path as the key and it seems to work wonders.

Great.

As per point 2, this is not needed as the music cache is used only to save the lyrics to a file after the user has chosen to save the file, and synchronized lyrics are always preferred over unsynchronized as per the label for the EXPORT_LRC option. There is also no way that the configuration will change between fetching the lyrics and saving them, as the ADD_(UN)SYNCED_LYRICS options are only for music file metadata.

If you cache the sync lyrics first and unsynced lyrics second, then you won't be caching the synced lyrics. If synced lyrics are preferred, then you need to be certain that unsynced lyrics (if they exist) are cached first so that the cache is overwritten by the synced lyrics (or have logic to check and prevent the overwriting).

@Sophist-UK

Copy link
Copy Markdown
Contributor

P.S. Given that lyrics can be a 10s of KB, you might want to hook into the remove release functionality and purge the cache of all its entries.

@oakrotka

Copy link
Copy Markdown
Author

I do not see a real need for any of this tbh, as this plugin is a small script and the only place where the cache is written to already ensures that synchronized lyrics will be the ones written last, and also this whole caching logic was already present without the release functionality prior to my PR, but here you go, I implemented both of those things.

@oakrotka oakrotka changed the title [lrclib_lyrics] different file naming scheme for unsynced files + improvements [lrclib_lyrics] different file naming scheme for unsynced files + caching improvements Aug 16, 2026
@Sophist-UK

Copy link
Copy Markdown
Contributor

If it were me I would cache the results of the web calls you make to get the lyrics, the purpose being to avoid making the same calls again if you reload or refresh the album because that is the expensive thing in elapsed time. That way if you have two versions of the same song, you would also reuse the cached data.

@oakrotka

Copy link
Copy Markdown
Author

I think that this is a big change that is out of scope for this PR and I would prefer to leave it as it is.

@Sophist-UK

Sophist-UK commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds the caching functionality - so changing the caching approach is definitely in scope for this PR.

However, my comment was only a suggestion - you are the author so the approach is your choice, and because this is a plugin and not core Picard, reviewers are likely to be more flexible about these things.

@oakrotka

oakrotka commented Sep 6, 2026

Copy link
Copy Markdown
Author

This PR does not add the caching functionality; it has been there well before my PR and has only been a workaround for the plugin to be able to write synchronized lyrics to a file after fetching them before. The only thing I change is the cache key for which these lyrics are stored, while also adding some missing events in which the cache is released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants