From 93c8950bf40dc40278e3c2aa4cbffd9cb2aab591 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Thu, 2 Oct 2025 08:24:01 -0400 Subject: [PATCH 1/6] =?UTF-8?q?Extends=20the=20importer=E2=80=99s=20?= =?UTF-8?q?=E2=80=9Cfresh=20on=20reimport=E2=80=9D=20lists=20so=20album=20?= =?UTF-8?q?flex=20metadata=20from=20new=20releases=20replaces=20stale=20va?= =?UTF-8?q?lues?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beetsplug/musicbrainz.py | 23 ++++++++++++++++++++++- docs/changelog.rst | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/beetsplug/musicbrainz.py b/beetsplug/musicbrainz.py index 8e259e94b..772972c07 100644 --- a/beetsplug/musicbrainz.py +++ b/beetsplug/musicbrainz.py @@ -29,7 +29,7 @@ from confuse.exceptions import NotFoundError import beets import beets.autotag.hooks -from beets import config, plugins, util +from beets import config, importer, plugins, util from beets.metadata_plugins import MetadataSourcePlugin from beets.util.id_extractors import extract_release_id @@ -55,6 +55,26 @@ FIELDS_TO_MB_KEYS = { "year": "date", } +_MB_REIMPORT_FRESH_FIELDS_ALBUM = [ + "media", + "releasegroup_id", + "data_url", +] +_MB_REIMPORT_FRESH_FIELDS_ITEM = [ + "data_url", +] + + +def _extend_reimport_fresh_fields() -> None: + """Ensure MusicBrainz fields stored as flex attrs refresh on reimport.""" + for field in _MB_REIMPORT_FRESH_FIELDS_ALBUM: + if field not in importer.REIMPORT_FRESH_FIELDS_ALBUM: + importer.REIMPORT_FRESH_FIELDS_ALBUM.append(field) + for field in _MB_REIMPORT_FRESH_FIELDS_ITEM: + if field not in importer.REIMPORT_FRESH_FIELDS_ITEM: + importer.REIMPORT_FRESH_FIELDS_ITEM.append(field) + + musicbrainzngs.set_useragent("beets", beets.__version__, "https://beets.io/") @@ -367,6 +387,7 @@ class MusicBrainzPlugin(MetadataSourcePlugin): from the beets configuration. This should be called at startup. """ super().__init__() + _extend_reimport_fresh_fields() self.config.add( { "host": "musicbrainz.org", diff --git a/docs/changelog.rst b/docs/changelog.rst index e74f0caa2..74093596e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -19,6 +19,8 @@ New features: Bug fixes: +- :doc:`plugins/musicbrainz` Refresh flexible MusicBrainz metadata on reimport + so format changes are applied. :bug:`6036` - :doc:`plugins/spotify` Ensure ``spotifysync`` keeps popularity, ISRC, and related fields current even when audio features requests fail. :bug:`6061` - :doc:`plugins/spotify` Fixed an issue where track matching and lookups could From 20820fdb14d9c469307c9bc809c9792182df0f50 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Thu, 2 Oct 2025 08:31:30 -0400 Subject: [PATCH 2/6] update imports --- beetsplug/musicbrainz.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/beetsplug/musicbrainz.py b/beetsplug/musicbrainz.py index 772972c07..c4f252e33 100644 --- a/beetsplug/musicbrainz.py +++ b/beetsplug/musicbrainz.py @@ -29,7 +29,11 @@ from confuse.exceptions import NotFoundError import beets import beets.autotag.hooks -from beets import config, importer, plugins, util +from beets import config, plugins, util +from beets.importer.tasks import ( + REIMPORT_FRESH_FIELDS_ALBUM, + REIMPORT_FRESH_FIELDS_ITEM, +) from beets.metadata_plugins import MetadataSourcePlugin from beets.util.id_extractors import extract_release_id @@ -68,11 +72,11 @@ _MB_REIMPORT_FRESH_FIELDS_ITEM = [ def _extend_reimport_fresh_fields() -> None: """Ensure MusicBrainz fields stored as flex attrs refresh on reimport.""" for field in _MB_REIMPORT_FRESH_FIELDS_ALBUM: - if field not in importer.REIMPORT_FRESH_FIELDS_ALBUM: - importer.REIMPORT_FRESH_FIELDS_ALBUM.append(field) + if field not in REIMPORT_FRESH_FIELDS_ALBUM: + REIMPORT_FRESH_FIELDS_ALBUM.append(field) for field in _MB_REIMPORT_FRESH_FIELDS_ITEM: - if field not in importer.REIMPORT_FRESH_FIELDS_ITEM: - importer.REIMPORT_FRESH_FIELDS_ITEM.append(field) + if field not in REIMPORT_FRESH_FIELDS_ITEM: + REIMPORT_FRESH_FIELDS_ITEM.append(field) musicbrainzngs.set_useragent("beets", beets.__version__, "https://beets.io/") From c5f5ffc027cc40d02266e4c206eebfe3db9b39fe Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Mon, 6 Oct 2025 10:55:49 -0400 Subject: [PATCH 3/6] Added releasegroup_id to _MB_REIMPORT_FRESH_FIELDS_ITEM list --- beetsplug/musicbrainz.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beetsplug/musicbrainz.py b/beetsplug/musicbrainz.py index c4f252e33..5d7c415ef 100644 --- a/beetsplug/musicbrainz.py +++ b/beetsplug/musicbrainz.py @@ -66,6 +66,7 @@ _MB_REIMPORT_FRESH_FIELDS_ALBUM = [ ] _MB_REIMPORT_FRESH_FIELDS_ITEM = [ "data_url", + "releasegroup_id", ] From c59aff9e270fa536f26f10680bd6521110a1087c Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 7 Oct 2025 18:02:04 -0400 Subject: [PATCH 4/6] Added the MusicBrainz flex fields directly to the importer --- beets/importer/tasks.py | 7 ++++++- beetsplug/musicbrainz.py | 26 -------------------------- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/beets/importer/tasks.py b/beets/importer/tasks.py index b4d566032..9830a62cc 100644 --- a/beets/importer/tasks.py +++ b/beets/importer/tasks.py @@ -58,8 +58,13 @@ REIMPORT_FRESH_FIELDS_ALBUM = [ "deezer_album_id", "beatport_album_id", "tidal_album_id", + "media", + "releasegroup_id", + "data_url", +] +REIMPORT_FRESH_FIELDS_ITEM = [ + field for field in REIMPORT_FRESH_FIELDS_ALBUM if field != "media" ] -REIMPORT_FRESH_FIELDS_ITEM = list(REIMPORT_FRESH_FIELDS_ALBUM) # Global logger. log = logging.getLogger("beets") diff --git a/beetsplug/musicbrainz.py b/beetsplug/musicbrainz.py index 5d7c415ef..8e259e94b 100644 --- a/beetsplug/musicbrainz.py +++ b/beetsplug/musicbrainz.py @@ -30,10 +30,6 @@ from confuse.exceptions import NotFoundError import beets import beets.autotag.hooks from beets import config, plugins, util -from beets.importer.tasks import ( - REIMPORT_FRESH_FIELDS_ALBUM, - REIMPORT_FRESH_FIELDS_ITEM, -) from beets.metadata_plugins import MetadataSourcePlugin from beets.util.id_extractors import extract_release_id @@ -59,27 +55,6 @@ FIELDS_TO_MB_KEYS = { "year": "date", } -_MB_REIMPORT_FRESH_FIELDS_ALBUM = [ - "media", - "releasegroup_id", - "data_url", -] -_MB_REIMPORT_FRESH_FIELDS_ITEM = [ - "data_url", - "releasegroup_id", -] - - -def _extend_reimport_fresh_fields() -> None: - """Ensure MusicBrainz fields stored as flex attrs refresh on reimport.""" - for field in _MB_REIMPORT_FRESH_FIELDS_ALBUM: - if field not in REIMPORT_FRESH_FIELDS_ALBUM: - REIMPORT_FRESH_FIELDS_ALBUM.append(field) - for field in _MB_REIMPORT_FRESH_FIELDS_ITEM: - if field not in REIMPORT_FRESH_FIELDS_ITEM: - REIMPORT_FRESH_FIELDS_ITEM.append(field) - - musicbrainzngs.set_useragent("beets", beets.__version__, "https://beets.io/") @@ -392,7 +367,6 @@ class MusicBrainzPlugin(MetadataSourcePlugin): from the beets configuration. This should be called at startup. """ super().__init__() - _extend_reimport_fresh_fields() self.config.add( { "host": "musicbrainz.org", From 87874952fad7ab096c236614e7fb10fa96e56943 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Tue, 7 Oct 2025 19:56:39 -0400 Subject: [PATCH 5/6] Refactor reimport fresh fields: consolidate REIMPORT_FRESH_FIELDS_ITEM and REIMPORT_FRESH_FIELDS_ALBUM definitions --- beets/importer/tasks.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/beets/importer/tasks.py b/beets/importer/tasks.py index 9830a62cc..922026c08 100644 --- a/beets/importer/tasks.py +++ b/beets/importer/tasks.py @@ -51,20 +51,17 @@ SINGLE_ARTIST_THRESH = 0.25 # def extend_reimport_fresh_fields_item(): # importer.REIMPORT_FRESH_FIELDS_ITEM.extend(['tidal_track_popularity'] # ) -REIMPORT_FRESH_FIELDS_ALBUM = [ +REIMPORT_FRESH_FIELDS_ITEM = [ "data_source", "bandcamp_album_id", "spotify_album_id", "deezer_album_id", "beatport_album_id", "tidal_album_id", - "media", "releasegroup_id", "data_url", ] -REIMPORT_FRESH_FIELDS_ITEM = [ - field for field in REIMPORT_FRESH_FIELDS_ALBUM if field != "media" -] +REIMPORT_FRESH_FIELDS_ALBUM = [*REIMPORT_FRESH_FIELDS_ITEM, "media"] # Global logger. log = logging.getLogger("beets") From 92a2233e0d05481d0224956e452b3806b8f2e450 Mon Sep 17 00:00:00 2001 From: Alok Saboo Date: Wed, 8 Oct 2025 09:59:07 -0400 Subject: [PATCH 6/6] remove releasegroup_id --- beets/importer/tasks.py | 1 - 1 file changed, 1 deletion(-) diff --git a/beets/importer/tasks.py b/beets/importer/tasks.py index 922026c08..710f4da50 100644 --- a/beets/importer/tasks.py +++ b/beets/importer/tasks.py @@ -58,7 +58,6 @@ REIMPORT_FRESH_FIELDS_ITEM = [ "deezer_album_id", "beatport_album_id", "tidal_album_id", - "releasegroup_id", "data_url", ] REIMPORT_FRESH_FIELDS_ALBUM = [*REIMPORT_FRESH_FIELDS_ITEM, "media"]