# -*- coding: utf-8 -*-
#
-# Copyright © 2018-2019 Nick Bowler
+# Copyright © 2018-2020 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.
</dl>
'''
-PLUGIN_VERSION = "1"
+PLUGIN_VERSION = "2"
PLUGIN_API_VERSIONS = ["2.0"]
PLUGIN_LICENSE = "GPL-3.0-or-later"
self.ui.replace_backslashes.isChecked()
config.setting["tweak_file_replacement_char"] = \
self.ui.sanitize_replacement.text()
- picard.util._re_slashes.__init__()
+ install_tweaker()
# Hook picard.util.sanitize_filename by replacing the underying re object.
class SanitizeHook(object):
return ret
def install_tweaker():
- picard.util._re_slashes = SanitizeHook()
+ re = SanitizeHook()
+ if not hasattr(picard.util, "_re_slashes"):
+ # Harder to globally monkey patch this picard.util function on newer
+ # Picard, so instead we patch it in the two modules which import it.
+ orig_sanitize_filename = picard.util.sanitize_filename
+ def sanitize_filename_hook(string, **kwargs):
+ return orig_sanitize_filename(re.sub(None, string), **kwargs)
+
+ picard.util.scripttofilename.sanitize_filename = sanitize_filename_hook
+ picard.util.textencoding.sanitize_filename = sanitize_filename_hook
+ else:
+ # On older picard we can monkey patch the underlying re object.
+ picard.util._re_slashes = re
+
log.info("%s activated" % (modulename()))
if modulename() in config.setting["enabled_plugins"]: