From 2781ab1e9c8a39b78c3b15066c8269927611d1fe Mon Sep 17 00:00:00 2001 From: soergeld Date: Sat, 9 Jan 2021 16:47:34 +0100 Subject: [PATCH 1/7] add new hook for tags --- beets/autotag/mb.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 03ea5b382..a16cfb3e6 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 @@ -259,6 +260,12 @@ def track_info(recording, index=None, medium=None, medium_index=None, if arranger: info.arranger = u', '.join(arranger) + # supplementary tags provided by plugins + extra_trackdatas = plugins.send('extracting_trackdata', info=recording) + for extra_trackdata in extra_trackdatas: + for key in extra_trackdata: + info[key] = extra_trackdata[key] + info.decode() return info @@ -447,6 +454,12 @@ def album_info(release): if config['musicbrainz']['genres'] and genres: info.genre = ';'.join(g['name'] for g in genres) + # supplementary tags provided by plugins + extra_albumdatas = plugins.send('extracting_albumdata', info=release) + for extra_albumdata in extra_albumdatas: + for key in extra_albumdata: + info[key] = extra_albumdata[key] + info.decode() return info From 79e5b89caf18a577f922780468f0286260fd9fad Mon Sep 17 00:00:00 2001 From: soergeld Date: Sat, 9 Jan 2021 16:54:14 +0100 Subject: [PATCH 2/7] documentation and changelog --- docs/changelog.rst | 7 ++++--- docs/dev/plugins.rst | 5 +++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 0fb503f80..2054f1daf 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -94,7 +94,7 @@ New features: Windows. Thanks to :user:`MartyLake`. :bug:`3331` :bug:`3334` -* The 'data_source' field is now also applied as an album-level flexible +* The ``data_source`` field is now also applied as an album-level flexible attribute during imports, allowing for more refined album level searches. :bug:`3350` :bug:`1693` * :doc:`/plugins/deezer`: Added Deezer plugin as an import metadata provider: @@ -173,7 +173,8 @@ New features: * :doc:`/plugins/replaygain` now does its analysis in parallel when using the ``command``, ``ffmpeg`` or ``bs1770gain`` backends. :bug:`3478` - +* Add ``extracting_albumdata`` and ``extracting_trackdata`` hooks to allow + plugins to add new fields based on MusicBrainz data. Thanks to :user:`dosoe`. Fixes: * :bug:`/plugins/discogs`: Fixed a bug with ``index_tracks`` options that @@ -1929,7 +1930,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 a6aa3d6d7..40a1f38a9 100644 --- a/docs/dev/plugins.rst +++ b/docs/dev/plugins.rst @@ -238,6 +238,11 @@ 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``. + +* `extracting_trackdata` and `extracting_albumdata`: called after the metadata + is obtained from MusicBrainz. The parameter is a ``dict`` containing the data + retrieved from MusicBrainz for a track or an album. + Allows to add additional tags. The included ``mpdupdate`` plugin provides an example use case for event listeners. From 93ebb9816dce06d7188884ff43d3898b46c4cfe4 Mon Sep 17 00:00:00 2001 From: soergeld Date: Sat, 9 Jan 2021 16:58:35 +0100 Subject: [PATCH 3/7] style --- docs/changelog.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index 2054f1daf..0caf9fd38 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -175,6 +175,7 @@ New features: :bug:`3478` * Add ``extracting_albumdata`` and ``extracting_trackdata`` hooks to allow plugins to add new fields based on MusicBrainz data. Thanks to :user:`dosoe`. + Fixes: * :bug:`/plugins/discogs`: Fixed a bug with ``index_tracks`` options that From 00b08d52d596f1b4a9280ac1efaf3b84f123debf Mon Sep 17 00:00:00 2001 From: Dorian Date: Sat, 6 Feb 2021 15:07:10 +0100 Subject: [PATCH 4/7] style following review --- beets/autotag/mb.py | 13 +++++-------- docs/dev/plugins.rst | 10 +++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index a16cfb3e6..8f2cbeb92 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -260,11 +260,10 @@ def track_info(recording, index=None, medium=None, medium_index=None, if arranger: info.arranger = u', '.join(arranger) - # supplementary tags provided by plugins - extra_trackdatas = plugins.send('extracting_trackdata', info=recording) + # supplementary fields provided by plugins + extra_trackdatas = plugins.send('mb_track_extract', data=recording) for extra_trackdata in extra_trackdatas: - for key in extra_trackdata: - info[key] = extra_trackdata[key] + info.update(extra_trackdata) info.decode() return info @@ -454,11 +453,9 @@ def album_info(release): if config['musicbrainz']['genres'] and genres: info.genre = ';'.join(g['name'] for g in genres) - # supplementary tags provided by plugins - extra_albumdatas = plugins.send('extracting_albumdata', info=release) + extra_albumdatas = plugins.send('mb_album_extract', data=release) for extra_albumdata in extra_albumdatas: - for key in extra_albumdata: - info[key] = extra_albumdata[key] + info.update(extra_albumdata) info.decode() return info diff --git a/docs/dev/plugins.rst b/docs/dev/plugins.rst index 40a1f38a9..4ce2a6bdb 100644 --- a/docs/dev/plugins.rst +++ b/docs/dev/plugins.rst @@ -239,10 +239,14 @@ The events currently available are: :ref:`appending choices to the prompt ` by returning a list of ``PromptChoices``. Parameters: ``task`` and ``session``. -* `extracting_trackdata` and `extracting_albumdata`: called after the metadata - is obtained from MusicBrainz. The parameter is a ``dict`` containing the data - retrieved from MusicBrainz for a track or an album. +* `mb_track_extract`: called after the metadata is obtained from + MusicBrainz. The parameter is a ``dict`` containing the data + retrieved from MusicBrainz for a track. Allows to add additional tags. + Parameter: ``data`` + +* `mb_album_extract`: Like `mb_track_extract`, but for album tags. + Parameter: ``data`` The included ``mpdupdate`` plugin provides an example use case for event listeners. From 9a5ba4ee3b871864afdba6d3a66beca3bc411b48 Mon Sep 17 00:00:00 2001 From: Dorian Date: Sat, 6 Feb 2021 16:01:36 +0100 Subject: [PATCH 5/7] typo --- beets/autotag/mb.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 8f2cbeb92..dfd3a9c81 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -260,7 +260,7 @@ def track_info(recording, index=None, medium=None, medium_index=None, if arranger: info.arranger = u', '.join(arranger) - # supplementary fields provided by plugins + # Supplementary fields provided by plugins extra_trackdatas = plugins.send('mb_track_extract', data=recording) for extra_trackdata in extra_trackdatas: info.update(extra_trackdata) From 64238ca8c61392436ca56352f353fcde1f139c45 Mon Sep 17 00:00:00 2001 From: Dorian Date: Tue, 11 May 2021 10:44:33 +0200 Subject: [PATCH 6/7] complete documentation --- docs/dev/plugins.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/dev/plugins.rst b/docs/dev/plugins.rst index 4ce2a6bdb..1f026bd4a 100644 --- a/docs/dev/plugins.rst +++ b/docs/dev/plugins.rst @@ -241,7 +241,7 @@ The events currently available are: * `mb_track_extract`: called after the metadata is obtained from MusicBrainz. The parameter is a ``dict`` containing the data - retrieved from MusicBrainz for a track. + retrieved from MusicBrainz for a track in the form ``field : value`` Allows to add additional tags. Parameter: ``data`` From c64fc68b16c223068b523cd46c8103ffb531f405 Mon Sep 17 00:00:00 2001 From: Dorian Date: Tue, 11 May 2021 22:17:38 +0200 Subject: [PATCH 7/7] more detailed documentation --- docs/dev/plugins.rst | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/docs/dev/plugins.rst b/docs/dev/plugins.rst index e7462c81e..b32955b61 100644 --- a/docs/dev/plugins.rst +++ b/docs/dev/plugins.rst @@ -247,12 +247,15 @@ The events currently available are: 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 data - retrieved from MusicBrainz for a track in the form ``field : value`` - Allows to add additional tags. + 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. +* `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.