Skip to content

Commit e348566

Browse files
committed
Allow selecting either tags or genres in the includes, defaulting to genres
Genres is a filtered list based on what musicbrainz considers a genre, tags are all the user-submitted tags. [1] 1. https://musicbrainz.org/doc/MusicBrainz_API#:~:text=Since%20genres%20are,!).
1 parent bde5de4 commit e348566

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

beetsplug/musicbrainz.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def get_message(self):
8989
"isrcs",
9090
"url-rels",
9191
"release-rels",
92+
"genres",
9293
"tags",
9394
}
9495
& set(musicbrainzngs.VALID_INCLUDES["release"])
@@ -395,6 +396,17 @@ def __init__(self):
395396
self.config["ratelimit_interval"].as_number(),
396397
self.config["ratelimit"].get(int),
397398
)
399+
genres_config = config["musicbrainz"]["genres"]
400+
if genres_config:
401+
genres_config = genres_config.get(str)
402+
if genres_config == "genres":
403+
self.genre_or_tag = "genre"
404+
elif genres_config == "tags":
405+
self.genre_or_tag = "tag"
406+
else:
407+
self.genre_or_tag = "genre"
408+
else:
409+
self.genre_or_tag = False
398410

399411
def track_info(
400412
self,
@@ -705,10 +717,10 @@ def album_info(self, release: JSONDict) -> beets.autotag.hooks.AlbumInfo:
705717
else:
706718
info.media = "Media"
707719

708-
if self.config["genres"]:
720+
if self.genre_or_tag:
709721
sources = [
710-
release["release-group"].get("tag-list", []),
711-
release.get("tag-list", []),
722+
release["release-group"].get(self.genre_or_tag + "-list", []),
723+
release.get(self.genre_or_tag + "-list", []),
712724
]
713725
genres: Counter[str] = Counter()
714726
for source in sources:

docs/changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ New features:
3333
* :doc:`plugins/mpdstats`: Add new configuration option,
3434
``played_ratio_threshold``, to allow configuring the percentage the song must
3535
be played for it to be counted as played instead of skipped.
36+
* :doc:`plugins/musicbrainz`: Allow selecting tags or genres to populate the genres tag.
3637

3738
Bug fixes:
3839

docs/plugins/musicbrainz.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ genres
120120
Use MusicBrainz genre tags to populate (and replace if it's already set) the
121121
``genre`` tag. This will make it a list of all the genres tagged for the
122122
release and the release-group on MusicBrainz, separated by "; " and sorted by
123-
the total number of votes.
123+
the total number of votes. Specify "genres" to use just musicbrainz genres and
124+
"tags" to use all user-supplied musicbrainz tags.
124125
Default: ``no``
125126

126127
.. _musicbrainz.external_ids:

0 commit comments

Comments
 (0)