From 0202d762bf51d0861a2f9970fa6f5df3d807c2d2 Mon Sep 17 00:00:00 2001 From: Denis Defreyne Date: Sat, 7 Apr 2018 22:20:48 +0200 Subject: [PATCH] Add artist_credit config option --- beets/autotag/__init__.py | 17 ++++++++++++----- beets/config_default.yaml | 1 + docs/changelog.rst | 7 +++++-- docs/reference/config.rst | 9 +++++++++ test/test_autotag.py | 21 ++++++++++++++++++++- 5 files changed, 47 insertions(+), 8 deletions(-) diff --git a/beets/autotag/__init__.py b/beets/autotag/__init__.py index 4c5f09eb4..09564f49d 100644 --- a/beets/autotag/__init__.py +++ b/beets/autotag/__init__.py @@ -63,12 +63,19 @@ def apply_metadata(album_info, mapping): mapping from Items to TrackInfo objects. """ for item, track_info in mapping.items(): - # Album, artist, track count. - if track_info.artist: - item.artist = track_info.artist + # Artist or artist credit. + if config['artist_credit']: + item.artist = (track_info.artist_credit or + track_info.artist or + album_info.artist_credit or + album_info.artist) + item.albumartist = (album_info.artist_credit or + album_info.artist) else: - item.artist = album_info.artist - item.albumartist = album_info.artist + item.artist = (track_info.artist or album_info.artist) + item.albumartist = album_info.artist + + # Album. item.album = album_info.album # Artist sort and credit names. diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 27aa3d4ca..273f94235 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -56,6 +56,7 @@ per_disc_numbering: no verbose: 0 terminal_encoding: original_date: no +artist_credit: no id3v23: no va_name: "Various Artists" diff --git a/docs/changelog.rst b/docs/changelog.rst index aa930904a..dd04b1d71 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -18,6 +18,9 @@ New features: * :doc:`/plugins/web`: added the boolean ``cors_supports_credentials`` option to allow in-browser clients to login to the beet web server even when it is protected by an authorization mechanism. +* A new importer configuration ``artist_credit`` will tell beets to prefer the + artist credit over the artist when autotagging. + :bug:`1249` Fixes: @@ -75,9 +78,9 @@ Fixes: album art would not work and throw an exception. It now works as expected. Additionally, the server will now return a 404 response when the album id is unknown, instead of a 500 response and a thrown exception. :bug:`2823` -* :doc:`/plugins/web`: In a python 3 enviroment, the server would throw an +* :doc:`/plugins/web`: In a python 3 enviroment, the server would throw an exception if non latin-1 characters where in the File name. - It now checks if non latin-1 characters are in the filename and changes + It now checks if non latin-1 characters are in the filename and changes them to ascii-characters in that case :bug:`2815` * Partially fix bash completion for subcommand names that contain hyphens. :bug:`2836` :bug:`2837` diff --git a/docs/reference/config.rst b/docs/reference/config.rst index 24ed1340d..94dab4345 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -253,6 +253,15 @@ Either ``yes`` or ``no``, indicating whether matched albums should have their That is, if this option is turned on, then ``year`` will always equal ``original_year`` and so on. Default: ``no``. +.. _artist_credit: + +artist_credit +~~~~~~~~~~~~~ + +Either ``yes`` or ``no``, indicating whether matched tracks and albums should +use the artist credit, rather than the artist. That is, if this option is turned +on, then ``artist`` will contain the artist as credited on the release. + .. _per_disc_numbering: per_disc_numbering diff --git a/test/test_autotag.py b/test/test_autotag.py index 6f107afa4..932616be1 100644 --- a/test/test_autotag.py +++ b/test/test_autotag.py @@ -616,12 +616,13 @@ class AssignmentTest(unittest.TestCase): class ApplyTestUtil(object): - def _apply(self, info=None, per_disc_numbering=False): + def _apply(self, info=None, per_disc_numbering=False, artist_credit=False): info = info or self.info mapping = {} for i, t in zip(self.items, info.tracks): mapping[i] = t config['per_disc_numbering'] = per_disc_numbering + config['artist_credit'] = artist_credit autotag.apply_metadata(info, mapping) @@ -706,6 +707,24 @@ class ApplyTest(_common.TestCase, ApplyTestUtil): self.assertEqual(self.items[0].tracktotal, 1) self.assertEqual(self.items[1].tracktotal, 1) + def test_artist_credit(self): + self._apply(artist_credit=True) + self.assertEqual(self.items[0].artist, 'trackArtistCredit') + self.assertEqual(self.items[1].artist, 'albumArtistCredit') + self.assertEqual(self.items[0].albumartist, 'albumArtistCredit') + self.assertEqual(self.items[1].albumartist, 'albumArtistCredit') + + def test_artist_credit_prefers_artist_over_albumartist_credit(self): + self.info.tracks[0].artist = 'oldArtist' + self.info.tracks[0].artist_credit = None + self._apply(artist_credit=True) + self.assertEqual(self.items[0].artist, 'oldArtist') + + def test_artist_credit_falls_back_to_albumartist(self): + self.info.artist_credit = None + self._apply(artist_credit=True) + self.assertEqual(self.items[1].artist, 'artistNew') + def test_mb_trackid_applied(self): self._apply() self.assertEqual(self.items[0].mb_trackid,