Skip to content

Commit a97633d

Browse files
committed
Opt in dicogs plugin.
1 parent 6f623ee commit a97633d

File tree

1 file changed

+10
-23
lines changed

1 file changed

+10
-23
lines changed

beetsplug/discogs.py

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import traceback
2828
from functools import cache
2929
from string import ascii_lowercase
30-
from typing import TYPE_CHECKING
30+
from typing import TYPE_CHECKING, Sequence
3131

3232
import confuse
3333
from discogs_client import Client, Master, Release
@@ -40,8 +40,7 @@
4040
from beets import config
4141
from beets.autotag.distance import string_dist
4242
from beets.autotag.hooks import AlbumInfo, TrackInfo
43-
from beets.plugins import BeetsPlugin, MetadataSourcePlugin, get_distance
44-
from beets.util.id_extractors import extract_release_id
43+
from beets.metadata_plugins import MetadataSourcePlugin
4544

4645
if TYPE_CHECKING:
4746
from collections.abc import Callable, Iterable
@@ -84,7 +83,7 @@ class ReleaseFormat(TypedDict):
8483
descriptions: list[str] | None
8584

8685

87-
class DiscogsPlugin(BeetsPlugin):
86+
class DiscogsPlugin(MetadataSourcePlugin):
8887
def __init__(self):
8988
super().__init__()
9089
self.config.add(
@@ -169,20 +168,8 @@ def authenticate(self, c_key, c_secret):
169168

170169
return token, secret
171170

172-
def album_distance(self, items, album_info, mapping):
173-
"""Returns the album distance."""
174-
return get_distance(
175-
data_source="Discogs", info=album_info, config=self.config
176-
)
177-
178-
def track_distance(self, item, track_info):
179-
"""Returns the track distance."""
180-
return get_distance(
181-
data_source="Discogs", info=track_info, config=self.config
182-
)
183-
184171
def candidates(
185-
self, items: list[Item], artist: str, album: str, va_likely: bool
172+
self, items: Sequence[Item], artist: str, album: str, va_likely: bool
186173
) -> Iterable[AlbumInfo]:
187174
return self.get_albums(f"{artist} {album}" if va_likely else album)
188175

@@ -217,7 +204,7 @@ def album_for_id(self, album_id: str) -> AlbumInfo | None:
217204
"""
218205
self._log.debug("Searching for release {0}", album_id)
219206

220-
discogs_id = extract_release_id("discogs", album_id)
207+
discogs_id = self.extract_release_id(album_id)
221208

222209
if not discogs_id:
223210
return None
@@ -272,7 +259,7 @@ def get_albums(self, query: str) -> Iterable[AlbumInfo]:
272259
exc_info=True,
273260
)
274261
return []
275-
return map(self.get_album_info, releases)
262+
return filter(None, map(self.get_album_info, releases))
276263

277264
@cache
278265
def get_master_year(self, master_id: str) -> int | None:
@@ -334,7 +321,7 @@ def get_album_info(self, result):
334321
self._log.warning("Release does not contain the required fields")
335322
return None
336323

337-
artist, artist_id = MetadataSourcePlugin.get_artist(
324+
artist, artist_id = self.get_artist(
338325
[a.data for a in result.artists], join_key="join"
339326
)
340327
album = re.sub(r" +", " ", result.title)
@@ -359,7 +346,7 @@ def get_album_info(self, result):
359346
else:
360347
genre = base_genre
361348

362-
discogs_albumid = extract_release_id("discogs", result.data.get("uri"))
349+
discogs_albumid = self.extract_release_id(result.data.get("uri"))
363350

364351
# Extract information for the optional AlbumInfo fields that are
365352
# contained on nested discogs fields.
@@ -419,7 +406,7 @@ def get_album_info(self, result):
419406
genre=genre,
420407
media=media,
421408
original_year=original_year,
422-
data_source="Discogs",
409+
data_source=self.data_source,
423410
data_url=data_url,
424411
discogs_albumid=discogs_albumid,
425412
discogs_labelid=labelid,
@@ -638,7 +625,7 @@ def get_track_info(self, track, index, divisions):
638625
title = f"{prefix}: {title}"
639626
track_id = None
640627
medium, medium_index, _ = self.get_track_index(track["position"])
641-
artist, artist_id = MetadataSourcePlugin.get_artist(
628+
artist, artist_id = self.get_artist(
642629
track.get("artists", []), join_key="join"
643630
)
644631
length = self.get_track_length(track["duration"])

0 commit comments

Comments
 (0)