mirror of
https://github.com/beetbox/beets.git
synced 2025-12-08 09:34:23 +01:00
autotagger now applies MusicBrainz IDs
This commit is contained in:
parent
aec7bef504
commit
3ce936701a
2 changed files with 75 additions and 1 deletions
|
|
@ -282,11 +282,17 @@ 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']
|
||||
item.album = info['album']
|
||||
item.tracktotal = len(items)
|
||||
|
||||
# Release date.
|
||||
if 'year' in info:
|
||||
item.year = info['year']
|
||||
if 'month' in info:
|
||||
|
|
@ -294,10 +300,15 @@ def apply_metadata(items, info):
|
|||
if 'day' in info:
|
||||
item.day = info['day']
|
||||
|
||||
# Title and track index.
|
||||
item.title = track_data['title']
|
||||
item.track = index + 1
|
||||
|
||||
#fixme Set MusicBrainz IDs
|
||||
# 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
|
||||
|
||||
def tag_album(items, search_artist=None, search_album=None):
|
||||
"""Bundles together the functionality used to infer tags for a
|
||||
|
|
|
|||
|
|
@ -221,6 +221,69 @@ class OrderingTest(unittest.TestCase):
|
|||
self.assertEqual(ordered[1].title, 'two')
|
||||
self.assertEqual(ordered[2].title, 'three')
|
||||
|
||||
class ApplyTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.items = []
|
||||
self.items.append(Item({}))
|
||||
self.items.append(Item({}))
|
||||
trackinfo = []
|
||||
trackinfo.append({
|
||||
'title': 'oneNew',
|
||||
'id': 'http://musicbrainz.org/track/dfa939ec-118c-4d0f-'
|
||||
'84a0-60f3d1e6522c',
|
||||
})
|
||||
trackinfo.append({
|
||||
'title': 'twoNew',
|
||||
'id': 'http://musicbrainz.org/track/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',
|
||||
}
|
||||
|
||||
def test_titles_applied(self):
|
||||
autotag.apply_metadata(self.items, self.info)
|
||||
self.assertEqual(self.items[0].title, 'oneNew')
|
||||
self.assertEqual(self.items[1].title, 'twoNew')
|
||||
|
||||
def test_album_and_artist_applied_to_all(self):
|
||||
autotag.apply_metadata(self.items, self.info)
|
||||
self.assertEqual(self.items[0].album, 'albumNew')
|
||||
self.assertEqual(self.items[1].album, 'albumNew')
|
||||
self.assertEqual(self.items[0].artist, 'artistNew')
|
||||
self.assertEqual(self.items[1].artist, 'artistNew')
|
||||
|
||||
def test_track_index_applied(self):
|
||||
autotag.apply_metadata(self.items, self.info)
|
||||
self.assertEqual(self.items[0].track, 1)
|
||||
self.assertEqual(self.items[1].track, 2)
|
||||
|
||||
def test_track_total_applied(self):
|
||||
autotag.apply_metadata(self.items, self.info)
|
||||
self.assertEqual(self.items[0].tracktotal, 2)
|
||||
self.assertEqual(self.items[1].tracktotal, 2)
|
||||
|
||||
def test_mb_trackid_applied(self):
|
||||
autotag.apply_metadata(self.items, self.info)
|
||||
self.assertEqual(self.items[0].mb_trackid,
|
||||
'dfa939ec-118c-4d0f-84a0-60f3d1e6522c')
|
||||
self.assertEqual(self.items[1].mb_trackid,
|
||||
'40130ed1-a27c-42fd-a328-1ebefb6caef4')
|
||||
|
||||
def test_mb_albumid_and_artistid_applied(self):
|
||||
autotag.apply_metadata(self.items, self.info)
|
||||
for item in self.items:
|
||||
self.assertEqual(item.mb_albumid,
|
||||
'7edb51cb-77d6-4416-a23c-3a8c2994a2c7')
|
||||
self.assertEqual(item.mb_artistid,
|
||||
'a6623d39-2d8e-4f70-8242-0a9553b91e50')
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue