From 2fda23100409853aebf0a801869e92712d3fbe00 Mon Sep 17 00:00:00 2001 From: Tai Lee Date: Tue, 21 May 2013 23:50:02 +1000 Subject: [PATCH] Abstract method to determine if track number has changed. This is a little more accurate than the previous method (check if track is in index or medium_index) by looking at the `per_disc_numbering` setting and comparing the index or medium index accordingly. It's also a little more accurate in the display output by diffing the combined `disc-track` to `medium-medium_index` (if using per disc numbering) and intelligently colorizing the either the whole track number or just the suffix. --- beets/autotag/match.py | 14 +++++++++++--- beets/ui/commands.py | 33 +++++++++++++++++++++++---------- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/beets/autotag/match.py b/beets/autotag/match.py index c423e7a56..1f60e59ff 100644 --- a/beets/autotag/match.py +++ b/beets/autotag/match.py @@ -196,6 +196,14 @@ def assign_items(items, tracks): extra_tracks = set(tracks) - set(mapping.values()) return mapping, extra_items, extra_tracks +def track_index_changed(item, track_info): + if config['per_disc_numbering'].get(bool): + if item.track != track_info.medium_index: + return True + elif item.track != track_info.index: + return True + return False + def track_distance(item, track_info, incl_artist=False): """Determines the significance of a track metadata change. Returns a float in [0.0,1.0]. `incl_artist` indicates that a distance @@ -230,7 +238,7 @@ def track_distance(item, track_info, incl_artist=False): # Track index. if track_info.index and item.track: - if item.track not in (track_info.index, track_info.medium_index): + if track_index_changed(item, track_info): dist += TRACK_INDEX_WEIGHT dist_max += TRACK_INDEX_WEIGHT @@ -374,8 +382,8 @@ def _recommendation(results): rec = max_rec['tracklength'] # Track number differs. - elif rec > max_rec['tracknumber'] and item.track not in \ - (track_info.index, track_info.medium_index): + elif rec > max_rec['tracknumber'] and \ + track_index_changed(item, track_info): rec = max_rec['tracknumber'] return rec diff --git a/beets/ui/commands.py b/beets/ui/commands.py index 2cd1ec682..706ca5a95 100644 --- a/beets/ui/commands.py +++ b/beets/ui/commands.py @@ -163,14 +163,22 @@ def show_change(cur_artist, cur_album, match): """Return a string representing the track index of the given TrackInfo object. """ - if config['per_disc_numbering'].get(bool): - if match.info.mediums > 1: - return u'{0}-{1}'.format(track_info.medium, - track_info.medium_index) - else: - return unicode(track_info.medium_index) + if isinstance(track_info, autotag.hooks.TrackInfo): + index = track_info.index + medium_index = track_info.medium_index + medium = track_info.medium + mediums = match.info.mediums else: - return unicode(track_info.index) + index = medium_index = track_info.track + medium = track_info.disc + mediums = track_info.disctotal + if config['per_disc_numbering'].get(bool): + if mediums > 1: + return u'{0}-{1}'.format(medium, medium_index) + else: + return unicode(medium_index) + else: + return unicode(index) # Identify the album in question. if cur_artist != match.info.artist or \ @@ -222,9 +230,14 @@ def show_change(cur_artist, cur_album, match): lhs_width = len(cur_title) # Track number change. - if item.track not in (track_info.index, track_info.medium_index): - cur_track, new_track = unicode(item.track), format_index(track_info) - lhs_track, rhs_track = ui.color_diff_suffix(cur_track, new_track) + cur_track, new_track = format_index(item), format_index(track_info) + if cur_track != new_track: + if (cur_track + new_track).count('-') == 1: + lhs_track, rhs_track = ui.colorize('red', cur_track), \ + ui.colorize('red', new_track) + else: + lhs_track, rhs_track = ui.color_diff_suffix(cur_track, + new_track) templ = ui.colorize('red', u' (#') + u'{0}' + \ ui.colorize('red', u')') lhs += templ.format(lhs_track)