# -*- coding: utf-8 -*- # # Copyright © 2018 Nick Bowler # # License GPLv3+: GNU General Public License version 3 or any later version. # This is free software: you are free to change and redistribute it. # There is NO WARRANTY, to the extent permitted by law. PLUGIN_NAME = u"Tweak filename filter" PLUGIN_AUTHOR = u"Nick Bowler" PLUGIN_DESCRIPTION = u'''

Adds additional options to tweak file naming.

Currently, this overrides the default methods to substitute forward and back-slashes, allowing alternate behaviours.

tweak_file_replace_backslash (bool)
if true, backslashes will be replaced when renaming files. (default: true)
tweak_file_replacement_char (string)
matching characters will be replaced by this string (default: _)
''' PLUGIN_VERSION = "0" PLUGIN_API_VERSIONS = ["1.0"] PLUGIN_LICENSE = "GPL-3.0-or-later" from picard import (config, log) import picard.util import re def modulename(): return modulename.__module__[len("picard.plugins."):] # Hook picard.util.sanitize_filename by replacing the underying re object. class SanitizeHook(object): def __init__(self): if config.setting["tweak_file_replace_backslash"]: self.re_match = re.compile(r'[\\/]', re.UNICODE) else: self.re_match = re.compile(r'[/]', re.UNICODE) def sub(self, repl, string): ret = self.re_match.sub( config.setting["tweak_file_replacement_char"], string) return ret def install_tweaker(): picard.util._re_slashes = SanitizeHook() log.info("%s activated" % (modulename())) config.TextOption("setting", "tweak_file_replacement_char", "_"), config.BoolOption("setting", "tweak_file_replace_backslash", True), if modulename() in config.setting["enabled_plugins"]: install_tweaker() else: log.debug("%s disabled in configuration" % (modulename()));