apply artist credits & add to database (GC-286)

This commit is contained in:
Adrian Sampson 2012-05-19 16:13:15 -07:00
parent e56ca46b75
commit 711a1c1113
6 changed files with 70 additions and 36 deletions

View file

@ -106,6 +106,8 @@ def apply_item_metadata(item, track_info):
"""Set an item's metadata from its matched TrackInfo object.
"""
item.artist = track_info.artist
item.artist_sort = track_info.artist_sort
item.artist_credit = track_info.artist_credit
item.title = track_info.title
item.mb_trackid = track_info.track_id
if track_info.artist_id:
@ -130,12 +132,12 @@ def apply_metadata(items, album_info, per_disc_numbering=False):
item.album = album_info.album
item.tracktotal = len(items)
# Artist sort names.
if track_info.artist_sort:
item.artist_sort = track_info.artist_sort
else:
item.artist_sort = album_info.artist_sort
# Artist sort and credit names.
item.artist_sort = track_info.artist_sort or album_info.artist_sort
item.artist_credit = track_info.artist_credit or \
album_info.artist_credit
item.albumartist_sort = album_info.artist_sort
item.albumartist_credit = album_info.artist_credit
# Release date.
if album_info.year:

View file

@ -46,9 +46,11 @@ ITEM_FIELDS = [
('title', 'text', True, True),
('artist', 'text', True, True),
('artist_sort', 'text', True, True),
('artist_credit', 'text', True, True),
('album', 'text', True, True),
('albumartist', 'text', True, True),
('albumartist_sort', 'text', True, True),
('albumartist_credit', 'text', True, True),
('genre', 'text', True, True),
('composer', 'text', True, True),
('grouping', 'text', True, True),
@ -102,29 +104,30 @@ ALBUM_FIELDS = [
('id', 'integer primary key', False),
('artpath', 'blob', False),
('albumartist', 'text', True),
('albumartist_sort', 'text', True),
('album', 'text', True),
('genre', 'text', True),
('year', 'int', True),
('month', 'int', True),
('day', 'int', True),
('tracktotal', 'int', True),
('disctotal', 'int', True),
('comp', 'bool', True),
('mb_albumid', 'text', True),
('mb_albumartistid', 'text', True),
('albumtype', 'text', True),
('label', 'text', True),
('mb_releasegroupid', 'text', True),
('asin', 'text', True),
('catalognum', 'text', True),
('script', 'text', True),
('language', 'text', True),
('country', 'text', True),
('albumstatus', 'text', True),
('media', 'text', True),
('albumdisambig', 'text', True),
('albumartist', 'text', True),
('albumartist_sort', 'text', True),
('albumartist_credit', 'text', True, True),
('album', 'text', True),
('genre', 'text', True),
('year', 'int', True),
('month', 'int', True),
('day', 'int', True),
('tracktotal', 'int', True),
('disctotal', 'int', True),
('comp', 'bool', True),
('mb_albumid', 'text', True),
('mb_albumartistid', 'text', True),
('albumtype', 'text', True),
('label', 'text', True),
('mb_releasegroupid', 'text', True),
('asin', 'text', True),
('catalognum', 'text', True),
('script', 'text', True),
('language', 'text', True),
('country', 'text', True),
('albumstatus', 'text', True),
('media', 'text', True),
('albumdisambig', 'text', True),
]
ALBUM_KEYS = [f[0] for f in ALBUM_FIELDS]
ALBUM_KEYS_ITEM = [f[0] for f in ALBUM_FIELDS if f[2]]

View file

@ -15,6 +15,9 @@ Changelog
instead of a messy traceback. They still interrupt beets, but they should now
be easier for users to understand. Tracebacks are still available in verbose
mode.
* New metadata fields for `artist credits`_: ``artist_credit`` and
``albumartist_credit`` can now contain release- and recording-specific
variations of the artist's name. See :ref:`itemfields`.
* New plugin event: ``import_task_choice`` is called after an import task has an
action assigned.
* New plugin event: ``library_opened`` is called when beets starts up and
@ -30,6 +33,8 @@ Changelog
* :doc:`/plugins/chroma`: Fix occasional crash at end of fingerprint submission
and give more context to "failed fingerprint generation" errors.
.. _artist credits: http://wiki.musicbrainz.org/Artist_Credit
1.0b14 (May 12, 2012)
---------------------

View file

@ -158,10 +158,15 @@ Ordinary metadata:
* title
* artist
* artist_sort
* artist_sort: The "sort name" of the track artist (e.g., "Beatles, The" or
"White, Jack").
* artist_credit: The track-specific `artist credit`_ name, which may be a
variation of the artist's "canonical" name.
* album
* albumartist
* albumartist: The artist for the entire album, which may be different from the
artists for the individual tracks.
* albumartist_sort
* albumartist_credit
* genre
* composer
* grouping
@ -175,9 +180,9 @@ Ordinary metadata:
* lyrics
* comments
* bpm
* comp
* albumtype (the MusicBrainz album type; the MusicBrainz wiki has a `list of
type names`_)
* comp: Compilation flag.
* albumtype: The MusicBrainz album type; the MusicBrainz wiki has a `list of
type names`_.
* label
* asin
* catalognum
@ -190,6 +195,7 @@ Ordinary metadata:
* disctitle
* encoder
.. _artist credit: http://wiki.musicbrainz.org/Artist_Credit
.. _list of type names: http://wiki.musicbrainz.org/XMLWebService#Release_Type_and_Status
Audio information:

Binary file not shown.

View file

@ -466,9 +466,11 @@ class ApplyTest(unittest.TestCase):
self.items.append(Item({}))
self.items.append(Item({}))
trackinfo = []
trackinfo.append(TrackInfo('oneNew',
'dfa939ec-118c-4d0f-84a0-60f3d1e6522c',
medium=1, medium_index=1))
trackinfo.append(TrackInfo(
'oneNew', 'dfa939ec-118c-4d0f-84a0-60f3d1e6522c', medium=1,
medium_index=1, artist_credit='trackArtistCredit',
artist_sort='trackArtistSort',
))
trackinfo.append(TrackInfo('twoNew',
'40130ed1-a27c-42fd-a328-1ebefb6caef4',
medium=2, medium_index=1))
@ -478,6 +480,8 @@ class ApplyTest(unittest.TestCase):
album = 'albumNew',
album_id = '7edb51cb-77d6-4416-a23c-3a8c2994a2c7',
artist_id = 'a6623d39-2d8e-4f70-8242-0a9553b91e50',
artist_credit = 'albumArtistCredit',
artist_sort = 'albumArtistSort',
albumtype = 'album',
va = False,
mediums = 2,
@ -555,6 +559,20 @@ class ApplyTest(unittest.TestCase):
self.assertEqual(self.items[0].artist, 'artist1!')
self.assertEqual(self.items[1].artist, 'artist2!')
def test_artist_credit_applied(self):
autotag.apply_metadata(self.items, self.info)
self.assertEqual(self.items[0].albumartist_credit, 'albumArtistCredit')
self.assertEqual(self.items[0].artist_credit, 'trackArtistCredit')
self.assertEqual(self.items[1].albumartist_credit, 'albumArtistCredit')
self.assertEqual(self.items[1].artist_credit, 'albumArtistCredit')
def test_artist_sort_applied(self):
autotag.apply_metadata(self.items, self.info)
self.assertEqual(self.items[0].albumartist_sort, 'albumArtistSort')
self.assertEqual(self.items[0].artist_sort, 'trackArtistSort')
self.assertEqual(self.items[1].albumartist_sort, 'albumArtistSort')
self.assertEqual(self.items[1].artist_sort, 'albumArtistSort')
class ApplyCompilationTest(unittest.TestCase):
def setUp(self):
self.items = []