diff --git a/src/goof.py b/src/goof.py index 7f0bb42..1424b5f 100644 --- a/src/goof.py +++ b/src/goof.py @@ -50,7 +50,7 @@ cache.push([album_input, song_input, lyrics, additional_song]) # getting song by song ref song_output_list = cache.pull_songs(song_ref=song_ref) -print(len(song_output_list), song_output_list) +print(len(song_output_list), song_output_list, song_output_list[0].album) # song_output = song_output_list[0] # print(song_output) # print("album id", song_output.album_ref) diff --git a/src/music_kraken/database/new_database.py b/src/music_kraken/database/new_database.py index b12f05c..6eba370 100644 --- a/src/music_kraken/database/new_database.py +++ b/src/music_kraken/database/new_database.py @@ -268,10 +268,13 @@ class Database: url=source_row['url'] ) for source_row in source_rows] - def get_song_from_row(self, song_result, exclude_independent_relations: bool = False) -> Song: + def get_song_from_row(self, song_result, exclude_relations: set = set()) -> Song: + new_exclude_relations: set = set(exclude_relations) + new_exclude_relations.add(Song) + song_id = song_result['song_id'] - return Song( + song_obj = Song( id_=song_id, title=song_result['title'], isrc=song_result['isrc'], @@ -286,7 +289,14 @@ class Database: album_ref=Reference(song_result['album_id']) ) - def pull_songs(self, song_ref: Reference = None, album_ref: Reference = None, exclude_independent_relations: bool = False) -> List[Song]: + if Album not in exclude_relations and song_result['album_id'] is not None: + album_obj = self.pull_albums(album_ref=Reference(song_result['album_id']), exclude_relations=new_exclude_relations) + if len(album_obj) > 0: + song_obj.album = album_obj[0] + + return song_obj + + def pull_songs(self, song_ref: Reference = None, album_ref: Reference = None, exclude_relations: set = set()) -> List[Song]: """ This function is used to get one song (including its children like Sources etc) from one song id (a reference object) @@ -311,10 +321,14 @@ class Database: return [self.get_song_from_row( song_result=song_result, - exclude_independent_relations=exclude_independent_relations + exclude_relations=exclude_relations ) for song_result in song_rows] - def get_album_from_row(self, album_result, exclude_independent_relations: bool = False) -> Album: + def get_album_from_row(self, album_result, exclude_relations: set = set()) -> Album: + new_exclude_relations: set = exclude_relations.copy() + + new_exclude_relations.add(Album) + album_id = album_result['album_id'] album_obj = Album( @@ -329,17 +343,20 @@ class Database: barcode=album_result['barcode'] ) - if not exclude_independent_relations: + print(exclude_relations) + + if Song not in exclude_relations: + print("yay") # getting the tracklist tracklist: List[Song] = self.pull_songs( album_ref=Reference(id_=album_id), - exclude_independent_relations=True + exclude_relations=new_exclude_relations ) album_obj.set_tracklist(tracklist=tracklist) return album_obj - def pull_albums(self, album_ref: Reference = None, exclude_independent_relations: bool = False) -> List[Album]: + def pull_albums(self, album_ref: Reference = None, exclude_relations: set = set()) -> List[Album]: """ This function is used to get matching albums/releses from one song id (a reference object) @@ -357,7 +374,7 @@ class Database: return [self.get_album_from_row( album_result=album_row, - exclude_independent_relations=exclude_independent_relations + exclude_relations=exclude_relations ) for album_row in album_rows] diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index d1e31a0..c3c6c45 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -190,6 +190,8 @@ class Song(DatabaseObject): self.album_ref = album_ref self.artist_refs = artist_refs + self.album: Album = None + def __eq__(self, other): if type(other) != type(self): return False diff --git a/test.db b/test.db index bcddebc..5fa740d 100644 Binary files a/test.db and b/test.db differ