Skip to content

Commit 9ca6ae6

Browse files
committed
Merge pull request #908 from ruippeixotog/issue-230
Add support for releases with multiple versions of the same recording
2 parents 8467b5e + 7c19679 commit 9ca6ae6

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

beetsplug/mbsync.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,29 @@ def mbsync_albums(lib, query, move, pretend, write):
6464
log.info(u'Release ID not found: {0}'.format(a.mb_albumid))
6565
continue
6666

67+
# Construct an hash mapping recording MBIDs to their information. A
68+
# release can have recording MBIDs that appear multiple times in the
69+
# same release.
70+
track_index = {}
71+
for track_info in album_info.tracks:
72+
if track_info.track_id in track_index:
73+
track_index[track_info.track_id].append(track_info)
74+
else:
75+
track_index[track_info.track_id] = [track_info]
76+
6777
# Construct a track mapping according to MBIDs. This should work
68-
# for albums that have missing or extra tracks.
78+
# for albums that have missing or extra tracks. If a mapping is
79+
# ambiguous, the items' disc and track number need to match in order
80+
# for an item to be mapped.
6981
mapping = {}
7082
for item in items:
71-
for track_info in album_info.tracks:
72-
if item.mb_trackid == track_info.track_id:
73-
mapping[item] = track_info
83+
candidates = track_index.get(item.mb_trackid, [])
84+
if len(candidates) == 1:
85+
mapping[item] = candidates[0]
86+
continue
87+
for c in candidates:
88+
if c.medium_index == item.track and c.medium == item.disc:
89+
mapping[item] = c
7490
break
7591

7692
# Apply.

0 commit comments

Comments
 (0)