started fetching of album

This commit is contained in:
Lars Noack 2022-12-08 09:10:26 +01:00
parent 91f663aae1
commit 265f7228bc
4 changed files with 53 additions and 2 deletions

View File

@ -58,3 +58,7 @@ print(len(song_output_list), song_output_list)
# getting song by album ref # getting song by album ref
song_output_list = cache.pull_songs(album_ref=album_input.reference) song_output_list = cache.pull_songs(album_ref=album_input.reference)
print(len(song_output_list), song_output_list) 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])

View File

@ -38,6 +38,11 @@ SELECT id, text, language, song_id
FROM Lyrics FROM Lyrics
WHERE {where}; WHERE {where};
""" """
ALBUM_QUERY = """
SELECT Album.id AS album_id, title, copyright, album_status, year, date, country, barcode
FROM Album
WHERE {where};
"""
class Database: class Database:
@ -312,8 +317,43 @@ class Database:
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) 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]: 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__": if __name__ == "__main__":
cache = Database("") cache = Database("")

View File

@ -264,13 +264,20 @@ class Album(DatabaseObject):
self.barcode: str = barcode self.barcode: str = barcode
self.song_ref_list: List[Reference] = song_ref_list 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: for existing_song_ref in self.song_ref_list:
if song_ref == existing_song_ref: if song_ref == existing_song_ref:
return return
self.song_ref_list.append(song_ref) self.song_ref_list.append(song_ref)
if song_ref.id not in self.track_names:
self.track_names[song_ref.id] = None

BIN
test.db

Binary file not shown.