From ffe63a64f5dc6724054e22dd88d4181068c5f4e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Sun, 13 Mar 2022 18:50:22 +0000 Subject: [PATCH 01/10] Nicely disable musicbrainz --- beets/autotag/mb.py | 9 +++++++++ beets/config_default.yaml | 1 + 2 files changed, 10 insertions(+) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index e6a2e277f..9a6a7e7f9 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -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): + return None + # Build search criteria. criteria = {'release': album.lower().strip()} if artist is not None: @@ -558,6 +561,9 @@ def album_for_id(releaseid): object or None if the album is not found. May raise a MusicBrainzAPIError. """ + if not config["musicbrainz"]["enabled"].get(bool): + return None + log.debug('Requesting MusicBrainz release {}', releaseid) albumid = _parse_id(releaseid) if not albumid: @@ -579,6 +585,9 @@ def track_for_id(releaseid): """Fetches a track by its MusicBrainz ID. Returns a TrackInfo object or None if no track is found. May raise a MusicBrainzAPIError. """ + if not config["musicbrainz"]["enabled"].get(bool): + return None + trackid = _parse_id(releaseid) if not trackid: log.debug('Invalid MBID ({0}).', releaseid) diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 74540891e..518e086a1 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -108,6 +108,7 @@ musicbrainz: searchlimit: 5 extra_tags: [] genres: no + enabled: yes match: strong_rec_thresh: 0.04 From 85c4310e47b0e5e4f34aa7c538f8fe68083bd5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Tue, 15 Mar 2022 21:56:33 +0000 Subject: [PATCH 02/10] Update docs --- beets/config_default.yaml | 2 +- docs/reference/config.rst | 59 ++++++++++++++++++++++++++++++++++----- 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/beets/config_default.yaml b/beets/config_default.yaml index 518e086a1..fd2dbf551 100644 --- a/beets/config_default.yaml +++ b/beets/config_default.yaml @@ -101,6 +101,7 @@ paths: statefile: state.pickle musicbrainz: + enabled: yes host: musicbrainz.org https: no ratelimit: 1 @@ -108,7 +109,6 @@ musicbrainz: searchlimit: 5 extra_tags: [] genres: no - enabled: yes match: strong_rec_thresh: 0.04 diff --git a/docs/reference/config.rst b/docs/reference/config.rst index 642216c8f..ae04ce525 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -716,6 +716,39 @@ Default: ``{}`` (empty). MusicBrainz Options ------------------- +Default configuration:: + + musicbrainz: + enabled: yes + host: musicbrainz.org + https: no + ratelimit: 1 + ratelimit_interval: 1.0 + searchlimit: 5 + extra_tags: [] + genres: no + +.. _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``. + +.. _host: + +host +~~~~ + +The ``host`` key, of course, controls the Web server hostname (and port, +optionally) that will be contacted by beets. + +Default: ``musicbrainz.org`` + You can instruct beets to use `your own MusicBrainz database`_ instead of the `main server`_. Use the ``host``, ``https`` and ``ratelimit`` options under a ``musicbrainz:`` header, like so:: @@ -725,16 +758,27 @@ under a ``musicbrainz:`` header, like so:: https: no ratelimit: 100 -The ``host`` key, of course, controls the Web server hostname (and port, -optionally) that will be contacted by beets (default: musicbrainz.org). +.. _https: + +https +~~~~~ + The ``https`` key makes the client use HTTPS instead of HTTP. This setting applies -only to custom servers. The official MusicBrainz server always uses HTTPS. (Default: no.) +only to custom servers. The official MusicBrainz server always uses HTTPS. The server must have search indices enabled (see `Building search indexes`_). -The ``ratelimit`` option, an integer, controls the number of Web service requests -per second (default: 1). **Do not change the rate limit setting** if you're -using the main MusicBrainz server---on this public server, you're `limited`_ -to one request per second. +Default: ``no`` + +.. _ratelimit and ratelimit_interval: + +ratelimit and ratelimit_interval +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +``ratelimit`` many requests will be sent per ``ratelimit_interval`` by the Web service. +**Do not change these settings** if you're using the main MusicBrainz +server - on this public server, you're `limited`_ to one request per second. + +Default: ``1`` and ``1.0`` .. _your own MusicBrainz database: https://musicbrainz.org/doc/MusicBrainz_Server/Setup .. _main server: https://musicbrainz.org/ @@ -780,6 +824,7 @@ 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`` .. _match-config: From f10b70444c47cd3e70395aaeda941e0633b10be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Tue, 15 Mar 2022 22:13:23 +0000 Subject: [PATCH 03/10] Add a changelog entry --- docs/changelog.rst | 2 ++ docs/reference/config.rst | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index bd3ee2841..002b96c5d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -8,6 +8,8 @@ Changelog goes here! New features: +* :ref:`musicbrainz-config`: a new :ref:`musicbrainz.enabled` option allows disabling + the MusicBrainz metadata source during the autotagging process * :doc:`/plugins/kodiupdate`: Now supports multiple kodi instances :bug:`4101` * Add the item fields ``bitrate_mode``, ``encoder_info`` and ``encoder_settings``. diff --git a/docs/reference/config.rst b/docs/reference/config.rst index ae04ce525..94ec61a72 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -728,7 +728,7 @@ Default configuration:: extra_tags: [] genres: no -.. _enabled: +.. _musicbrainz.enabled: enabled ~~~~~~~ From 6f23c9b41a31712c121f8b3c94247a0a7895d562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Fri, 18 Mar 2022 05:05:58 +0000 Subject: [PATCH 04/10] Move the logic to hooks.py --- beets/autotag/hooks.py | 31 +++++++++++++++---------------- beets/autotag/mb.py | 9 --------- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 9cd6f2cd8..4055596be 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -598,6 +598,16 @@ def tracks_for_id(track_id): yield t +def handle_exc(call_func, *args): + if not config["musicbrainz"]["enabled"]: + return () + + try: + return call_func(*args) + except mb.MusicBrainzAPIError as exc: + exc.log(log) + + @plugins.notify_info_yielded('albuminfo_received') def album_candidates(items, artist, album, va_likely, extra_tags): """Search for album matches. ``items`` is a list of Item objects @@ -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: - 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) # Also add VA matches from MusicBrainz where appropriate. if va_likely and album: - try: - yield from mb.match_album(None, album, len(items), - extra_tags) - except mb.MusicBrainzAPIError as exc: - exc.log(log) + yield from handle_exc(mb.match_album, None, *common_args) # Candidates from plugins. - yield from plugins.candidates(items, artist, album, va_likely, - extra_tags) + yield from plugins.candidates(items, artist, album, va_likely, extra_tags) @plugins.notify_info_yielded('trackinfo_received') @@ -639,10 +641,7 @@ def item_candidates(item, artist, title): # MusicBrainz candidates. if artist and title: - try: - yield from mb.match_track(artist, title) - except mb.MusicBrainzAPIError as exc: - exc.log(log) + yield from handle_exc(mb.match_track, artist, title) # Plugin candidates. yield from plugins.item_candidates(item, artist, title) diff --git a/beets/autotag/mb.py b/beets/autotag/mb.py index 9a6a7e7f9..e6a2e277f 100644 --- a/beets/autotag/mb.py +++ b/beets/autotag/mb.py @@ -482,9 +482,6 @@ 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): - return None - # Build search criteria. criteria = {'release': album.lower().strip()} if artist is not None: @@ -561,9 +558,6 @@ def album_for_id(releaseid): object or None if the album is not found. May raise a MusicBrainzAPIError. """ - if not config["musicbrainz"]["enabled"].get(bool): - return None - log.debug('Requesting MusicBrainz release {}', releaseid) albumid = _parse_id(releaseid) if not albumid: @@ -585,9 +579,6 @@ def track_for_id(releaseid): """Fetches a track by its MusicBrainz ID. Returns a TrackInfo object or None if no track is found. May raise a MusicBrainzAPIError. """ - if not config["musicbrainz"]["enabled"].get(bool): - return None - trackid = _parse_id(releaseid) if not trackid: log.debug('Invalid MBID ({0}).', releaseid) From 2193b3749bb65648d36aa662e1f9c4b6bda8b07f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Fri, 18 Mar 2022 05:13:06 +0000 Subject: [PATCH 05/10] Remove optional docs changes --- docs/reference/config.rst | 48 ++++++--------------------------------- 1 file changed, 7 insertions(+), 41 deletions(-) diff --git a/docs/reference/config.rst b/docs/reference/config.rst index 94ec61a72..aad9d4bdf 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -716,18 +716,6 @@ Default: ``{}`` (empty). MusicBrainz Options ------------------- -Default configuration:: - - musicbrainz: - enabled: yes - host: musicbrainz.org - https: no - ratelimit: 1 - ratelimit_interval: 1.0 - searchlimit: 5 - extra_tags: [] - genres: no - .. _musicbrainz.enabled: enabled @@ -739,16 +727,6 @@ process quicker. Default: ``yes``. -.. _host: - -host -~~~~ - -The ``host`` key, of course, controls the Web server hostname (and port, -optionally) that will be contacted by beets. - -Default: ``musicbrainz.org`` - You can instruct beets to use `your own MusicBrainz database`_ instead of the `main server`_. Use the ``host``, ``https`` and ``ratelimit`` options under a ``musicbrainz:`` header, like so:: @@ -758,27 +736,16 @@ under a ``musicbrainz:`` header, like so:: https: no ratelimit: 100 -.. _https: - -https -~~~~~ - +The ``host`` key, of course, controls the Web server hostname (and port, +optionally) that will be contacted by beets (default: musicbrainz.org). The ``https`` key makes the client use HTTPS instead of HTTP. This setting applies -only to custom servers. The official MusicBrainz server always uses HTTPS. +only to custom servers. The official MusicBrainz server always uses HTTPS. (Default: no.) The server must have search indices enabled (see `Building search indexes`_). -Default: ``no`` - -.. _ratelimit and ratelimit_interval: - -ratelimit and ratelimit_interval -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -``ratelimit`` many requests will be sent per ``ratelimit_interval`` by the Web service. -**Do not change these settings** if you're using the main MusicBrainz -server - on this public server, you're `limited`_ to one request per second. - -Default: ``1`` and ``1.0`` +The ``ratelimit`` option, an integer, controls the number of Web service requests +per second (default: 1). **Do not change the rate limit setting** if you're +using the main MusicBrainz server---on this public server, you're `limited`_ +to one request per second. .. _your own MusicBrainz database: https://musicbrainz.org/doc/MusicBrainz_Server/Setup .. _main server: https://musicbrainz.org/ @@ -824,7 +791,6 @@ 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`` .. _match-config: From f14eac857b91311b27bd3d934a3c87dbdd9b8fce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Fri, 18 Mar 2022 22:57:22 +0000 Subject: [PATCH 06/10] Rename handle_exc to invoke_mb --- beets/autotag/hooks.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 4055596be..a385699ac 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -598,7 +598,7 @@ def tracks_for_id(track_id): yield t -def handle_exc(call_func, *args): +def invoke_mb(call_func, *args): if not config["musicbrainz"]["enabled"]: return () @@ -622,11 +622,11 @@ def album_candidates(items, artist, album, va_likely, extra_tags): common_args = [album, len(items), extra_tags] # Base candidates if we have album and artist to match. if artist and album: - yield from handle_exc(mb.match_album, artist, *common_args) + yield from invoke_mb(mb.match_album, artist, *common_args) # Also add VA matches from MusicBrainz where appropriate. if va_likely and album: - yield from handle_exc(mb.match_album, None, *common_args) + yield from invoke_mb(mb.match_album, None, *common_args) # Candidates from plugins. yield from plugins.candidates(items, artist, album, va_likely, extra_tags) @@ -641,7 +641,7 @@ def item_candidates(item, artist, title): # MusicBrainz candidates. if artist and title: - yield from handle_exc(mb.match_track, artist, title) + yield from invoke_mb(mb.match_track, artist, title) # Plugin candidates. yield from plugins.item_candidates(item, artist, title) From e1ffadb2d6bbff8654c7bf593bda0dc40ac5f070 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Wed, 23 Mar 2022 16:20:06 +0000 Subject: [PATCH 07/10] Return iterable from the exception handler --- beets/autotag/hooks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index a385699ac..2f9e2135c 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -606,6 +606,7 @@ def invoke_mb(call_func, *args): return call_func(*args) except mb.MusicBrainzAPIError as exc: exc.log(log) + return () @plugins.notify_info_yielded('albuminfo_received') From e9972491f1e4d49cbabcaec258add299e6ea0efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Wed, 23 Mar 2022 16:34:13 +0000 Subject: [PATCH 08/10] Do not assign extra variable to keep things within max line_length --- beets/autotag/hooks.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 2f9e2135c..1811cbaf1 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -620,14 +620,15 @@ 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: - yield from invoke_mb(mb.match_album, artist, *common_args) + yield from invoke_mb(mb.match_album, artist, album, len(items), + extra_tags) # Also add VA matches from MusicBrainz where appropriate. if va_likely and album: - yield from invoke_mb(mb.match_album, None, *common_args) + yield from invoke_mb(mb.match_album, None, album, len(items), + extra_tags) # Candidates from plugins. yield from plugins.candidates(items, artist, album, va_likely, extra_tags) From a6e7105449ffc89a5cb463451527feafe93a7012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Wed, 23 Mar 2022 16:59:21 +0000 Subject: [PATCH 09/10] Move musicbrainz.enabled check out from invoke_mb --- beets/autotag/hooks.py | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/beets/autotag/hooks.py b/beets/autotag/hooks.py index 1811cbaf1..30904ff29 100644 --- a/beets/autotag/hooks.py +++ b/beets/autotag/hooks.py @@ -599,9 +599,6 @@ def tracks_for_id(track_id): def invoke_mb(call_func, *args): - if not config["musicbrainz"]["enabled"]: - return () - try: return call_func(*args) except mb.MusicBrainzAPIError as exc: @@ -620,15 +617,16 @@ def album_candidates(items, artist, album, va_likely, extra_tags): constrain the search. """ - # Base candidates if we have album and artist to match. - if artist and album: - yield from invoke_mb(mb.match_album, artist, album, len(items), - extra_tags) + if config["musicbrainz"]["enabled"]: + # Base candidates if we have album and artist to match. + if artist and album: + yield from invoke_mb(mb.match_album, artist, album, len(items), + extra_tags) - # Also add VA matches from MusicBrainz where appropriate. - if va_likely and album: - yield from invoke_mb(mb.match_album, None, album, len(items), - extra_tags) + # Also add VA matches from MusicBrainz where appropriate. + if va_likely and album: + yield from invoke_mb(mb.match_album, None, album, len(items), + extra_tags) # Candidates from plugins. yield from plugins.candidates(items, artist, album, va_likely, extra_tags) @@ -642,7 +640,7 @@ def item_candidates(item, artist, title): """ # MusicBrainz candidates. - if artist and title: + if config["musicbrainz"]["enabled"] and artist and title: yield from invoke_mb(mb.match_track, artist, title) # Plugin candidates. From 5d6f808d33492ef450dd835da6de109a8bf3b731 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Wed, 23 Mar 2022 17:02:45 +0000 Subject: [PATCH 10/10] Move musicbrainz.enabled section below network config in config.rst --- docs/reference/config.rst | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/docs/reference/config.rst b/docs/reference/config.rst index aad9d4bdf..6e7df1b59 100644 --- a/docs/reference/config.rst +++ b/docs/reference/config.rst @@ -716,17 +716,6 @@ Default: ``{}`` (empty). MusicBrainz Options ------------------- -.. _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``. - You can instruct beets to use `your own MusicBrainz database`_ instead of the `main server`_. Use the ``host``, ``https`` and ``ratelimit`` options under a ``musicbrainz:`` header, like so:: @@ -752,6 +741,17 @@ to one request per second. .. _limited: https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting .. _Building search indexes: https://musicbrainz.org/doc/Development/Search_server_setup +.. _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``. + .. _searchlimit: searchlimit