Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to optionally disable the musicbrainz metadata source #4319

Merged
merged 10 commits into from
Mar 23, 2022

Conversation

snejus
Copy link
Member

@snejus snejus commented Mar 15, 2022

Description

Fixes #400.
Related to #2686

As I mentioned in #400 (comment), this adds a patch that allows to disable the MusicBrainz metadata source during the import process.

I had a little go at making the MusicBrainz Options section in the docs a little bit more consistent, and copied over the entire default config section for clarity.

To Do

  • Documentation. (If you've add a new command-line flag, for example, find the appropriate page under docs/ to describe it.)
  • Changelog. (Add an entry to docs/changelog.rst near the top of the document.)
  • Tests. (Encouraged but not strictly required.)

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome; thanks for getting this started! I actually think that it might be a little cleaner to handle this disabling in the beets.autotag.hooks module, which is the "dispatcher" that aggregates results from multiple sources. For example, this is the line that asks MB for matches:

yield from mb.match_album(artist, album, len(items),

Maybe it would make a little more sense to skip those calls there, rather than having them all return None?

@@ -482,6 +482,9 @@ def match_album(artist, album, tracks=None, extra_tags=None):
The query consists of an artist name, an album name, and,
optionally, a number of tracks on the album and any other extra tags.
"""
if not config["musicbrainz"]["enabled"].get(bool):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The .get(bool) bit here is actually unnecessary; using this in an if does that automatically.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's helpful, thanks!

@@ -716,6 +716,39 @@ Default: ``{}`` (empty).
MusicBrainz Options
-------------------

Default configuration::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for my own sanity, could we keep this PR's docs changes focused on the new option? Some refactoring, reordering, and adding examples would be nice too, but it will be easier to think about in a separate PR. Thank you!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, I'll move them out to another branch!

@snejus
Copy link
Member Author

snejus commented Mar 17, 2022

I do agree, will add the logic to hooks.py in a second.

@snejus
Copy link
Member Author

snejus commented Mar 18, 2022

It did end up being cleaner once the error handling logic got abstracted away.

@snejus snejus requested a review from sampsyo March 18, 2022 05:25
Comment on lines 624 to 625
if artist and album:
try:
yield from mb.match_album(artist, album, len(items),
extra_tags)
except mb.MusicBrainzAPIError as exc:
exc.log(log)
yield from handle_exc(mb.match_album, artist, *common_args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, this pattern would be much more readable as

    if artist and album and config["musicbrainz"]["enabled"]:
        yield from handle_exc(mb.match_album, artist, *common_args)

with the check for MB being enabled removed from handle_exc. This would separate exception handling and checking whether to query musicbrainz somewhat more cleanly.

If not going this way, renaming handle_exc -> invoke_mb or similar would also help.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, @wisp3rwind. I've just renamed the function to invoke_mb

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice; looking good overall! I have a few low-level suggestions.

Comment on lines 602 to 603
if not config["musicbrainz"]["enabled"]:
return ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do sort of like @wisp3rwind's suggestion to consider moving this out of the invoke_mb utility—it might make it a little clearer what's going on!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm also fine with the current version (renamed to invoke_mb); I was mostly concerned about handle_exc being actively misleading since it does more than handling exceptions. So, from my side, I'd say it's up to you @snejus which variant you prefer.

try:
return call_func(*args)
except mb.MusicBrainzAPIError as exc:
exc.log(log)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might cause a crash when an exception occurs. Namely, it seems like this function needs to return an iterable, right? So I think this exception handler should probably return () or similar…

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Yes, I'd suspect the same.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well caught! Fixed in e1ffadb

@@ -609,25 +619,17 @@ def album_candidates(items, artist, album, va_likely, extra_tags):
constrain the search.
"""

common_args = [album, len(items), extra_tags]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this might be bikeshedding, but I actually think the repetition (passing the same set of arguments to the two calls to mb.match_album) is a little more intelligible.

Copy link
Member Author

@snejus snejus Mar 23, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I must admit I sometimes treat the maximum line length a bit too religiously and adjust the code accordingly ... in unconventional ways 😆

@@ -609,25 +619,17 @@ def album_candidates(items, artist, album, va_likely, extra_tags):
constrain the search.
"""

common_args = [album, len(items), extra_tags]
# Base candidates if we have album and artist to match.
if artist and album:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This stanza and the next could share a single if config["musicbrainz"]["enabled"]:.

Comment on lines 719 to 728
.. _musicbrainz.enabled:

enabled
~~~~~~~

This option allows you to disable using MusicBrainz as a metadata source. This applies
if you use plugins that fetch data from alternative sources and should make the import
process quicker.

Default: ``yes``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this documentation stuff might be out of order—it makes the "top-level" description below appear to be part of the "enabled" subsection. I think this should appear among the other subsections below (which start with "searchlimit").

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree - have moved it below.

Copy link
Member

@sampsyo sampsyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me; thank you for your attention to detail here! 😃

@sampsyo sampsyo merged commit 6e142ef into beetbox:master Mar 23, 2022
@snejus snejus deleted the disable-musicbrainz-plugin branch March 24, 2022 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optionally disable the MusicBrainz data source
3 participants