Skip to content

Commit 9242db0

Browse files
committed
discogs: add configurable search_limit
1 parent 3a663ad commit 9242db0

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

beetsplug/discogs.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def __init__(self):
7373
"separator": ", ",
7474
"index_tracks": False,
7575
"append_style_genre": False,
76+
"search_limit": 5,
7677
}
7778
)
7879
self.config["apikey"].redact = True
@@ -257,8 +258,8 @@ def item_candidates(self, item, artist, title):
257258
)
258259
if track_result:
259260
candidates.append(track_result)
260-
# first 10 results, don't overwhelm with options
261-
return candidates[:10]
261+
262+
return candidates
262263

263264
def album_for_id(self, album_id):
264265
"""Fetches an album by its Discogs ID and returns an AlbumInfo object
@@ -303,18 +304,17 @@ def get_albums(self, query):
303304
query = re.sub(r"(?i)\b(CD|disc|vinyl)\s*\d+", "", query)
304305

305306
try:
306-
releases = self.discogs_client.search(query, type="release").page(1)
307-
307+
results = self.discogs_client.search(query, type="release")
308+
results.per_page = self.config["search_limit"].as_number()
309+
releases = results.page(1)
308310
except CONNECTION_ERRORS:
309311
self._log.debug(
310312
"Communication error while searching for {0!r}",
311313
query,
312314
exc_info=True,
313315
)
314316
return []
315-
return [
316-
album for album in map(self.get_album_info, releases[:5]) if album
317-
]
317+
return map(self.get_album_info, releases)
318318

319319
def get_master_year(self, master_id):
320320
"""Fetches a master release given its Discogs ID and returns its year

docs/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ New features:
1717
:bug:`4605`
1818
* :doc:`plugins/web`: Show notifications when a track plays. This uses the
1919
Media Session API to customize media notifications.
20+
* :doc:`plugins/discogs`: Add configurable ``search_limit`` option to
21+
limit the number of results returned by the Discogs metadata search queries.
2022

2123
Bug fixes:
2224

docs/plugins/discogs.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,20 @@ This option is useful when importing classical music.
101101

102102
Other configurations available under ``discogs:`` are:
103103

104-
- **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.
105-
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".
104+
- **append_style_genre**: Appends the Discogs style (if found) to the genre
105+
tag. This can be useful if you want more granular genres to categorize your
106+
music. For example, a release in Discogs might have a genre of "Electronic"
107+
and a style of "Techno": enabling this setting would set the genre to be
108+
"Electronic, Techno" (assuming default separator of ``", "``) instead of just
109+
"Electronic".
106110
Default: ``False``
107-
- **separator**: How to join multiple genre and style values from Discogs into a string.
111+
- **separator**: How to join multiple genre and style values from Discogs into
112+
a string.
108113
Default: ``", "``
114+
- **search_limit**: The maximum number of results to return from Discogs. This is
115+
useful if you want to limit the number of results returned to speed up
116+
searches.
117+
Default: ``5``
109118

110119

111120
Troubleshooting

0 commit comments

Comments
 (0)