From 8dc7a80a8f23b7d0119658a1cda3ed4cecfd66de Mon Sep 17 00:00:00 2001 From: Sophist Date: Mon, 3 Jun 2013 22:49:48 +0100 Subject: [PATCH 1/5] Make track lengths within 1s of each other match Due to minor timing differences when ripping a CD, it is common for tracks to differ by up to 1s in length. This commit enhances metadatabox to show lengths +/- 1s as matching. Note: Means of converting mmm:ss to seconds is not elegant - anyone with a better solution please say. --- picard/ui/metadatabox.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/picard/ui/metadatabox.py b/picard/ui/metadatabox.py index 5433bc105..2dc2a07ab 100644 --- a/picard/ui/metadatabox.py +++ b/picard/ui/metadatabox.py @@ -97,6 +97,22 @@ class TagDiff: self.status = defaultdict(lambda: 0) self.objects = 0 + import re + __length_ne_re = re.compile(r"^(\d+):(\d\d)$") + + def __length_ne(self,orig,new): + match = self.__length_ne_re.match(orig[0]) + if match: + orig_length = int(match.group(1))*60+int(match.group(2)) + else: + orig_length = 0 + match = self.__length_ne_re.match(new[0]) + if match: + new_length = int(match.group(1))*60+int(match.group(2)) + else: + new_length = 0 + return abs(new_length - orig_length) > 1 + def add(self, tag, orig_values, new_values, removable): if orig_values: orig_values = sorted(orig_values) @@ -112,7 +128,9 @@ class TagDiff: elif new_values and not orig_values: self.status[tag] |= TagStatus.Added removable = True - elif orig_values and new_values and orig_values != new_values: + elif orig_values and new_values and tag=="~length" and self.__length_ne(orig_values,new_values): + self.status[tag] |= TagStatus.Changed + elif orig_values and new_values and tag!="~length" and orig_values != new_values: self.status[tag] |= TagStatus.Changed elif not (orig_values or new_values or tag in COMMON_TAGS): self.status[tag] |= TagStatus.Empty From 3f6c64da879b628fe71e098dd8e55ae93fa5899f Mon Sep 17 00:00:00 2001 From: Sophist Date: Wed, 5 Jun 2013 13:54:33 +0100 Subject: [PATCH 2/5] Changed to implement bitmap's alternative approach --- picard/ui/metadatabox.py | 47 +++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/picard/ui/metadatabox.py b/picard/ui/metadatabox.py index 2dc2a07ab..8dd2f8918 100644 --- a/picard/ui/metadatabox.py +++ b/picard/ui/metadatabox.py @@ -25,9 +25,10 @@ from picard.cluster import Cluster from picard.track import Track from picard.file import File from picard.config import TextOption, BoolOption -from picard.util import partial +from picard.util import partial, format_time from picard.util.tags import display_tag_name from picard.ui.edittagdialog import EditTagDialog +from picard.metadata import MULTI_VALUED_JOINER COMMON_TAGS = [ @@ -82,7 +83,11 @@ class TagCounter(dict): if tag in self.different: return (ungettext("(different across %d item)", "(different across %d items)", count) % count, True) else: - msg = "; ".join(self[tag]) + if tag == "~length": + msg = format_time(self[tag]) + else: + msg = MULTI_VALUED_JOINER.join(self[tag]) + if count > 0 and missing > 0: return (msg + " " + (ungettext("(missing from %d item)", "(missing from %d items)", missing) % missing), True) else: @@ -97,29 +102,17 @@ class TagDiff: self.status = defaultdict(lambda: 0) self.objects = 0 - import re - __length_ne_re = re.compile(r"^(\d+):(\d\d)$") - - def __length_ne(self,orig,new): - match = self.__length_ne_re.match(orig[0]) - if match: - orig_length = int(match.group(1))*60+int(match.group(2)) + def __tag_ne(self,tag,orig,new): + if tag == "~length": + return abs(orig-new)>1000 else: - orig_length = 0 - match = self.__length_ne_re.match(new[0]) - if match: - new_length = int(match.group(1))*60+int(match.group(2)) - else: - new_length = 0 - return abs(new_length - orig_length) > 1 + return orig!=new 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: @@ -128,9 +121,7 @@ class TagDiff: elif new_values and not orig_values: self.status[tag] |= TagStatus.Added removable = True - elif orig_values and new_values and tag=="~length" and self.__length_ne(orig_values,new_values): - self.status[tag] |= TagStatus.Changed - elif orig_values and new_values and tag!="~length" and orig_values != new_values: + elif orig_values and new_values and self.__tag_ne(tag,orig_values, new_values): self.status[tag] |= TagStatus.Changed elif not (orig_values or new_values or tag in COMMON_TAGS): self.status[tag] |= TagStatus.Empty @@ -209,7 +200,7 @@ class MetadataBox(QtGui.QTableWidget): else: self.editing = True self.itemChanged.disconnect(self.item_changed) - item.setText("; ".join(values)) + item.setText(MULTI_VALUED_JOINER.join(values)) self.itemChanged.connect(self.item_changed) return QtGui.QTableWidget.edit(self, index, trigger, event) return False @@ -375,8 +366,7 @@ class MetadataBox(QtGui.QTableWidget): tags = set(new_metadata.keys()) tags.update(orig_metadata.keys()) - for name in filter(lambda x: not x.startswith("~") or x == "~length", tags): - + for name in filter(lambda x: not x.startswith("~"), tags): new_values = new_metadata.getall(name) orig_values = orig_metadata.getall(name) @@ -386,11 +376,18 @@ class MetadataBox(QtGui.QTableWidget): tag_diff.add(name, orig_values, new_values, clear_existing_tags) + tag_diff.add("~length", + orig_metadata.length, new_metadata.length, False) + for track in self.tracks: if track.num_linked_files == 0: for name, values in dict.iteritems(track.metadata): - if not name.startswith("~") or name == "~length": + if not name.startswith("~"): tag_diff.add(name, values, values, True) + + length = track.metadata.length + tag_diff.add("~length", length, length, False) + tag_diff.objects += 1 all_tags = set(orig_tags.keys() + new_tags.keys()) From 591eee0fcff2d0291ad775905607d6965f60455f Mon Sep 17 00:00:00 2001 From: Sophist Date: Wed, 5 Jun 2013 18:18:15 +0100 Subject: [PATCH 3/5] Fix vertical alignment with right-aligned lengths --- picard/ui/itemviews.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/picard/ui/itemviews.py b/picard/ui/itemviews.py index 0c913f577..1820faa30 100644 --- a/picard/ui/itemviews.py +++ b/picard/ui/itemviews.py @@ -547,7 +547,7 @@ class TreeItem(QtGui.QTreeWidgetItem): obj.item = self if sortable: self.__lt__ = self._lt - self.setTextAlignment(1, QtCore.Qt.AlignRight) + self.setTextAlignment(1, QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter) def _lt(self, other): column = self.treeWidget().sortColumn() From 20d7debd6cceaa5ea5315494fcab7c76c71781ea Mon Sep 17 00:00:00 2001 From: Sophist Date: Wed, 5 Jun 2013 20:55:13 +0100 Subject: [PATCH 4/5] Change matching fuzziness to 2s --- picard/ui/metadatabox.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/picard/ui/metadatabox.py b/picard/ui/metadatabox.py index 8dd2f8918..54f94002e 100644 --- a/picard/ui/metadatabox.py +++ b/picard/ui/metadatabox.py @@ -104,7 +104,7 @@ class TagDiff: def __tag_ne(self,tag,orig,new): if tag == "~length": - return abs(orig-new)>1000 + return abs(orig-new)>2000 else: return orig!=new From 2d620e6f1e9e4225b24f314849d1831d6bdd499c Mon Sep 17 00:00:00 2001 From: Michael Wiencek Date: Wed, 5 Jun 2013 15:02:10 -0500 Subject: [PATCH 5/5] whitespace --- picard/ui/metadatabox.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/picard/ui/metadatabox.py b/picard/ui/metadatabox.py index 54f94002e..d4694024c 100644 --- a/picard/ui/metadatabox.py +++ b/picard/ui/metadatabox.py @@ -102,11 +102,11 @@ class TagDiff: self.status = defaultdict(lambda: 0) self.objects = 0 - def __tag_ne(self,tag,orig,new): + def __tag_ne(self, tag, orig, new): if tag == "~length": - return abs(orig-new)>2000 + return abs(orig - new) > 2000 else: - return orig!=new + return orig != new def add(self, tag, orig_values, new_values, removable): if orig_values: @@ -121,7 +121,7 @@ class TagDiff: elif new_values and not orig_values: self.status[tag] |= TagStatus.Added removable = True - elif orig_values and new_values and self.__tag_ne(tag,orig_values, new_values): + elif orig_values and new_values and self.__tag_ne(tag, orig_values, new_values): self.status[tag] |= TagStatus.Changed elif not (orig_values or new_values or tag in COMMON_TAGS): self.status[tag] |= TagStatus.Empty