From ae91763d9bde591b2b8482b997aed07e80aa5f38 Mon Sep 17 00:00:00 2001 From: ShubhamBhut Date: Sun, 7 Apr 2024 07:48:44 +0530 Subject: [PATCH] PICARD-2729: Allow disabling date sanitazation for APE and Vorbis tags --- picard/formats/apev2.py | 5 ++++- picard/formats/vorbis.py | 8 ++++++-- picard/profile.py | 1 + picard/ui/options/metadata.py | 3 +++ picard/ui/ui_options_metadata.py | 7 ++++++- test/formats/common.py | 1 + 6 files changed, 21 insertions(+), 4 deletions(-) diff --git a/picard/formats/apev2.py b/picard/formats/apev2.py index 777fd7c0f28..fa25bf7568b 100644 --- a/picard/formats/apev2.py +++ b/picard/formats/apev2.py @@ -135,6 +135,8 @@ def _load(self, filename): self.__casemap = {} file = self._File(encode_filename(filename)) metadata = Metadata() + config = get_config() + date_sanitize = not config.setting['disable_date_sanitize'] if file.tags: for origname, values in file.tags.items(): name_lower = origname.lower() @@ -160,7 +162,8 @@ def _load(self, filename): name = name_lower if name == 'year': name = 'date' - value = sanitize_date(value) + if date_sanitize: + value = sanitize_date(value) elif name == 'track': name = 'tracknumber' track = value.split('/') diff --git a/picard/formats/vorbis.py b/picard/formats/vorbis.py index 25ac86d5175..63b5be368a4 100644 --- a/picard/formats/vorbis.py +++ b/picard/formats/vorbis.py @@ -136,13 +136,16 @@ def _load(self, filename): file = self._File(encode_filename(filename)) file.tags = file.tags or {} metadata = Metadata() + config = get_config() + date_sanitize = not config.setting['disable_date_sanitize'] for origname, values in file.tags.items(): for value in values: value = value.rstrip('\0') name = origname if name in {'date', 'originaldate', 'releasedate'}: # YYYY-00-00 => YYYY - value = sanitize_date(value) + if date_sanitize: + value = sanitize_date(value) elif name == 'performer' or name == 'comment': # transform "performer=Joe Barr (Piano)" to "performer:Piano=Joe Barr" name += ':' @@ -280,7 +283,8 @@ def _save(self, filename, metadata): name = 'lyrics' elif name in {'date', 'originaldate', 'releasedate'}: # YYYY-00-00 => YYYY - value = sanitize_date(value) + if not config.setting['disable_date_sanitize']: + value = sanitize_date(value) elif name.startswith('performer:') or name.startswith('comment:'): # transform "performer:Piano=Joe Barr" to "performer=Joe Barr (Piano)" name, desc = name.split(':', 1) diff --git a/picard/profile.py b/picard/profile.py index 360908b9a5e..fbcc44655d6 100644 --- a/picard/profile.py +++ b/picard/profile.py @@ -70,6 +70,7 @@ class UserProfileGroups(): SettingDesc('convert_punctuation', ['convert_punctuation']), SettingDesc('release_ars', ['release_ars']), SettingDesc('track_ars', ['track_ars']), + SettingDesc('disable_date_sanitize', ['disable_date_sanitize']), SettingDesc('guess_tracknumber_and_title', ['guess_tracknumber_and_title']), SettingDesc('va_name', ['va_name']), SettingDesc('nat_name', ['nat_name']), diff --git a/picard/ui/options/metadata.py b/picard/ui/options/metadata.py index f1c34eae004..2e9a37bab0d 100644 --- a/picard/ui/options/metadata.py +++ b/picard/ui/options/metadata.py @@ -92,6 +92,7 @@ class MetadataOptionsPage(OptionsPage): ListOption('setting', 'script_exceptions', [], title=N_("Translation script exceptions")), BoolOption('setting', 'release_ars', True, title=N_("Use release relationships")), BoolOption('setting', 'track_ars', False, title=N_("Use track and release relationships")), + BoolOption('setting', 'disable_date_sanitize', False, title=N_("Disable date sanitization for APE and Vorbis tags")), BoolOption('setting', 'convert_punctuation', False, title=N_("Convert Unicode punctuation characters to ASCII")), BoolOption('setting', 'standardize_artists', False, title=N_("Use standardized artist names")), BoolOption('setting', 'standardize_instruments', True, title=N_("Use standardized instrument and vocal credits")), @@ -121,6 +122,7 @@ def load(self): self.ui.convert_punctuation.setChecked(config.setting['convert_punctuation']) self.ui.release_ars.setChecked(config.setting['release_ars']) self.ui.track_ars.setChecked(config.setting['track_ars']) + self.ui.disable_date_sanitize.setChecked(config.setting['disable_date_sanitize']) self.ui.va_name.setText(config.setting['va_name']) self.ui.nat_name.setText(config.setting['nat_name']) self.ui.standardize_artists.setChecked(config.setting['standardize_artists']) @@ -152,6 +154,7 @@ def save(self): config.setting['convert_punctuation'] = self.ui.convert_punctuation.isChecked() config.setting['release_ars'] = self.ui.release_ars.isChecked() config.setting['track_ars'] = self.ui.track_ars.isChecked() + config.setting['disable_date_sanitize'] = self.ui.disable_date_sanitize.isChecked() config.setting['va_name'] = self.ui.va_name.text() nat_name = self.ui.nat_name.text() if nat_name != config.setting['nat_name']: diff --git a/picard/ui/ui_options_metadata.py b/picard/ui/ui_options_metadata.py index cd6cfe2a48b..7936371e602 100644 --- a/picard/ui/ui_options_metadata.py +++ b/picard/ui/ui_options_metadata.py @@ -72,6 +72,9 @@ def setupUi(self, MetadataOptionsPage): self.guess_tracknumber_and_title = QtWidgets.QCheckBox(self.metadata_groupbox) self.guess_tracknumber_and_title.setObjectName("guess_tracknumber_and_title") self.verticalLayout_3.addWidget(self.guess_tracknumber_and_title) + self.disable_date_sanitize = QtWidgets.QCheckBox(self.metadata_groupbox) + self.disable_date_sanitize.setObjectName("disable_date_sanitize") + self.verticalLayout_3.addWidget(self.disable_date_sanitize) self.verticalLayout.addWidget(self.metadata_groupbox) self.custom_fields_groupbox = QtWidgets.QGroupBox(MetadataOptionsPage) sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Policy.Preferred, QtWidgets.QSizePolicy.Policy.Maximum) @@ -121,7 +124,8 @@ def setupUi(self, MetadataOptionsPage): MetadataOptionsPage.setTabOrder(self.convert_punctuation, self.release_ars) MetadataOptionsPage.setTabOrder(self.release_ars, self.track_ars) MetadataOptionsPage.setTabOrder(self.track_ars, self.guess_tracknumber_and_title) - MetadataOptionsPage.setTabOrder(self.guess_tracknumber_and_title, self.va_name) + MetadataOptionsPage.setTabOrder(self.guess_tracknumber_and_title, self.disable_date_sanitize) + MetadataOptionsPage.setTabOrder(self.disable_date_sanitize, self.va_name) MetadataOptionsPage.setTabOrder(self.va_name, self.va_name_default) MetadataOptionsPage.setTabOrder(self.va_name_default, self.nat_name) MetadataOptionsPage.setTabOrder(self.nat_name, self.nat_name_default) @@ -139,6 +143,7 @@ def retranslateUi(self, MetadataOptionsPage): self.release_ars.setText(_("Use release relationships")) self.track_ars.setText(_("Use track relationships")) self.guess_tracknumber_and_title.setText(_("Guess track number and title from filename if empty")) + self.disable_date_sanitize.setText(_("Disable sanitizing date for APE and Vorbis tags")) self.custom_fields_groupbox.setTitle(_("Custom Fields")) self.label_6.setText(_("Various artists:")) self.label_7.setText(_("Standalone recordings:")) diff --git a/test/formats/common.py b/test/formats/common.py index b4459e88f0b..53282d4d470 100644 --- a/test/formats/common.py +++ b/test/formats/common.py @@ -65,6 +65,7 @@ 'replace_spaces_with_underscores': False, 'replace_dir_separator': '_', 'win_compat_replacements': {}, + 'disable_date_sanitize': False, }