Skip to content

Instantly share code, notes, and snippets.

@phw
Created May 31, 2021 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phw/1547137ebf7b6f344d0c548cc5ca5cf3 to your computer and use it in GitHub Desktop.
Save phw/1547137ebf7b6f344d0c548cc5ca5cf3 to your computer and use it in GitHub Desktop.
PLUGIN_NAME = '$rperformer function'
PLUGIN_AUTHOR = 'Philipp Wolfer'
PLUGIN_DESCRIPTION = 'Like $performer but supports regular expressions'
PLUGIN_VERSION = "1.0"
PLUGIN_API_VERSIONS = ["2.0", "2.1", "2.2", "2.3", "2.4", "2.5", "2.6"]
PLUGIN_LICENSE = "GPL-2.0-or-later"
PLUGIN_LICENSE_URL = "https://www.gnu.org/licenses/gpl-2.0.html"
import re
from picard.script import register_script_function
def rperformer(parser, pattern="", join=", "):
values = []
for name, value in parser.context.items():
if name.startswith("performer:"):
name, performance = name.split(':', 2)
try:
match = bool(re.search(pattern, performance))
except re.error:
# fall back to simple string matching if regex is invalid
match = pattern in performance
if match:
values.append(value)
return join.join(values)
register_script_function(rperformer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment