Skip to content

Commit

Permalink
chroma: use multiple recording candidates
Browse files Browse the repository at this point in the history
  • Loading branch information
sampsyo committed Jun 6, 2012
1 parent 01fe599 commit d83c1fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
42 changes: 21 additions & 21 deletions beetsplug/chroma.py
Expand Up @@ -32,7 +32,7 @@


# Stores the Acoustid match information for each track. This is # Stores the Acoustid match information for each track. This is
# populated when an import task begins and then used when searching for # populated when an import task begins and then used when searching for
# candidates. It maps audio file paths to (recording_id, release_ids) # candidates. It maps audio file paths to (recording_ids, release_ids)
# pairs. If a given path is not present in the mapping, then no match # pairs. If a given path is not present in the mapping, then no match
# was found. # was found.
_matches = {} _matches = {}
Expand Down Expand Up @@ -71,25 +71,25 @@ def acoustid_match(path):
if res['status'] != 'ok' or not res.get('results'): if res['status'] != 'ok' or not res.get('results'):
log.debug('chroma: no match found') log.debug('chroma: no match found')
return None return None
result = res['results'][0] result = res['results'][0] # Best match.
if result['score'] < SCORE_THRESH: if result['score'] < SCORE_THRESH:
log.debug('chroma: no results above threshold') log.debug('chroma: no results above threshold')
return None return None
_acoustids[path] = result['id'] _acoustids[path] = result['id']


# Get recordings from the result. # Get recording and releases from the result.
if not result.get('recordings'): if not result.get('recordings'):
log.debug('chroma: no recordings found') log.debug('chroma: no recordings found')
return None return None
recording = result['recordings'][0] recording_ids = []
recording_id = recording['id'] release_ids = []
if 'releases' in recording: for recording in result['recordings']:
release_ids = [rel['id'] for rel in recording['releases']] recording_ids.append(recording['id'])
else: if 'releases' in recording:
release_ids = [] release_ids += [rel['id'] for rel in recording['releases']]


log.debug('chroma: matched recording {0}'.format(recording_id)) log.debug('chroma: matched recordings {0}'.format(recording_ids))
_matches[path] = recording_id, release_ids _matches[path] = recording_ids, release_ids




# Plugin structure and autotagging logic. # Plugin structure and autotagging logic.
Expand Down Expand Up @@ -118,8 +118,8 @@ def track_distance(self, item, info):
# Match failed. # Match failed.
return 0.0, 0.0 return 0.0, 0.0


recording_id, _ = _matches[item.path] recording_ids, _ = _matches[item.path]
if info.track_id == recording_id: if info.track_id in recording_ids:
dist = 0.0 dist = 0.0
else: else:
dist = TRACK_ID_WEIGHT dist = TRACK_ID_WEIGHT
Expand All @@ -139,14 +139,14 @@ def item_candidates(self, item):
if item.path not in _matches: if item.path not in _matches:
return [] return []


recording_id, _ = _matches[item.path] recording_ids, _ = _matches[item.path]
track = hooks._track_for_id(recording_id) tracks = []
if track: for recording_id in recording_ids:
log.debug('found acoustid item candidate') track = hooks._track_for_id(recording_id)
return [track] if track:
else: tracks.append(track)
log.debug('no acoustid item candidate found') log.debug('acoustid item candidates: {0}'.format(len(tracks)))
return [] return tracks


def configure(self, config): def configure(self, config):
global _userkey global _userkey
Expand Down
4 changes: 4 additions & 0 deletions docs/changelog.rst
Expand Up @@ -34,6 +34,10 @@ Changelog
* When previewing changes during import, differences in track duration are now * When previewing changes during import, differences in track duration are now
shown as "2:50 vs. 3:10" rather than separated with ``->`` like track numbers. shown as "2:50 vs. 3:10" rather than separated with ``->`` like track numbers.
This should clarify that beets isn't doing anything to modify lengths. This should clarify that beets isn't doing anything to modify lengths.
* :doc:`/plugins/chroma`: Fix tracking with ambiguous Acoustids. Some Acoustids
are identified with multiple recordings; beets now considers any associated
recording a valid match. This should reduce some cases of errant track
reordering when using chroma.
* Fix ID3 tag name for the catalog number field. * Fix ID3 tag name for the catalog number field.
* :doc:`/plugins/chroma`: Fix occasional crash at end of fingerprint submission * :doc:`/plugins/chroma`: Fix occasional crash at end of fingerprint submission
and give more context to "failed fingerprint generation" errors. and give more context to "failed fingerprint generation" errors.
Expand Down

0 comments on commit d83c1fa

Please sign in to comment.