From 265f7228bc13497d2d6424f69458086f28720301 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 8 Dec 2022 09:10:26 +0100 Subject: [PATCH] started fetching of album --- src/goof.py | 4 +++ src/music_kraken/database/new_database.py | 42 +++++++++++++++++++++- src/music_kraken/database/objects/song.py | 9 ++++- test.db | Bin 65536 -> 65536 bytes 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/goof.py b/src/goof.py index ce47741..7dcb3b1 100644 --- a/src/goof.py +++ b/src/goof.py @@ -58,3 +58,7 @@ print(len(song_output_list), song_output_list) # getting song by album ref song_output_list = cache.pull_songs(album_ref=album_input.reference) print(len(song_output_list), song_output_list) + +# getting album +album_output_list = cache.pull_albums(album_ref=album_input.ref) +print(album_output_list[0]) diff --git a/src/music_kraken/database/new_database.py b/src/music_kraken/database/new_database.py index cacb797..4b25159 100644 --- a/src/music_kraken/database/new_database.py +++ b/src/music_kraken/database/new_database.py @@ -38,6 +38,11 @@ SELECT id, text, language, song_id FROM Lyrics WHERE {where}; """ +ALBUM_QUERY = """ +SELECT Album.id AS album_id, title, copyright, album_status, year, date, country, barcode +FROM Album +WHERE {where}; +""" class Database: @@ -312,8 +317,43 @@ class Database: return [self.get_song_from_row(song_result=song_result) for song_result in song_rows] + def get_album_from_row(self, album_result) -> Album: + album_id = album_result['album_id'] + + album_obj = Album( + id_=album_id, + title=album_result['title'], + copyright_=album_result['copyright'], + album_status=album_result['album_status'], + language=album_result['language'], + year=album_result['year'], + date=album_result['date'], + country=album_result['country'], + 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) + + return album_obj + def pull_albums(self, album_ref: Reference = None) -> List[Album]: - pass + """ + This function is used to get matching albums/releses + from one song id (a reference object) + :param album_ref: + :return requested_album_list: + """ + where = "1=1" + if album_ref is not None: + where = f"Album.id=\"{album_ref.id}\"" + + query = ALBUM_QUERY.format(where=where) + self.cursor.execute(query) + + album_rows = self.cursor.fetchall() if __name__ == "__main__": cache = Database("") diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index 0498593..e813bc9 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -264,13 +264,20 @@ class Album(DatabaseObject): self.barcode: str = barcode self.song_ref_list: List[Reference] = song_ref_list + self.track_names = {} - def add_song(self, song_ref: Reference): + 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: return self.song_ref_list.append(song_ref) + if song_ref.id not in self.track_names: + self.track_names[song_ref.id] = None + diff --git a/test.db b/test.db index 62e65919c01879ea254bac03e6f42f5335d19c92..bcddebcbd8fb2c0b9c756ab347bba2991cf4bbf0 100644 GIT binary patch delta 1301 zcmcJOKZ{dA6vbbXjT%88TSrL1;97Xe{ChKVK}@W5L6P?X=I`#JCSbB)m)LAAybrLg zosx)^#o7zoT54}$Z{wIR;57D^bI&>Vch~E^^?L8abg+_6%V-=zC1?OqX%3d@07`jB zrKBWy^Kcm5^OM=p@Y#HJR9TOjumGAF3PPa(&A9>e%o$~)l9r#euGEvFU88bnnd4AZ zjDSEZ!J@NZB`4CLsjzKi^JUN<<*06^+ww5SZ~LHA_x`=x$PMY2x6uSIP=N^2fS}xh zp^^X%Oft_+B+fSvCI?S*1W#L6>;9u_z1kb2v9b<$h$*>GEm_VyNJB(mu2Ryl=F{ZP zC`WZO{a8NEu(`{fvw8F6>o}|O?XT6(GHY`4wpXq+Iucx^0l7+SNU77QD+f$|hDS#S)t?eW(%<&>5ZH38_ZIt!1(4Ufy46u2GSMn~gLv z7bFAg(m!KB!KGEoRdE>>%P`AOoVZz=#-vU@S^amd9Zc zhRwz0EtaEvy(o%Kc~+EX<@@s6c7OP~T;1)|t(>5pzk@kJcUQ|Xe47uH#0k*ug&LcAGSAU7C8na2`Hlu1a%ZF4F&{r zL=c678~$*V{PX?k?&#UUbQdM@idzGL1)md8g2g1kD;9YS(j}etJ6D=X)orNc8dWl2 zsLQbg6JSmTPouEP@W8uCw_i4fnG$(dRd`pC)%U zOH>!zAM3{jHZS`wsl0gdbzFpe`D^yGE{a^d8PqcuwKv>F2%HiSN)oVG4 zSKCx#_>yXglmD=v=Ra<4N*9y~j)1oqKm