From 8eac98585d817aef8803b7a7c4bbc36f684b6752 Mon Sep 17 00:00:00 2001 From: Aidan Epstein Date: Tue, 7 Sep 2021 20:49:05 -0700 Subject: [PATCH] Get genres from both musicbrainz releases and release-groups. This adds the votes from each. This also changes the behavior to reset tags if the genre option is enabled and no tags are received from musicbrainz. This also sorts genres by the number of votes. --- beets/autotag/mb.py | 15 ++++++++++++--- docs/changelog.rst | 6 ++++++ docs/reference/config.rst | 7 ++++--- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 3e0658317..122723db5 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -20,6 +20,7 @@ from __future__ import division, absolute_import, print_function import musicbrainzngs import re import traceback +from collections import Counter from six.moves.urllib.parse import urljoin from beets import logging @@ -458,9 +459,17 @@ def album_info(release): first_medium = release['medium-list'][0] info.media = first_medium.get('format') - genres = release.get('genre-list') - if config['musicbrainz']['genres'] and genres: - info.genre = ';'.join(g['name'] for g in genres) + if config['musicbrainz']['genres']: + sources = [ + release['release-group'].get('genre-list', []), + release.get('genre-list', []), + ] + genres = Counter() + for source in sources: + for genreitem in source: + genres[genreitem['name']] += int(genreitem['count']) + info.genre = '; '.join(g[0] for g in sorted(genres.items(), + key=lambda g: -g[1])) extra_albumdatas = plugins.send('mb_album_extract', data=release) for extra_albumdata in extra_albumdatas: diff --git a/docs/changelog.rst b/docs/changelog.rst index b438e29ec..c02fe455c 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -14,6 +14,12 @@ For packagers: be necessary. :bug:`4037` :bug:`4038` +Major new features: + +* Include the genre tags from the release group when the musicbrainz genre + option is set, and sort them by the number of votes. Thanks to + :user:`aereaux`. + 1.5.0 (August 19, 2021) ----------------------- diff --git a/docs/reference/config.rst b/docs/reference/config.rst index aabe732c2..f300bd982 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -753,9 +753,10 @@ Default: ``[]`` genres ~~~~~~ -Use MusicBrainz genre tags to populate the ``genre`` tag. This will make it a -semicolon-separated list of all the genres tagged for the release on -MusicBrainz. +Use MusicBrainz genre tags to populate (and replace if it's already set) the +``genre`` tag. This will make it a list of all the genres tagged for the +release and the release-group on MusicBrainz, separated by "; " and sorted by +the total number of votes. Default: ``no``