Skip to content

Commit

Permalink
Merge pull request #908 from ruippeixotog/issue-230
Browse files Browse the repository at this point in the history
Add support for releases with multiple versions of the same recording
  • Loading branch information
sampsyo committed Aug 22, 2014
2 parents 8467b5e + 7c19679 commit 9ca6ae6
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions beetsplug/mbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,29 @@ def mbsync_albums(lib, query, move, pretend, write):
log.info(u'Release ID not found: {0}'.format(a.mb_albumid))
continue

# Construct an hash mapping recording MBIDs to their information. A
# release can have recording MBIDs that appear multiple times in the
# same release.
track_index = {}
for track_info in album_info.tracks:
if track_info.track_id in track_index:
track_index[track_info.track_id].append(track_info)
else:
track_index[track_info.track_id] = [track_info]

# Construct a track mapping according to MBIDs. This should work
# for albums that have missing or extra tracks.
# for albums that have missing or extra tracks. If a mapping is
# ambiguous, the items' disc and track number need to match in order
# for an item to be mapped.
mapping = {}
for item in items:
for track_info in album_info.tracks:
if item.mb_trackid == track_info.track_id:
mapping[item] = track_info
candidates = track_index.get(item.mb_trackid, [])
if len(candidates) == 1:
mapping[item] = candidates[0]
continue
for c in candidates:
if c.medium_index == item.track and c.medium == item.disc:
mapping[item] = c
break

# Apply.
Expand Down

0 comments on commit 9ca6ae6

Please sign in to comment.