diff --git a/music_kraken/objects/song.py b/music_kraken/objects/song.py index 00a951b..48b52c4 100644 --- a/music_kraken/objects/song.py +++ b/music_kraken/objects/song.py @@ -8,7 +8,7 @@ import copy import pycountry from ..utils.enums.album import AlbumType, AlbumStatus -from .collection import Collection +from .collection import Collection, AppendHookArguments from .formatted_text import FormattedText from .lyrics import Lyrics from .contact import Contact @@ -144,6 +144,14 @@ class Song(Base): UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("artist_collection", "feature_artist_collection", "album_collection") TITEL = "title" + @staticmethod + def register_artwork_parent(append_hook_arguments: AppendHookArguments): + album: Album = append_hook_arguments.new_object + + song: Song + for song in append_hook_arguments.collection_root_objects: + song.artwork.parent_artworks.add(album.artwork) + def __init_collections__(self) -> None: self.feature_artist_collection.push_to = [self.artist_collection] self.artist_collection.pull_from = [self.feature_artist_collection] @@ -161,6 +169,7 @@ class Song(Base): self.feature_artist_collection.extend_object_to_attribute = { "album_collection": self.album_collection } + self.album_collection.append_callbacks = set((Song.register_artwork_parent, )) def _add_other_db_objects(self, object_type: Type[OuterProxy], object_list: List[OuterProxy]): if object_type is Song: @@ -249,6 +258,7 @@ class Album(Base): albumsort: int notes: FormattedText + artwork: Artwork source_collection: SourceCollection song_collection: Collection[Song] @@ -268,6 +278,7 @@ class Album(Base): "date": ID3Timestamp, "notes": FormattedText, + "artwork": lambda: Artwork(crop_images=False), "source_collection": SourceCollection, "song_collection": Collection, @@ -290,6 +301,7 @@ class Album(Base): barcode: str = None, albumsort: int = None, notes: FormattedText = None, + artwork: Artwork = None, source_list: List[Source] = None, artist_list: List[Artist] = None, song_list: List[Song] = None, @@ -304,6 +316,13 @@ class Album(Base): DOWNWARDS_COLLECTION_STRING_ATTRIBUTES = ("song_collection",) UPWARDS_COLLECTION_STRING_ATTRIBUTES = ("label_collection", "artist_collection") + @staticmethod + def register_artwork_parent(append_hook_arguments: AppendHookArguments): + song: Song = append_hook_arguments.new_object + + for root_object in append_hook_arguments.collection_root_objects: + song.artwork.parent_artworks.add(root_object.artwork) + def __init_collections__(self): self.feature_artist_collection.push_to = [self.artist_collection] self.artist_collection.pull_from = [self.feature_artist_collection] @@ -322,6 +341,8 @@ class Album(Base): "label_collection": self.label_collection } + self.song_collection.append_callbacks = set((Album.register_artwork_parent, )) + def _add_other_db_objects(self, object_type: Type[OuterProxy], object_list: List[OuterProxy]): if object_type is Song: self.song_collection.extend(object_list)