Skip to content

Commit

Permalink
Changelog and style for #908
Browse files Browse the repository at this point in the history
Use a defaultdict for more idiomatic collection.
  • Loading branch information
sampsyo committed Aug 22, 2014
1 parent 9ca6ae6 commit e52ca41
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
32 changes: 15 additions & 17 deletions beetsplug/mbsync.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from beets import autotag, library, ui, util
from beets.autotag import hooks
from beets import config
from collections import defaultdict

log = logging.getLogger('beets')

Expand Down Expand Up @@ -64,30 +65,27 @@ 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 = {}
# Map recording MBIDs to their information. Recordings can appear
# multiple times on a release, so each MBID maps to a list of TrackInfo
# objects.
track_index = defaultdict(list)
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]
track_index[track_info.track_id].append(track_info)

# Construct a track mapping according to MBIDs. This should work
# 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.
# for albums that have missing or extra tracks. If there are multiple
# copies of a recording, they are disambiguated using their disc and
# track number.
mapping = {}
for item in items:
candidates = track_index.get(item.mb_trackid, [])
candidates = track_index[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
else:
for c in candidates:
if c.medium_index == item.track and c.medium == item.disc:
mapping[item] = c
break

# Apply.
with lib.transaction():
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Little improvements and fixes:
work in ``auto`` mode. Thanks to Harry Khanna.
* The :ref:`write-cmd` command now has a ``--force`` flag. Thanks again to
Harry Khanna.
* :doc:`/plugins/mbsync`: Track alignment now works with albums that have
multiple copies of the same recording. Thanks to Rui Gonçalves.


1.3.6 (May 10, 2014)
Expand Down

0 comments on commit e52ca41

Please sign in to comment.