diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 0334cff1e..aad0fb1ba 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -23,6 +23,7 @@ import traceback from six.moves.urllib.parse import urljoin from beets import logging +from beets import plugins import beets.autotag.hooks import beets from beets import util @@ -265,6 +266,11 @@ def track_info(recording, index=None, medium=None, medium_index=None, if arranger: info.arranger = u', '.join(arranger) + # Supplementary fields provided by plugins + extra_trackdatas = plugins.send('mb_track_extract', data=recording) + for extra_trackdata in extra_trackdatas: + info.update(extra_trackdata) + info.decode() return info @@ -453,6 +459,10 @@ def album_info(release): if config['musicbrainz']['genres'] and genres: info.genre = ';'.join(g['name'] for g in genres) + extra_albumdatas = plugins.send('mb_album_extract', data=release) + for extra_albumdata in extra_albumdatas: + info.update(extra_albumdata) + info.decode() return info diff --git a/docs/changelog.rst b/docs/changelog.rst index b3447b936..224ec2da0 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -204,6 +204,8 @@ Other new things: configuration. Thanks to :user:`FichteFoll`. :bug:`2797` :bug:`2988` +* Add ``mb_album_extract`` and ``mb_track_extract`` hooks to allow + plugins to add new fields based on MusicBrainz data. Thanks to :user:`dosoe`. * Removes usage of the bs1770gain replaygain backend. Thanks to :user:`SamuelCook`. * Added ``trackdisambig`` which stores the recording disambiguation from @@ -2007,7 +2009,7 @@ Major new features and bigger changes: search results you wish to see when looking up releases at MusicBrainz during import. :bug:`1245` * The importer now records the data source for a match in a new - flexible attribute `data_source` on items and albums. :bug:`1311` + flexible attribute ``data_source`` on items and albums. :bug:`1311` * The colors used in the terminal interface are now configurable via the new config option ``colors``, nested under the option ``ui``. (Also, the `color` config option has been moved from top-level to under ``ui``. Beets will diff --git a/docs/dev/plugins.rst b/docs/dev/plugins.rst index d81461f4d..b32955b61 100644 --- a/docs/dev/plugins.rst +++ b/docs/dev/plugins.rst @@ -245,6 +245,18 @@ The events currently available are: during a ``beet import`` interactive session. Plugins can use this event for :ref:`appending choices to the prompt ` by returning a list of ``PromptChoices``. Parameters: ``task`` and ``session``. + +* `mb_track_extract`: called after the metadata is obtained from + MusicBrainz. The parameter is a ``dict`` containing the tags retrieved from + MusicBrainz for a track. Plugins must return a new (potentially empty) + ``dict`` with additional ``field: value`` pairs, which the autotagger will + apply to the item, as flexible attributes if ``field`` is not a hardcoded + field. Fields already present on the track are overwritten. + Parameter: ``data`` + +* `mb_album_extract`: Like `mb_track_extract`, but for album tags. Overwrites + tags set at the track level, if they have the same ``field``. + Parameter: ``data`` The included ``mpdupdate`` plugin provides an example use case for event listeners.