Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion beets/metadata_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ class MetadataSourcePlugin(BeetsPlugin, metaclass=abc.ABCMeta):

def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)
self.config.add({"source_weight": 0.5})
self.config.add(
{
"search_limit": 5,
"source_weight": 0.5,
}
)

@abc.abstractmethod
def album_for_id(self, album_id: str) -> AlbumInfo | None:
Expand Down
8 changes: 7 additions & 1 deletion beetsplug/deezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class DeezerPlugin(SearchApiMetadataSourcePlugin[IDResponse]):
album_url = "https://api.deezer.com/album/"
track_url = "https://api.deezer.com/track/"

def __init__(self) -> None:
super().__init__()

def commands(self):
"""Add beet UI commands to interact with Deezer."""
deezer_update_cmd = ui.Subcommand(
Expand Down Expand Up @@ -245,7 +248,10 @@ def _search_api(
try:
response = requests.get(
f"{self.search_url}{query_type}",
params={"q": query},
params={
"q": query,
"limit": self.config["search_limit"].get(),
},
timeout=10,
)
response.raise_for_status()
Expand Down
3 changes: 1 addition & 2 deletions beetsplug/discogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ def __init__(self):
"separator": ", ",
"index_tracks": False,
"append_style_genre": False,
"search_limit": 5,
}
)
self.config["apikey"].redact = True
Expand Down Expand Up @@ -250,7 +249,7 @@ def get_albums(self, query: str) -> Iterable[AlbumInfo]:

try:
results = self.discogs_client.search(query, type="release")
results.per_page = self.config["search_limit"].as_number()
results.per_page = self.config["search_limit"].get()
releases = results.page(1)
except CONNECTION_ERRORS:
self._log.debug(
Expand Down
14 changes: 12 additions & 2 deletions beetsplug/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@

import traceback
from collections import Counter
from contextlib import suppress
from functools import cached_property
from itertools import product
from typing import TYPE_CHECKING, Any, Iterable, Sequence
from urllib.parse import urljoin

import musicbrainzngs
from confuse.exceptions import NotFoundError

import beets
import beets.autotag.hooks
Expand Down Expand Up @@ -371,7 +373,6 @@ def __init__(self):
"https": False,
"ratelimit": 1,
"ratelimit_interval": 1,
"searchlimit": 5,
"genres": False,
"external_ids": {
"discogs": False,
Expand All @@ -383,6 +384,15 @@ def __init__(self):
"extra_tags": [],
},
)
# TODO: Remove in 3.0.0
with suppress(NotFoundError):
self.config["search_limit"] = self.config["match"][
"searchlimit"
].get()
self._log.warning(
"'musicbrainz.searchlimit' option is deprecated and will be "
"removed in 3.0.0. Use 'musicbrainz.search_limit' instead."
)
hostname = self.config["host"].as_str()
https = self.config["https"].get(bool)
# Only call set_hostname when a custom server is configured. Since
Expand Down Expand Up @@ -799,7 +809,7 @@ def _search_api(
)
try:
method = getattr(musicbrainzngs, f"search_{query_type}s")
res = method(limit=self.config["searchlimit"].get(int), **filters)
res = method(limit=self.config["search_limit"].get(), **filters)
except musicbrainzngs.MusicBrainzError as exc:
raise MusicBrainzAPIError(
exc, f"{query_type} search", filters, traceback.format_exc()
Expand Down
6 changes: 5 additions & 1 deletion beetsplug/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,11 @@ def _search_api(
response = self._handle_response(
"get",
self.search_url,
params={"q": query, "type": query_type},
params={
"q": query,
"type": query_type,
"limit": self.config["search_limit"].get(),
},
)
except APIError as e:
self._log.debug("Spotify API error: {}", e)
Expand Down
4 changes: 3 additions & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ New features:
``played_ratio_threshold``, to allow configuring the percentage the song must
be played for it to be counted as played instead of skipped.
- :doc:`plugins/web`: Display artist and album as part of the search results.
- :doc:`plugins/spotify` :doc:`plugins/deezer`: Add new configuration option
``search_limit`` to limit the number of results returned by search queries.

Bug fixes:

Expand Down Expand Up @@ -2552,7 +2554,7 @@ Major new features and bigger changes:
analysis tool. Thanks to :user:`jmwatte`. :bug:`1343`
- A new ``filesize`` field on items indicates the number of bytes in the file.
:bug:`1291`
- A new :ref:`searchlimit` configuration option allows you to specify how many
- A new :ref:`search_limit` configuration option allows you to specify how many
search results you wish to see when looking up releases at MusicBrainz during
import. :bug:`1245`
- The importer now records the data source for a match in a new flexible
Expand Down
6 changes: 5 additions & 1 deletion docs/plugins/deezer.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ Configuration
-------------

This plugin can be configured like other metadata source plugins as described in
:ref:`metadata-source-plugin-configuration`.
:ref:`metadata-source-plugin-configuration`. In addition, the following
configuration options are provided.

- **search_limit**: The maximum number of results to return from Deezer for each
search query. Default: ``5``.

The default options should work as-is, but there are some options you can put in
config.yaml under the ``deezer:`` section:
Expand Down
13 changes: 9 additions & 4 deletions docs/plugins/musicbrainz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Default
https: no
ratelimit: 1
ratelimit_interval: 1.0
searchlimit: 5
search_limit: 5
extra_tags: []
genres: no
external_ids:
Expand Down Expand Up @@ -82,16 +82,21 @@ make the import process quicker.

Default: ``yes``.

.. _searchlimit:
.. _search_limit:

searchlimit
+++++++++++
search_limit
++++++++++++

The number of matches returned when sending search queries to the MusicBrainz
server.

Default: ``5``.

searchlimit
+++++++++++

.. deprecated:: 2.4 Use `search_limit`_.

.. _extra_tags:

extra_tags
Expand Down
2 changes: 2 additions & 0 deletions docs/plugins/spotify.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ config.yaml under the ``spotify:`` section:
enhance search results in some cases, but in general, it is not recommended.
For instance ``artist:deadmau5 album:4×4`` will be converted to
``artist:deadmau5 album:4x4`` (notice ``×!=x``). Default: ``no``.
- **search_limit**: The maximum number of results to return from Spotify for
each search query. Default: ``5``.

Here's an example:

Expand Down
Loading