mirror of
https://github.com/beetbox/beets.git
synced 2025-12-15 21:14:19 +01:00
hooks: Generalise AlbumInfo and TrackInfo into Info
This commit is contained in:
parent
7340f150e0
commit
e8d2c28e94
1 changed files with 12 additions and 13 deletions
|
|
@ -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.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue