hooks: Generalise AlbumInfo and TrackInfo into Info

This commit is contained in:
Šarūnas Nejus 2025-08-26 01:33:09 +01:00
parent 7340f150e0
commit e8d2c28e94
No known key found for this signature in database
GPG key ID: DD28F6704DBE3435

View file

@ -16,8 +16,11 @@
from __future__ import annotations
from copy import deepcopy
from typing import TYPE_CHECKING, Any, NamedTuple, TypeVar
from typing_extensions import Self
from beets import logging
if TYPE_CHECKING:
@ -36,6 +39,9 @@ class AttrDict(dict[str, V]):
is equivalent to `d['field']`.
"""
def copy(self) -> Self:
return deepcopy(self)
def __getattr__(self, attr: str) -> V:
if attr in self:
return self[attr]
@ -49,7 +55,11 @@ class AttrDict(dict[str, V]):
return id(self)
class AlbumInfo(AttrDict[Any]):
class Info(AttrDict[Any]):
pass
class AlbumInfo(Info):
"""Describes a canonical release that may be used to match a release
in the library. Consists of these data members:
@ -152,14 +162,8 @@ class AlbumInfo(AttrDict[Any]):
self.discogs_artistid = discogs_artistid
self.update(kwargs)
def copy(self) -> AlbumInfo:
dupe = AlbumInfo([])
dupe.update(self)
dupe.tracks = [track.copy() for track in self.tracks]
return dupe
class TrackInfo(AttrDict[Any]):
class TrackInfo(Info):
"""Describes a canonical track present on a release. Appears as part
of an AlbumInfo's ``tracks`` list. Consists of these data members:
@ -242,11 +246,6 @@ class TrackInfo(AttrDict[Any]):
self.album = album
self.update(kwargs)
def copy(self) -> TrackInfo:
dupe = TrackInfo()
dupe.update(self)
return dupe
# Structures that compose all the information for a candidate match.