This commit is contained in:
Lars Noack 2022-12-16 12:53:05 +01:00
parent 933eddeea4
commit 0c2b604b92
3 changed files with 27 additions and 15 deletions

View File

@ -325,9 +325,9 @@ class Database:
table = "SongArtist" table = "SongArtist"
wheres = [] wheres = []
if song_ref is not None: if song_ref is not None:
wheres.append("song_id=\"{song_ref.id}\"") wheres.append(f"song_id=\"{song_ref.id}\"")
if artist_ref is not None: if artist_ref is not None:
wheres.append("artist_id=\"{artist_ref.id}\"") wheres.append(f"artist_id=\"{artist_ref.id}\"")
where_str = "" where_str = ""
if len(wheres) > 0: if len(wheres) > 0:
where_str = "WHERE " + " AND ".join(wheres) where_str = "WHERE " + " AND ".join(wheres)
@ -349,7 +349,7 @@ class Database:
new_exclude_relations.add(Song) new_exclude_relations.add(Song)
return Artist( return Artist(
id_=artist_row['artist_id'], id_=artist_row['artist_id'],
name=artist_row['name'] name=artist_row['artist_name']
) )
def pull_artists(self, artist_ref: Reference = None, exclude_relations: set = None) -> List[Artist]: def pull_artists(self, artist_ref: Reference = None, exclude_relations: set = None) -> List[Artist]:
@ -398,11 +398,10 @@ class Database:
main_artists = [] main_artists = []
feature_artists = [] feature_artists = []
print(exclude_relations)
if Artist not in exclude_relations: if Artist not in exclude_relations:
for song_ref, artist_ref, is_feature in self.pull_artist_song(song_ref=song_id): for song_ref, artist_ref, is_feature in self.pull_artist_song(song_ref=Reference(song_id)):
print(artist_ref) print(artist_ref)
if not is_feature: if is_feature:
feature_artists.extend(self.pull_artists(artist_ref=artist_ref)) feature_artists.extend(self.pull_artists(artist_ref=artist_ref))
else: else:
main_artists.extend(self.pull_artists(artist_ref=artist_ref)) main_artists.extend(self.pull_artists(artist_ref=artist_ref))

View File

@ -320,14 +320,6 @@ All objects dependent on Artist
""" """
class ArtistSong(Song):
"""
A subclass of Song with the additional attribute is_feature, which
makes only sense when in/from the Artist class
"""
is_feature: bool = False
class Artist(DatabaseObject): class Artist(DatabaseObject):
def __init__( def __init__(
self, self,
@ -340,7 +332,13 @@ class Artist(DatabaseObject):
self.name: str | None = name self.name: str | None = name
self.songs: List[ArtistSong] = [] self.main_songs = []
self.feature_songs = []
self.main_albums = []
self.feature_albums = []
self.songs: List[Song] = []
self.album_refs: List[Album] = [] self.album_refs: List[Album] = []
self.set_discography(discography) self.set_discography(discography)
@ -349,6 +347,21 @@ class Artist(DatabaseObject):
def __str__(self): def __str__(self):
return self.name or "" return self.name or ""
def add_song(self, song: Song, is_feature: bool):
"""
it is reccomendet, that the song object already contains the album,
else you will have to add it youreself
"""
if is_feature:
self.feature_songs.append(song)
if song.album is not None:
self.feature_albums.append(song.album)
else:
self.main_songs.append(song)
if song.album is not None:
self.main_albums(song.album)
def add_album(self, album: Album): def add_album(self, album: Album):
self.album_refs.append(album) self.album_refs.append(album)

BIN
test.db

Binary file not shown.