From b53548e3213ab1c9f75e6859202bd6764aa1b2e5 Mon Sep 17 00:00:00 2001 From: Hellow Date: Thu, 9 Mar 2023 20:44:57 +0100 Subject: [PATCH] implemented DatabaseObject.indexing_values for each data objects --- src/music_kraken/objects/song.py | 19 +++++++++---------- src/music_kraken/objects/target.py | 12 ++++++++---- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/music_kraken/objects/song.py b/src/music_kraken/objects/song.py index 3ef4d3c..bb5ede5 100644 --- a/src/music_kraken/objects/song.py +++ b/src/music_kraken/objects/song.py @@ -43,6 +43,9 @@ class Song(MainObject, SourceAttribute, MetadataAttribute): Inherits from DatabaseObject, SourceAttribute, and MetadataAttribute classes. """ + COLLECTION_ATTRIBUTES = ("lyrics_collection", "album_collection", "main_artist_collection", "feature_artist_collection", "source_collection") + SIMPLE_ATTRIBUTES = ("title", "unified_title", "isrc", "length", "tracksort", "genre") + def __init__( self, _id: str = None, @@ -74,19 +77,18 @@ class Song(MainObject, SourceAttribute, MetadataAttribute): self.tracksort: int = tracksort or 0 self.genre: str = genre - self.source_list = source_list or [] - - self.target_list = target_list or [] + self.target_collection: Collection = Collection( + data=target_list, + element_type=Target + ) self.lyrics_collection: Collection = Collection( - data=lyrics_list or [], - map_attributes=[], + data=lyrics_list, element_type=Lyrics ) self.album_collection: Collection = Collection( - data=album_list or [], - map_attributes=["title"], + data=album_list, element_type=Album ) @@ -180,9 +182,6 @@ class Song(MainObject, SourceAttribute, MetadataAttribute): album_list: List[Type['Album']] = property(fget=lambda self: self.album_collection.copy()) lyrics_list: List[Type[Lyrics]] = property(fget=lambda self: self.lyrics_collection.copy()) - COLLECTION_ATTRIBUTES = ("lyrics_collection", "album_collection", "main_artist_collection", "feature_artist_collection") - SIMPLE_ATTRIBUTES = ("title", "isrc", "length", "tracksort", "genre") - """ All objects dependent on Album diff --git a/src/music_kraken/objects/target.py b/src/music_kraken/objects/target.py index 7c829a9..7d7f7eb 100644 --- a/src/music_kraken/objects/target.py +++ b/src/music_kraken/objects/target.py @@ -1,4 +1,4 @@ -from typing import Optional +from typing import Optional, List, Tuple from pathlib import Path from ..utils import shared @@ -14,6 +14,8 @@ class Target(DatabaseObject): ``` """ + SIMPLE_ATTRIBUTES = ("_file", "_path") + def __init__( self, file: str = None, @@ -24,12 +26,14 @@ class Target(DatabaseObject): ) -> None: super().__init__(_id=_id, dynamic=dynamic) self._file: Path = Path(file) - self._path = path + self._path: Path = Path(path) if relative_to_music_dir else Path(path) self.is_relative_to_music_dir: bool = relative_to_music_dir @property def file_path(self) -> Path: - if self.is_relative_to_music_dir: - return Path(shared.MUSIC_DIR, self._path, self._file) return Path(self._path, self._file) + + @property + def indexing_values(self) -> List[Tuple[str, object]]: + return [('filepath', self.file_path)]