Skip to content

Commit 5f8ca35

Browse files
committed
hooks: introduce Info.name property
1 parent 50e4d03 commit 5f8ca35

File tree

2 files changed

+120
-101
lines changed

2 files changed

+120
-101
lines changed

beets/autotag/hooks.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@
1818

1919
from copy import deepcopy
2020
from dataclasses import dataclass
21+
from functools import cached_property
2122
from typing import TYPE_CHECKING, Any, TypeVar
2223

2324
from typing_extensions import Self
2425

26+
from beets.util import cached_classproperty
27+
2528
if TYPE_CHECKING:
2629
from beets.library import Item
2730

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

61+
@cached_property
62+
def name(self) -> str:
63+
raise NotImplementedError
64+
5865
def __init__(
5966
self,
6067
album: str | None = None,
@@ -96,6 +103,10 @@ class AlbumInfo(Info):
96103
user items, and later to drive tagging decisions once selected.
97104
"""
98105

106+
@cached_property
107+
def name(self) -> str:
108+
return self.album or ""
109+
99110
def __init__(
100111
self,
101112
tracks: list[TrackInfo],
@@ -168,6 +179,10 @@ class TrackInfo(Info):
168179
stand alone for singleton matching.
169180
"""
170181

182+
@cached_property
183+
def name(self) -> str:
184+
return self.title or ""
185+
171186
def __init__(
172187
self,
173188
*,
@@ -220,6 +235,10 @@ class Match:
220235
distance: Distance
221236
info: Info
222237

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

224243
@dataclass
225244
class AlbumMatch(Match):

0 commit comments

Comments
 (0)