-
-
Save phw/1547137ebf7b6f344d0c548cc5ca5cf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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