From 5d5bdb334361d03a7b18330910a8a3f05d4ac5ce Mon Sep 17 00:00:00 2001 From: Hellow Date: Thu, 8 Dec 2022 09:28:28 +0100 Subject: [PATCH] semi completed pull function for album --- src/.fuse_hidden0000823600000006 | Bin 65536 -> 0 bytes src/.fuse_hidden0000846000000007 | Bin 65536 -> 0 bytes src/goof.py | 6 +- src/music_kraken/database/new_database.py | 48 ++++++++------ src/music_kraken/database/objects/song.py | 74 ++++++++-------------- src/test.db | Bin 65536 -> 65536 bytes 6 files changed, 57 insertions(+), 71 deletions(-) delete mode 100644 src/.fuse_hidden0000823600000006 delete mode 100644 src/.fuse_hidden0000846000000007 diff --git a/src/.fuse_hidden0000823600000006 b/src/.fuse_hidden0000823600000006 deleted file mode 100644 index a4a79ffa1b59218bfd37c7e2c3c551bb3b01664a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 65536 zcmeI*&2Q6Y90zbarA?c@1P&;wrb!RtKr3)#=cSG}F$iE#M@XTK*|;q7%ag?5IGyb< zdYRNtJM6Ukj?)giao_)drX42jwtr*VX^-usZ2}ax6H+R^j}qJQz^E@`SACqi9 zs@VZ0t)AD_15)J9b3D)8B!uI*CH6kg-orG@Ce95%urYsR`fZa-+}anPFJ}MYva^@C z>_YbUMR)1%g;$H!h19~&nLpKOfQ)eCGtI5K(u_Lf?0sH9Q7Ra424jLb@gL`e_JHEoN1xV3R_qu#hS%!t+% z=CGOSJ#}lCad&e|-MCjL_thsW!_uo{OTDXZsrB3HcD$Jt+gg2NiQ#HTi$rt7GMUxA zhfC?)rAz$&vna6bp4*P&I-JUmgmpOoAS#~~I(1Nk!XrBvZsUK1)L2O8mY4bOrlOE) zyPj?O@o;e@lz84CjHpuLS{l?1scMbQ=0=^Bd7#!C8Gf1E)aOS2G<7p`U!EG)$f&+mPlPUmttet-GM0UjQ$vm;#5K|R)D5^4=w zz|jLgdE~3JGr8-zx7B{MTTLk%&3V&N)$iSiBZ<#a(QsxomT2BsFoV<2adl6kbC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~(PV3~3bJ6V7c8M9nk7ML(Uu^K>t#!lO~n#h zW9zr*jz@jpeol!KZHl@{uK&aS|5WxRd;XsdkRSj72tWV=5P$##AOHafKmY;|m;`~9 zDUDBZ^C1=X|0lVNfZzX{glfe;KmY;|fB*y_009U<00Izz00iEz0IvVvuP@dP0SG_< V0uX=z1Rwwb2tWV=5SRpk{{SF>XB7Yd diff --git a/src/.fuse_hidden0000846000000007 b/src/.fuse_hidden0000846000000007 deleted file mode 100644 index 8043063737df059bf3955a6ef5bc0bdeefb599a9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 65536 zcmeI*%}?8A90zbaDFnic%K=4bn)Gx%6x5o;d3UFdL7P^rG_(+R>t)C`~HYd+F_b@+Mh9LmpzZ20AVdN>_XJ9mDr9SKk@VXJdaK6#|fK{ z)|`+MyW{WZAt?!$1yK|}CPWYfi9Ii~XMY%DGne`=*i<|=|F&64Sp4*pDd{gk8v8(y zrlen{I@5nnzMfi{Oi%uh{dMBEiJ!(_XMY^~nWv6le=<7Ja`rbw%PI8aa>1p(m+^8%MYUpSf+Ca)yq6kK)#Lt5mIY1lbf3pzfMOX zt?l`a8N}nMfl%UQy)dFmiEF7>H)L6Bt#7S1S)K=tW{W)BSbea(@q|}JY#q`UVJ`=1 zH9qTArmK7HuHL3R1}z26!?ZqU;GHVxx(cEF&wEN-BEgSc(}XZ*I~9!5!;>n+mM*4AR0T|L}>GeGaX zwdU$0tr4$$27`&y4B}X}it%*vdN#qzO1$#K{`;9sE|(Jz=8o;)d~Y2a;EHzY6D=m8 zR=))t-|>@2zA!eLyOn!e?MKDhQliPYKN3~_{!$!Ce3XjDql2+T%T5H-JN%qh_ar)I zdHT*_<+H{)dYW~7L}BHNwwO8a(oqS&sr8OIUEide9X`G^P{MfGi4yW=m6Y5!`P$LI zcf}KpwClV5)M!sVk!(^w)EzI}V=FP1!&Gvoad%l;YmveYmLkjKaK&2%B7a1jkT?Oc zsO@-cA9eSLPM+&7+qZ%!#7Hk*5N~~DeSNL5-2C_ZEAj5pZ#aDI^EIC9mrkplSb0l{ zrz87IVkS2`D<0^*+VR?(?0B3yQ8QlqM7<=eljH3sj?W3=YC1Yty3}j);|Evg12gU| zVz7=!b{yAr0%~?VDKy>-Bm~RqcxUn6fJecPQQER}jK&N;W%gH*`8)>iaBW*aHIuAOHafKmY;| zfB*y_009U<00KiMa4oHkC%H7h`~OqYj39l>Mi?Lf0SG_<0uX=z1Rwwb2tWV=?~1_l zR7RUy9~;+-x@A~)r6{WvHY!(aMb_1NL9Q0+RnxMob;~e!x`AWwZHM7*a5JBGy~VJz zYuSqy%|Bo%rhMPmpHVNLH$CKs%d!M0ne%6i$>Wm;1eQ&kF8 zv#9KKx?$I#{S8Mi7Y&-XY%j3%r|$N%r`v&*WV5{gKP9~qq*u5D;9Y6rh!X-3fB*y_ z009U<00Izz00b_)zF@uG?5F?n>;FkB z80$d*0uX=z1Rwwb2tWV=5P$##E{*{I{r@DFAo%_NIRC#m^@fr_00Izz00bZa0SG_< z0uX=z1kNJB&;OJ3|MUC*)6;(l(s$BLHo*V^2tWV=5P$##AOHafKmY;|7&3v+(<53i zBba8bS}NORxmYYvxy*0IH|kbdR?C&DX(*;%Hw)o54JgrlN&D7=`F^UTT2tWV=5P$##AOHafKmY;|7%GAJv?eCG zP?6> Song: + def get_song_from_row(self, song_result, exclude_independent_relations: bool = False) -> Song: song_id = song_result['song_id'] return Song( @@ -286,17 +286,18 @@ class Database: album_ref=Reference(song_result['album_id']) ) - def pull_songs(self, song_ref: Reference = None, album_ref: Reference = None) -> List[Song]: + def pull_songs(self, song_ref: Reference = None, album_ref: Reference = None, exclude_independent_relations: bool = False) -> List[Song]: """ This function is used to get one song (including its children like Sources etc) from one song id (a reference object) :param song_ref: + :param album_ref: + :param exclude_independent_relations: + This excludes all relations from being fetched like for example the Album of the Song. + This is necessary when adding the Song as subclass as e.g. an Album (as tracklist or whatever). :return requested_song: """ - """ - if song_ref is None: - raise ValueError("The Song ref doesn't point anywhere. Remember to use the debugger.") - """ + where = "1=1" if song_ref is not None: where = f"Song.id=\"{song_ref.id}\"" @@ -307,17 +308,13 @@ class Database: self.cursor.execute(query) song_rows = self.cursor.fetchall() - """ - if len(song_rows) == 0: - logger.warning(f"No song found for the id {song_ref.id}") - return Song() - if len(song_rows) > 1: - logger.warning(f"Multiple Songs found for the id {song_ref.id}. Defaulting to the first one.") - """ - return [self.get_song_from_row(song_result=song_result) for song_result in song_rows] + return [self.get_song_from_row( + song_result=song_result, + exclude_independent_relations=exclude_independent_relations + ) for song_result in song_rows] - def get_album_from_row(self, album_result) -> Album: + def get_album_from_row(self, album_result, exclude_independent_relations: bool = False) -> Album: album_id = album_result['album_id'] album_obj = Album( @@ -332,14 +329,17 @@ class Database: barcode=album_result['barcode'] ) - # getting the tracklist - tracklist: List[Song] = self.pull_songs(album_ref=Reference(id_=album_id)) - for track in tracklist: - album_obj.add_song(track.reference, name=track.title) + if not exclude_independent_relations: + # getting the tracklist + tracklist: List[Song] = self.pull_songs( + album_ref=Reference(id_=album_id), + exclude_independent_relations=True + ) + album_obj.set_tracklist(tracklist=tracklist) return album_obj - def pull_albums(self, album_ref: Reference = None) -> List[Album]: + def pull_albums(self, album_ref: Reference = None, exclude_independent_relations: bool = False) -> List[Album]: """ This function is used to get matching albums/releses from one song id (a reference object) @@ -355,5 +355,11 @@ class Database: album_rows = self.cursor.fetchall() + return [self.get_album_from_row( + album_result=album_row, + exclude_independent_relations=exclude_independent_relations + ) for album_row in album_rows] + + if __name__ == "__main__": cache = Database("") diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index e813bc9..d1e31a0 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -11,11 +11,11 @@ from .database_object import ( Reference ) - """ All Objects dependent """ + class SongAttribute: def __init__(self, song_ref: Reference = None): # the reference to the song the lyrics belong to @@ -190,6 +190,11 @@ class Song(DatabaseObject): self.album_ref = album_ref self.artist_refs = artist_refs + def __eq__(self, other): + if type(other) != type(self): + return False + return self.id == other.id + def __str__(self) -> str: return f"\"{self.title}\" by {', '.join(self.artist_names)}" @@ -227,6 +232,7 @@ class Song(DatabaseObject): All objects dependend on Album """ + class Album(DatabaseObject): """ -------DB-FIELDS------- @@ -240,18 +246,18 @@ class Album(DatabaseObject): barcode TEXT, song_id BIGINT, """ + def __init__( - self, - id_: str = None, - title: str = None, - copyright_: str = None, - album_status: str = None, - language: str = None, - year: str = None, - date: str = None, - country: str = None, - barcode: str = None, - song_ref_list: List[Reference] = [] + self, + id_: str = None, + title: str = None, + copyright_: str = None, + album_status: str = None, + language: str = None, + year: str = None, + date: str = None, + country: str = None, + barcode: str = None, ) -> None: DatabaseObject.__init__(self, id_=id_) self.title: str = title @@ -263,41 +269,13 @@ class Album(DatabaseObject): self.country: str = country self.barcode: str = barcode - self.song_ref_list: List[Reference] = song_ref_list - self.track_names = {} + self.tracklist: List[Song] = [] - def add_song(self, song_ref: Reference, name: str = None): - if name is not None: - self.track_names[song_ref.id] = name - - for existing_song_ref in self.song_ref_list: - if song_ref == existing_song_ref: + def set_tracklist(self, tracklist: List[Song]): + self.tracklist = tracklist + + def add_song(self, song: Song): + for existing_song in self.tracklist: + if existing_song == song: return - self.song_ref_list.append(song_ref) - - if song_ref.id not in self.track_names: - self.track_names[song_ref.id] = None - - - - - -if __name__ == "__main__": - """ - Example for creating a Song object - """ - - song = Song( - title="Vein Deep in the Solution", - release_name="One Final Action", - target=Target(file="~/Music/genre/artist/album/song.mp3", path="~/Music/genre/artist/album"), - metadata={ - "album": "One Final Action" - }, - lyrics=[ - Lyrics(text="these are some depressive lyrics", language="en") - ], - sources=[ - Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd") - ] - ) + self.tracklist.append(song) diff --git a/src/test.db b/src/test.db index c19a7131864d1d30cf2373aee8ec65aef01e2396..5c1072412d32cbfed15c5df7e2183797903235a1 100644 GIT binary patch delta 1836 zcma)6&2QX96t|s^-F0^}q*Ai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