Merge pull request #4044 from aereaux/add_genres

Get genres from both musicbrainz releases and release-groups.
This commit is contained in:
Adrian Sampson 2021-09-09 07:12:29 -04:00 committed by GitHub
commit 410deb6c3b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 6 deletions

View file

@ -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:

View file

@ -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)
-----------------------

View file

@ -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``