diff --git a/beetsplug/discogs.py b/beetsplug/discogs.py index 1852f300f..187a30e4e 100644 --- a/beetsplug/discogs.py +++ b/beetsplug/discogs.py @@ -73,6 +73,7 @@ class DiscogsPlugin(BeetsPlugin): "separator": ", ", "index_tracks": False, "append_style_genre": False, + "search_limit": 5, } ) self.config["apikey"].redact = True @@ -257,8 +258,8 @@ class DiscogsPlugin(BeetsPlugin): ) if track_result: candidates.append(track_result) - # first 10 results, don't overwhelm with options - return candidates[:10] + + return candidates def album_for_id(self, album_id): """Fetches an album by its Discogs ID and returns an AlbumInfo object @@ -303,8 +304,9 @@ class DiscogsPlugin(BeetsPlugin): query = re.sub(r"(?i)\b(CD|disc|vinyl)\s*\d+", "", query) try: - releases = self.discogs_client.search(query, type="release").page(1) - + results = self.discogs_client.search(query, type="release") + results.per_page = self.config["search_limit"].as_number() + releases = results.page(1) except CONNECTION_ERRORS: self._log.debug( "Communication error while searching for {0!r}", @@ -312,9 +314,7 @@ class DiscogsPlugin(BeetsPlugin): exc_info=True, ) return [] - return [ - album for album in map(self.get_album_info, releases[:5]) if album - ] + return map(self.get_album_info, releases) def get_master_year(self, master_id): """Fetches a master release given its Discogs ID and returns its year diff --git a/docs/changelog.rst b/docs/changelog.rst index 3370f5396..ebb9880a9 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -17,6 +17,8 @@ New features: :bug:`4605` * :doc:`plugins/web`: Show notifications when a track plays. This uses the Media Session API to customize media notifications. +* :doc:`plugins/discogs`: Add configurable ``search_limit`` option to + limit the number of results returned by the Discogs metadata search queries. Bug fixes: diff --git a/docs/plugins/discogs.rst b/docs/plugins/discogs.rst index ac67f2d0a..c8df12a41 100644 --- a/docs/plugins/discogs.rst +++ b/docs/plugins/discogs.rst @@ -101,11 +101,20 @@ This option is useful when importing classical music. Other configurations available under ``discogs:`` are: -- **append_style_genre**: Appends the Discogs style (if found) to the genre tag. This can be useful if you want more granular genres to categorize your music. - For example, a release in Discogs might have a genre of "Electronic" and a style of "Techno": enabling this setting would set the genre to be "Electronic, Techno" (assuming default separator of ``", "``) instead of just "Electronic". +- **append_style_genre**: Appends the Discogs style (if found) to the genre + tag. This can be useful if you want more granular genres to categorize your + music. For example, a release in Discogs might have a genre of "Electronic" + and a style of "Techno": enabling this setting would set the genre to be + "Electronic, Techno" (assuming default separator of ``", "``) instead of just + "Electronic". Default: ``False`` -- **separator**: How to join multiple genre and style values from Discogs into a string. +- **separator**: How to join multiple genre and style values from Discogs into + a string. Default: ``", "`` +- **search_limit**: The maximum number of results to return from Discogs. This is + useful if you want to limit the number of results returned to speed up + searches. + Default: ``5`` Troubleshooting