From eb42920488a3f76c8bd6bc8511d614ccde764e83 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Fri, 9 Dec 2022 15:50:44 +0100 Subject: [PATCH] fucking finally --- src/goof.py | 2 +- src/music_kraken/database/new_database.py | 35 ++++++++++++++++------ src/music_kraken/database/objects/song.py | 2 ++ test.db | Bin 65536 -> 65536 bytes 4 files changed, 29 insertions(+), 10 deletions(-) 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 bcddebcbd8fb2c0b9c756ab347bba2991cf4bbf0..5fa740deaab7c7f41faf22537a1609db4a43d166 100644 GIT binary patch delta 1302 zcmcJOyNZ)h6oqq{s1fvMT1QBV;8?iHxnDqx);gfb{{Z{kW(G9@lL5QLW@_PofNAZN zM64{vUYOQWdkcFTkMRLKjs0frwZFaAYPGXk?YzG~SPB-ULngtaksxAFfXEeSp|xWs zIWO?RF!^W4)5GD@+4L~Vz=cZ&xFQq;Y7Quq1LH#CQgIW!JZ@jAC#_B$6Hzh{16EoO zLNf=JAc9ET5o4_<9rVrT!QQAubv@iv2PJ+x``x<#@7?Iv(|Yh8)2t zs=*}@5Ivz(ndaVP|4E7BN&9lW_wY);j*?iWqXyJ8W6ET*pr$}*ppg+Ss8!9!$*oa| z>h|&ypMNheSiOGyWn2V(^K<#5DwC@()A(riB95Qq%lWwZbT(|>o{2)LAF4+M zez#CdjQodyo`1hS%Kfw~n9RVb+#;J9xR|S?gRm+n$uPL4cX4-_lD0CSftXTGvep7H zBLa#}c;hsuIxgaT5vL`go8=E2?A96sO7AS>isZMN+T79kFZFYyRs^#r&-7Yz_`)9D^(Cybs%wNlHTASXtUxVK+sblZ} delta 1318 zcmb`GJ!@1!6o&8aCTav7(i&m6Sd4{-ov%AH2gGQtfdsifU_O(eCg3Juw`-GHxIZ9* zjor$wSXsngNSji73ws+U`v;uDet75oc+PaXGM%n`dfcBVZ&b1#p_VLytc?K2O$4oj zXG$>|gMBhc{>8!J-r)Js;a=?m8pW1qpuC1&>0S;Oy0U?kgQV9 zpkcz>65`%I=&Uv;zR}EK#oLOHE{osQ%9I3AYtb(AOBUT>1dz$AA- zRdgT)3t*VlU}cI?a-Ni-$NO;{2krUAU0$MmwM37cR^*h-$mL>v@P