mirror of
https://github.com/beetbox/beets.git
synced 2026-01-17 05:34:23 +01:00
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.
This commit is contained in:
parent
26682f9168
commit
2fda231004
2 changed files with 34 additions and 13 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue