Skip to content

Commit f67d40c

Browse files
authored
Refactor of metadata plugin and opt in all metadata plugins to new baseclass (#5787)
At the moment the `MetaDataSourcePlugin` has multiple responsibilities: - fetch data via `_search` api - defines contract for interaction within the beets autotag lookup I propose splitting these responsibilities, as it would enable us to use the `MetaDataSourcePlugin` baseclass with plugins that use external packages to fetch data. This follows from discussion in #5761 and #5748 (comment). Feedback is highly appreciated, as this is mainly architectural decision and I would prefer if the new behavior is a shared consensus. ## To Do - [x] Opt in plugins into the new `MetaDataSourcePlugin` - [x] Spotify - [x] Musicbrainz - [x] Deezer - [x] Beatport - [x] Chroma - [x] Disccogs - [x] Remove old MetaDataSourcePlugin and related functions - [x] Documentation on the ontology of plugins - [x] Changelog This PR was initially #5764 and was accidentally closed as the target branch was deleted. Wasn't able to recover the original PR.
2 parents 24dd40e + a0ae9db commit f67d40c

19 files changed

+786
-546
lines changed

beets/autotag/distance.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from jellyfish import levenshtein_distance
99
from unidecode import unidecode
1010

11-
from beets import config, plugins
11+
from beets import config, metadata_plugins
1212
from beets.util import as_string, cached_classproperty, get_most_common_tags
1313

1414
if TYPE_CHECKING:
@@ -409,7 +409,7 @@ def track_distance(
409409
dist.add_expr("medium", item.disc != track_info.medium)
410410

411411
# Plugins.
412-
dist.update(plugins.track_distance(item, track_info))
412+
dist.update(metadata_plugins.track_distance(item, track_info))
413413

414414
return dist
415415

@@ -526,6 +526,6 @@ def distance(
526526
dist.add("unmatched_tracks", 1.0)
527527

528528
# Plugins.
529-
dist.update(plugins.album_distance(items, album_info, mapping))
529+
dist.update(metadata_plugins.album_distance(items, album_info, mapping))
530530

531531
return dist

beets/autotag/match.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import lap
2525
import numpy as np
2626

27-
from beets import config, logging, plugins
27+
from beets import config, logging, metadata_plugins
2828
from beets.autotag import AlbumInfo, AlbumMatch, TrackInfo, TrackMatch, hooks
2929
from beets.util import get_most_common_tags
3030

@@ -119,7 +119,7 @@ def match_by_id(items: Iterable[Item]) -> AlbumInfo | None:
119119
return None
120120
# If all album IDs are equal, look up the album.
121121
log.debug("Searching for discovered album ID: {0}", first)
122-
return plugins.album_for_id(first)
122+
return metadata_plugins.album_for_id(first)
123123

124124

125125
def _recommendation(
@@ -274,7 +274,7 @@ def tag_album(
274274
if search_ids:
275275
for search_id in search_ids:
276276
log.debug("Searching for album ID: {0}", search_id)
277-
if info := plugins.album_for_id(search_id):
277+
if info := metadata_plugins.album_for_id(search_id):
278278
_add_candidate(items, candidates, info)
279279

280280
# Use existing metadata or text search.
@@ -311,7 +311,7 @@ def tag_album(
311311
log.debug("Album might be VA: {0}", va_likely)
312312

313313
# Get the results from the data sources.
314-
for matched_candidate in plugins.candidates(
314+
for matched_candidate in metadata_plugins.candidates(
315315
items, search_artist, search_album, va_likely
316316
):
317317
_add_candidate(items, candidates, matched_candidate)
@@ -346,7 +346,7 @@ def tag_item(
346346
if trackids:
347347
for trackid in trackids:
348348
log.debug("Searching for track ID: {0}", trackid)
349-
if info := plugins.track_for_id(trackid):
349+
if info := metadata_plugins.track_for_id(trackid):
350350
dist = track_distance(item, info, incl_artist=True)
351351
candidates[info.track_id] = hooks.TrackMatch(dist, info)
352352
# If this is a good match, then don't keep searching.
@@ -372,7 +372,7 @@ def tag_item(
372372
log.debug("Item search terms: {0} - {1}", search_artist, search_title)
373373

374374
# Get and evaluate candidate metadata.
375-
for track_info in plugins.item_candidates(
375+
for track_info in metadata_plugins.item_candidates(
376376
item, search_artist, search_title
377377
):
378378
dist = track_distance(item, track_info, incl_artist=True)

0 commit comments

Comments
 (0)