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
27 changes: 23 additions & 4 deletions beets/metadata_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import abc
import re
from concurrent.futures import ThreadPoolExecutor, as_completed
from contextlib import contextmanager
from functools import cache, cached_property, wraps
from typing import (
Comment thread
semohr marked this conversation as resolved.
Expand Down Expand Up @@ -79,10 +80,28 @@ def _yield_from_plugins(

@wraps(func)
def wrapper(*args, **kwargs) -> Iterator[Ret]:
for plugin in find_metadata_source_plugins():
method = getattr(plugin, method_name)
with maybe_handle_plugin_error(plugin, method_name):
yield from filter(None, method(*args, **kwargs))
# Run plugin methods concurrently for faster I/O-bound lookups.
with ThreadPoolExecutor() as executor:
futures = {
executor.submit(
# Evaluate iterator with list such that results are ready when
# future.result() is called.
lambda *args, **kwargs: list(
getattr(plugin, method_name)(
*args,
**kwargs,
)
),
*args,
**kwargs,
): plugin
for plugin in find_metadata_source_plugins()
}

Comment thread
semohr marked this conversation as resolved.
for future in as_completed(futures):
plugin = futures[future]
with maybe_handle_plugin_error(plugin, method_name):
yield from filter(None, future.result())
Comment thread
semohr marked this conversation as resolved.

return wrapper

Expand Down
3 changes: 3 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ New features
CLI flag to skip re-fetching lyrics for tracks that already have synced
lyrics, even when ``force`` is enabled. :bug:`5249`
- :doc:`plugins/musicbrainz`: Use aliases for artist credit.
- Metadata source plugin searches and lookups are now executed concurrently,
speeding up lookups when multiple plugins (e.g. MusicBrainz and Spotify) are
enabled.

Bug fixes
~~~~~~~~~
Expand Down
Loading