From d00d51e0bf8d8db159dc6a6def5da4deafaaba2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0ar=C5=ABnas=20Nejus?= Date: Mon, 25 Aug 2025 19:30:10 +0100 Subject: [PATCH] Add configurable search_limit to Spotify and Deezer plugins --- beetsplug/deezer.py | 6 +++++- beetsplug/spotify.py | 3 ++- docs/changelog.rst | 2 ++ docs/plugins/deezer.rst | 6 +++++- docs/plugins/spotify.rst | 2 ++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/beetsplug/deezer.py b/beetsplug/deezer.py index e427b08b1..0e162372a 100644 --- a/beetsplug/deezer.py +++ b/beetsplug/deezer.py @@ -49,6 +49,10 @@ class DeezerPlugin(SearchApiMetadataSourcePlugin[IDResponse]): album_url = "https://api.deezer.com/album/" track_url = "https://api.deezer.com/track/" + def __init__(self) -> None: + super().__init__() + self.config.add({"search_limit": 5}) + def commands(self): """Add beet UI commands to interact with Deezer.""" deezer_update_cmd = ui.Subcommand( @@ -263,7 +267,7 @@ class DeezerPlugin(SearchApiMetadataSourcePlugin[IDResponse]): self, query, ) - return response_data + return response_data[: self.config["search_limit"].get()] def deezerupdate(self, items: Sequence[Item], write: bool): """Obtain rank information from Deezer.""" diff --git a/beetsplug/spotify.py b/beetsplug/spotify.py index d83927328..ffeb844a6 100644 --- a/beetsplug/spotify.py +++ b/beetsplug/spotify.py @@ -138,6 +138,7 @@ class SpotifyPlugin( "client_id": "4e414367a1d14c75a5c5129a627fcab8", "client_secret": "f82bdc09b2254f1a8286815d02fd46dc", "tokenfile": "spotify_token.json", + "search_limit": 5, } ) self.config["client_id"].redact = True @@ -454,7 +455,7 @@ class SpotifyPlugin( self, query, ) - return response_data + return response_data[: self.config["search_limit"].get()] def commands(self) -> list[ui.Subcommand]: # autotagger import command diff --git a/docs/changelog.rst b/docs/changelog.rst index e12050fdc..1cc537136 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -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: diff --git a/docs/plugins/deezer.rst b/docs/plugins/deezer.rst index 2d0bd7009..b3a57e825 100644 --- a/docs/plugins/deezer.rst +++ b/docs/plugins/deezer.rst @@ -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: diff --git a/docs/plugins/spotify.rst b/docs/plugins/spotify.rst index be929adf7..2c6cb3d1c 100644 --- a/docs/plugins/spotify.rst +++ b/docs/plugins/spotify.rst @@ -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: