fucking finally

This commit is contained in:
Lars Noack 2022-12-09 15:50:44 +01:00
parent 5d5bdb3343
commit eb42920488
4 changed files with 29 additions and 10 deletions

View File

@ -50,7 +50,7 @@ cache.push([album_input, song_input, lyrics, additional_song])
# getting song by song ref # getting song by song ref
song_output_list = cache.pull_songs(song_ref=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] # song_output = song_output_list[0]
# print(song_output) # print(song_output)
# print("album id", song_output.album_ref) # print("album id", song_output.album_ref)

View File

@ -268,10 +268,13 @@ class Database:
url=source_row['url'] url=source_row['url']
) for source_row in source_rows] ) 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'] song_id = song_result['song_id']
return Song( song_obj = Song(
id_=song_id, id_=song_id,
title=song_result['title'], title=song_result['title'],
isrc=song_result['isrc'], isrc=song_result['isrc'],
@ -286,7 +289,14 @@ class Database:
album_ref=Reference(song_result['album_id']) 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) This function is used to get one song (including its children like Sources etc)
from one song id (a reference object) from one song id (a reference object)
@ -311,10 +321,14 @@ class Database:
return [self.get_song_from_row( return [self.get_song_from_row(
song_result=song_result, song_result=song_result,
exclude_independent_relations=exclude_independent_relations exclude_relations=exclude_relations
) for song_result in song_rows] ) 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_id = album_result['album_id']
album_obj = Album( album_obj = Album(
@ -329,17 +343,20 @@ class Database:
barcode=album_result['barcode'] barcode=album_result['barcode']
) )
if not exclude_independent_relations: print(exclude_relations)
if Song not in exclude_relations:
print("yay")
# getting the tracklist # getting the tracklist
tracklist: List[Song] = self.pull_songs( tracklist: List[Song] = self.pull_songs(
album_ref=Reference(id_=album_id), album_ref=Reference(id_=album_id),
exclude_independent_relations=True exclude_relations=new_exclude_relations
) )
album_obj.set_tracklist(tracklist=tracklist) album_obj.set_tracklist(tracklist=tracklist)
return album_obj 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 This function is used to get matching albums/releses
from one song id (a reference object) from one song id (a reference object)
@ -357,7 +374,7 @@ class Database:
return [self.get_album_from_row( return [self.get_album_from_row(
album_result=album_row, album_result=album_row,
exclude_independent_relations=exclude_independent_relations exclude_relations=exclude_relations
) for album_row in album_rows] ) for album_row in album_rows]

View File

@ -190,6 +190,8 @@ class Song(DatabaseObject):
self.album_ref = album_ref self.album_ref = album_ref
self.artist_refs = artist_refs self.artist_refs = artist_refs
self.album: Album = None
def __eq__(self, other): def __eq__(self, other):
if type(other) != type(self): if type(other) != type(self):
return False return False

BIN
test.db

Binary file not shown.