Skip to content

PICARD-1044: Allow the usage of scripting for loading local cover art#3042

Draft
zas wants to merge 1 commit intometabrainz:masterfrom
zas:PICARD-1044
Draft

PICARD-1044: Allow the usage of scripting for loading local cover art#3042
zas wants to merge 1 commit intometabrainz:masterfrom
zas:PICARD-1044

Conversation

@zas
Copy link
Copy Markdown
Collaborator

@zas zas commented Feb 15, 2026

Summary

  • This is a…
    • Bug fix
    • Feature addition
    • Refactoring
    • Minor / simple change (like a typo)
    • Other
  • Describe this change in 1-2 sentences:

Problem

The dialog for saving cover art supports the use of scripting, but the dialog for loading local cover art does not (it only supports regex). It would be very helpful if you could use the scripting there as well, so you could search for a more specific filename, such as "Cover\Album Artist - Album [Date].ext".

Solution

  • add a checkbox to select the mode (regex or script)
  • add a script editor widget, along error/example
  • provide evalutation time methods accordingly

AI Usage

In accordance with the AI use policy portion of the MetaBrainz Contribution Guidelines, the level of AI/LLM use in the development of this Pull Request is:

  • No AI/LLM use
  • Minimal use (e.g. autocompletion)
  • Moderate use (e.g. suggestions regarding code fragments)
  • Significant use (e.g. code structure, tests development, etc.)
  • Primarily AI developed
  • Other (please specify below)

Action

Additional actions required:

  • Update Picard documentation (please include a reference to this PR)
  • Other (please specify below)

- add a checkbox to select the mode (regex or script)
- add a script editor widget, along error/example
- provide evalutation time methods accordingly
@zas zas requested review from phw and rdswift February 15, 2026 14:38
Copy link
Copy Markdown
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.

Generally code looks fine and this seems to work.
I just wonder how useful this is, as it only works with exact matches. I initially thought we might be able to allow scripting but still have regex matching.

But this will become difficult, as it would be extremely tricky to have the script return a valid regex. We could escape all variables beforehand, but this then makes the variables difficult to use.

But could we have the resulting filename allow glob matching? So users could have * or ? returned as part of the filename for partial matches. It could be an option.

Also we could allow matching the file name case insensitive.

@zas
Copy link
Copy Markdown
Collaborator Author

zas commented Feb 15, 2026

Not sure what is the exact use case for this, maybe ask to the 2 people asking for it in the ticket.
At least they can test this code to see if it fits their needs.
Not sure it should be merged (hence the draft)

@rdswift
Copy link
Copy Markdown
Collaborator

rdswift commented Feb 16, 2026

A bit of thinking out loud here, but rather than using script_to_filename(), perhaps you could use ScriptParser.eval() to generate the regular expression to be used for checking the file names. That way the user could include reserved characters in the expression by escaping them (simlar to how it's done in the $rsearch() and $rreplace() scripting functions.

EDIT: There could even be a text box or label showing the regular expression created so the user could check that it made sense for them?

EDIT 2: For example, if the user entered something like:

.*%album%\\.\(png|jpg\)\$

would yield the regular expression:

.*Abbey Road\.(png|jpg)$

EDIT 3: Might need a new scripting function like $rsanitize() to replace invalid filename characters with regular expression wildcards to give you something like (assuming the album is "Back in Black" by AC/DC):

.*$rsanitize(%albumartist% - %album%)\\.\(png|jpg\)\$

would yield the regular expression:

.*AC.DC - Back in Black\.(png|jpg)$

@rdswift
Copy link
Copy Markdown
Collaborator

rdswift commented Feb 16, 2026

Just thinking that this might even allow the users to set track-specific cover art. Not something that I would want to do, but I've seen some users ask about this.

@rdswift
Copy link
Copy Markdown
Collaborator

rdswift commented Feb 17, 2026

EDIT 3: Might need a new scripting function like $rsanitize() to replace invalid filename characters with regular expression wildcards

Actually, that could already be accomplished using the $rreplace() scripting function.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants