From 738fbd94d5c470bb0de35ae5d0a7e7a66f97bfda Mon Sep 17 00:00:00 2001 From: Sophist Date: Mon, 3 Jun 2013 08:17:53 +0100 Subject: [PATCH] Remove sorting for displayed multi-value tags and provide a sort tags plugin Picard stores tags unsorted but displays them sorted and this is inconsistent. This commit removes display sorting of multi-value tags from Picard improves consistency by displaying what will be / is actually saved. This commit also provides a plug-in to allow user to sort tags both displayed and stored in the file. --- contrib/plugins/sort_multivalue_tags.py | 34 +++++++++++++++++++++++++ picard/ui/metadatabox.py | 2 -- 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 contrib/plugins/sort_multivalue_tags.py diff --git a/contrib/plugins/sort_multivalue_tags.py b/contrib/plugins/sort_multivalue_tags.py new file mode 100644 index 000000000..e5d052d0c --- /dev/null +++ b/contrib/plugins/sort_multivalue_tags.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +# This is the Sort Multivalue Tags plugin for MusicBrainz Picard. +# Copyright (C) 2013 Sophist +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +PLUGIN_NAME = u"Sort Multi-Value Tags" +PLUGIN_AUTHOR = u"Sophist" +PLUGIN_DESCRIPTION = u'Sort Multi-Value Tags e.g. Release Type, Lyrics alphabetically.' +PLUGIN_VERSION = "0.1" +PLUGIN_API_VERSIONS = ["0.15"] + +from picard.metadata import register_track_metadata_processor + +# Define and register the Track Metadata function +def sort_multivalue_tags(tagger, metadata, track, release): + + for tag in filter(lambda x: len(metadata[x]) > 1, metadata.keys()): + data = metadata.getall(tag) + if len(data) > 1: + sorted_data = sorted(data) + if data != sorted_data: + metadata.set(tag,sorted_data) + +register_track_metadata_processor(sort_multivalue_tags) diff --git a/picard/ui/metadatabox.py b/picard/ui/metadatabox.py index 5433bc105..1a2f38624 100644 --- a/picard/ui/metadatabox.py +++ b/picard/ui/metadatabox.py @@ -99,11 +99,9 @@ class TagDiff: def add(self, tag, orig_values, new_values, removable): if orig_values: - orig_values = sorted(orig_values) self.orig.add(tag, orig_values) if new_values: - new_values = sorted(new_values) self.new.add(tag, new_values) if orig_values and not new_values: