mirror of
https://github.com/beetbox/beets.git
synced 2025-12-16 05:34:47 +01:00
clean up MusicBrainz IDs at the MB layer (rather than exposing them)
This commit is contained in:
parent
d9383aceb1
commit
ac35ef14df
4 changed files with 17 additions and 26 deletions
|
|
@ -257,7 +257,7 @@ def track_distance(item, track_data, track_index=None):
|
|||
|
||||
# MusicBrainz track ID.
|
||||
if item.mb_trackid:
|
||||
if item.mb_trackid != track_data['id'].rsplit('/', 1)[1]:
|
||||
if item.mb_trackid != track_data['id']:
|
||||
dist += TRACK_ID_WEIGHT
|
||||
dist_max += TRACK_ID_WEIGHT
|
||||
|
||||
|
|
@ -302,10 +302,6 @@ def apply_metadata(items, info):
|
|||
"""Set the items' metadata to match the data given in info. The
|
||||
list of items must be ordered.
|
||||
"""
|
||||
# Global MusicBrainz IDs (album and artist).
|
||||
mb_albumid = info['album_id'].rsplit('/', 1)[1]
|
||||
mb_artistid = info['artist_id'].rsplit('/', 1)[1]
|
||||
|
||||
for index, (item, track_data) in enumerate(zip(items, info['tracks'])):
|
||||
# Album, artist, track count.
|
||||
item.artist = info['artist']
|
||||
|
|
@ -324,11 +320,10 @@ def apply_metadata(items, info):
|
|||
item.title = track_data['title']
|
||||
item.track = index + 1
|
||||
|
||||
# MusicBrainz track ID.
|
||||
item.mb_trackid = track_data['id'].rsplit('/', 1)[1]
|
||||
# Album and artist IDs.
|
||||
item.mb_albumid = mb_albumid
|
||||
item.mb_artistid = mb_artistid
|
||||
# MusicBrainz IDs.
|
||||
item.mb_trackid = track_data['id']
|
||||
item.mb_albumid = info['album_id']
|
||||
item.mb_artistid = info['artist_id']
|
||||
|
||||
def match_by_id(items):
|
||||
"""If the items are tagged with a MusicBrainz album ID, returns an
|
||||
|
|
|
|||
|
|
@ -104,9 +104,9 @@ def release_dict(release, tracks=None):
|
|||
"""
|
||||
# Basic info.
|
||||
out = {'album': release.title,
|
||||
'album_id': release.id,
|
||||
'album_id': release.id.rsplit('/', 1)[1],
|
||||
'artist': release.artist.name,
|
||||
'artist_id': release.artist.id,
|
||||
'artist_id': release.artist.id.rsplit('/', 1)[1],
|
||||
'asin': release.asin,
|
||||
}
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ def release_dict(release, tracks=None):
|
|||
out['tracks'] = []
|
||||
for track in tracks:
|
||||
t = {'title': track.title,
|
||||
'id': track.id}
|
||||
'id': track.id.rsplit('/', 1)[1]}
|
||||
if track.duration is not None:
|
||||
# Duration not always present.
|
||||
t['length'] = track.duration/(1000.0)
|
||||
|
|
|
|||
|
|
@ -176,22 +176,18 @@ class ApplyTest(unittest.TestCase):
|
|||
trackinfo = []
|
||||
trackinfo.append({
|
||||
'title': 'oneNew',
|
||||
'id': 'http://musicbrainz.org/track/dfa939ec-118c-4d0f-'
|
||||
'84a0-60f3d1e6522c',
|
||||
'id': 'dfa939ec-118c-4d0f-84a0-60f3d1e6522c',
|
||||
})
|
||||
trackinfo.append({
|
||||
'title': 'twoNew',
|
||||
'id': 'http://musicbrainz.org/track/40130ed1-a27c-42fd-'
|
||||
'a328-1ebefb6caef4',
|
||||
'id': '40130ed1-a27c-42fd-a328-1ebefb6caef4',
|
||||
})
|
||||
self.info = {
|
||||
'tracks': trackinfo,
|
||||
'artist': 'artistNew',
|
||||
'album': 'albumNew',
|
||||
'album_id': 'http://musicbrainz.org/release/7edb51cb-77d6-'
|
||||
'4416-a23c-3a8c2994a2c7',
|
||||
'artist_id': 'http://musicbrainz.org/artist/a6623d39-2d8e-'
|
||||
'4f70-8242-0a9553b91e50',
|
||||
'album_id': '7edb51cb-77d6-4416-a23c-3a8c2994a2c7',
|
||||
'artist_id': 'a6623d39-2d8e-4f70-8242-0a9553b91e50',
|
||||
}
|
||||
|
||||
def test_titles_applied(self):
|
||||
|
|
|
|||
|
|
@ -56,10 +56,10 @@ class MBReleaseDictTest(unittest.TestCase):
|
|||
def _make_release(self, date_str='2009'):
|
||||
release = musicbrainz2.model.Release()
|
||||
release.title = 'ALBUM TITLE'
|
||||
release.id = 'ALBUM ID'
|
||||
release.id = 'domain/ALBUM ID'
|
||||
release.artist = musicbrainz2.model.Artist()
|
||||
release.artist.name = 'ARTIST NAME'
|
||||
release.artist.id = 'ARTIST ID'
|
||||
release.artist.id = 'domain/ARTIST ID'
|
||||
|
||||
event = musicbrainz2.model.ReleaseEvent()
|
||||
if date_str is not None:
|
||||
|
|
@ -94,8 +94,8 @@ class MBReleaseDictTest(unittest.TestCase):
|
|||
|
||||
def test_parse_tracks(self):
|
||||
release = self._make_release()
|
||||
tracks = [self._make_track('TITLE ONE', 'ID ONE', 100.0 * 1000.0),
|
||||
self._make_track('TITLE TWO', 'ID TWO', 200.0 * 1000.0)]
|
||||
tracks = [self._make_track('TITLE ONE', 'dom/ID ONE', 100.0 * 1000.0),
|
||||
self._make_track('TITLE TWO', 'dom/ID TWO', 200.0 * 1000.0)]
|
||||
d = mb.release_dict(release, tracks)
|
||||
t = d['tracks']
|
||||
self.assertEqual(len(t), 2)
|
||||
|
|
@ -114,7 +114,7 @@ class MBReleaseDictTest(unittest.TestCase):
|
|||
|
||||
def test_no_durations(self):
|
||||
release = self._make_release()
|
||||
tracks = [self._make_track('TITLE', 'ID', None)]
|
||||
tracks = [self._make_track('TITLE', 'dom/ID', None)]
|
||||
d = mb.release_dict(release, tracks)
|
||||
self.assertFalse('length' in d['tracks'][0])
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue