Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New plugin to fetch lyrics and create .lrc files #385

Open
wants to merge 3 commits into
base: 2.0
Choose a base branch
from

Conversation

twodoorcoupe
Copy link
Contributor

Hello! I wanted to get back into working on the lyrics stuff, so I needed a good way to fetch lyrics and thought to make this plugin.

Besides getting lyrics from lrclib, you can also export/import lyrics to/from an .lrc file.

I saw there are already a couple of unofficial plugins that fetch lyrics with lrclib, but I thought it might be useful to have one in the official list, and I also needed something to easily create lrc files.

These are the available options:

options

For naming the lrc file, one can also use tags plus some special variables like in the Post Tagging Actions plugin.

Copy link
Contributor

@rdswift rdswift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with the availability of lyrics, but this looks to be a useful utility.

plugins/lrclib_lyrics/__init__.py Outdated Show resolved Hide resolved
Copy link
Contributor

@Sophist-UK Sophist-UK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only comment is that I think that to make it clear that it is an alternative and not an overriding option, non-synced lyrics need to be called (in the UI and in code) something other than just "Lyrics" i.e. either "standard lyrics" or "unsynced lyrics".

Otherwise, great job.

@twodoorcoupe
Copy link
Contributor Author

Sorry for the delay. Thank you both for the reviews! 🙏

@rdswift rdswift requested a review from phw November 2, 2024 15:59
Copy link
Member

@phw phw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this. This is great, and I like how this is ready for synced lyrics as well. I really would want to see more lyrics capabilities in Picard itself (specifically handling of separate lrc files). But in the meantime this plugin helps a lot for existing versions. And lrclib.net is great.

@phw phw requested a review from zas November 7, 2024 07:42
"folderpath": lambda file: os.path.dirname(file), # pylint: disable=unnecessary-lambda
"filename": lambda file: os.path.splitext(os.path.basename(file))[0],
"filename_ext": lambda file: os.path.basename(file), # pylint: disable=unnecessary-lambda
"directory": lambda file: os.path.basename(os.path.dirname(file))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor stylistic comment: in Picard code we tend to use single quoted strings for identifiers or keys (see https://github.com/metabrainz/picard/blob/master/CONTRIBUTING.md#strings-quoting-single-or-double-quotes)

So here we would write:

    'directory': lambda file: os.path.basename(os.path.dirname(file))

Same goes for option names above.

Or in code like metadata.get("title") below, where we usually write:

metadata.get('title')

Copy link
Collaborator

@zas zas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just few non-blocking comments, overall the code looks good and the feature is very welcome.
Nicely done.

with open(filename, 'w') as file:
file.write(lyrics)
log.debug(f"Created new lyrics file at {filename}")
except OSError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason of the exception might be useful in the error message, and it should be log.error() not log.debug() below.

pass
else:
file.metadata["lyrics"] = lyrics
except FileNotFoundError:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may as well handle OSError in case the file exists but cannot be read.

Copy link
Contributor

@Sophist-UK Sophist-UK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt it would be that hard to add support for synched lyrics in Picard so it would be nice to have that supported here too.

Could you code to check Picard for Synced Lyrics support and enable / disable functionality accordingly?

@phw
Copy link
Member

phw commented Nov 7, 2024

@Sophist-UK The synced lyrics support was actually implemented by @twodoorcoupe in metabrainz/picard#2373 . This is currently not yet in any release version. At the time this gets released the plugin will be needed to be updated anyway. So that part can be updated once it is actually available to users.

And maybe we might even have native support for lrc files inside Picard by then

@twodoorcoupe
Copy link
Contributor Author

Thank you guys.

I really would want to see more lyrics capabilities in Picard itself (specifically handling of separate lrc files).

Yeah that's what I would like to focus on next, whenever I find the time.

The synced lyrics support was actually implemented

Unfortunately it's only for id3 for now. For other formats I did not know how to map the tag, though I think once that is decided it would be easy to implement.

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.

5 participants