Skip to content

Commit 95df036

Browse files
committed
hooks: introduce Info.name property
1 parent ec60ec6 commit 95df036

File tree

2 files changed

+118
-104
lines changed

2 files changed

+118
-104
lines changed

beets/autotag/hooks.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
from typing_extensions import Self
2525

26+
from beets.util import cached_classproperty
27+
2628
if TYPE_CHECKING:
2729
from beets.library import Item
2830

@@ -56,6 +58,10 @@ def __hash__(self) -> int: # type: ignore[override]
5658
class Info(AttrDict[Any]):
5759
"""Container for metadata about a musical entity."""
5860

61+
@cached_property
62+
def name(self) -> str:
63+
raise NotImplementedError
64+
5965
def __init__(
6066
self,
6167
album: str | None = None,
@@ -97,6 +103,10 @@ class AlbumInfo(Info):
97103
user items, and later to drive tagging decisions once selected.
98104
"""
99105

106+
@cached_property
107+
def name(self) -> str:
108+
return self.album or ""
109+
100110
def __init__(
101111
self,
102112
tracks: list[TrackInfo],
@@ -169,6 +179,10 @@ class TrackInfo(Info):
169179
stand alone for singleton matching.
170180
"""
171181

182+
@cached_property
183+
def name(self) -> str:
184+
return self.title or ""
185+
172186
def __init__(
173187
self,
174188
*,
@@ -221,6 +235,10 @@ class Match:
221235
distance: Distance
222236
info: Info
223237

238+
@cached_classproperty
239+
def type(cls) -> str:
240+
return cls.__name__.removesuffix("Match") # type: ignore[attr-defined]
241+
224242

225243
@dataclass
226244
class AlbumMatch(Match):

0 commit comments

Comments
 (0)