From 0fe7c70f218c1f054ea92dbe3d356d8ec0a4f7d5 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Tue, 13 Dec 2022 11:16:19 +0100 Subject: [PATCH] refa --- src/goof.py | 6 ++- src/music_kraken/database/new_database.py | 4 +- src/music_kraken/database/objects/song.py | 59 ++++++++++++---------- src/music_kraken/static_files/new_db.sql | 2 +- test.db | Bin 65536 -> 65536 bytes 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/src/goof.py b/src/goof.py index ec9a685..94aaf8a 100644 --- a/src/goof.py +++ b/src/goof.py @@ -50,12 +50,14 @@ song_input = Song( Source(src="youtube", url="https://youtu.be/dfnsdajlhkjhsd"), Source(src="musify", url="https://ln.topdf.de/Music-Kraken/") ], - album_ref=album_input.reference + album = album_input, + main_artist_list = [main_artist], + feature_artist_list = [feature_artist] ) additional_song = Song( title="A fcking Song", - album_ref=album_input.reference + album=album_input ) song_ref = song_input.reference diff --git a/src/music_kraken/database/new_database.py b/src/music_kraken/database/new_database.py index 1d14894..05cd37e 100644 --- a/src/music_kraken/database/new_database.py +++ b/src/music_kraken/database/new_database.py @@ -316,6 +316,9 @@ class Database: song_id = song_result['song_id'] + # maybee fetch album + album = None + song_obj = Song( id_=song_id, title=song_result['title'], @@ -329,7 +332,6 @@ class Database: ), sources=self.pull_sources(song_ref=Reference(id_=song_id)), lyrics=self.pull_lyrics(song_ref=Reference(id_=song_id)), - album_ref=Reference(song_result['album_id']) ) if Album not in exclude_relations and song_result['album_id'] is not None: diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index 5f2b406..f2fe82b 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -17,17 +17,17 @@ All Objects dependent class SongAttribute: - def __init__(self, song_ref: Reference = None): + def __init__(self, song = None): # the reference to the song the lyrics belong to - self.song_ref = song_ref + self.song = song - def add_song(self, song_ref: Reference): - self.song_ref = song_ref + def add_song(self, song): + self.song = song def get_ref_song_id(self): - if self.song_ref is None: + if self.song is None: return None - return self.song_ref.id + return self.song.reference.id def set_ref_song_id(self, song_id): self.song_ref = Reference(song_id) @@ -150,8 +150,9 @@ class Song(DatabaseObject): target: Target = None, lyrics: List[Lyrics] = None, metadata: dict = {}, - album_ref: Reference = None, - artist_refs: List[Reference] = None + album = None, + main_artist_list: list = [], + feature_artist_list: list = [] ) -> None: """ id: is not NECESARRILY the musicbrainz id, but is DISTINCT for every song @@ -176,31 +177,42 @@ class Song(DatabaseObject): sources = [] self.sources: List[Source] = sources for source in self.sources: - source.add_song(self.reference) + source.add_song(self) if target is None: target = Target() self.target: Target = target - self.target.add_song(self.reference) + self.target.add_song(self) if lyrics is None: lyrics = [] self.lyrics: List[Lyrics] = lyrics for lyrics_ in self.lyrics: - lyrics_.add_song(self.reference) + lyrics_.add_song(self) - self.album_ref = album_ref - self.artist_refs = artist_refs + self.album: Album = album - self._album: Album | None = None + self.main_artist_list = main_artist_list + self.feature_artist_list = feature_artist_list def __eq__(self, other): if type(other) != type(self): return False return self.id == other.id + def get_artist_credits(self) -> str: + feature_str = "" + if len(self.feature_artist_list) > 0: + feature_str = " feat. " + ", ".join([artist.name for artist in self.feature_artist_list]) + return ", ".join([artist.name for artist in self.main_artist_list]) + feature_str + def __str__(self) -> str: - return f"\"{self.title}\" by {', '.join(self.artist_names)}" + artist_credit_str = "" + artist_credits = self.get_artist_credits() + if artist_credits != "": + artist_credit_str = f" by {artist_credits}" + + return f"\"{self.title}\"{artist_credit_str}" def __repr__(self) -> str: return self.__str__() @@ -224,20 +236,12 @@ class Song(DatabaseObject): raise TypeError(f"length of a song must be of the type int not {type(length)}") self.length_ = length - def get_album_id(self) -> str | None: - if self.album_ref is None: + def get_album_id(self): + if self.album is None: return None - return self.album_ref.id + return self.album.id - def set_album(self, album): - if self.album_ref.id is not None: - if self.album_ref.id != album.id: - logger.warning(f"song already refers to different album, overriding reference.") - - self.album_ref = Reference(album.id) - self._album = album - - album = property(fget=lambda self: self._album, fset=set_album) + album_id: str = property(fget=get_album_id) length: int = property(fget=get_length, fset=set_length) @@ -338,7 +342,6 @@ class Artist(DatabaseObject): self.songs: List[ArtistSong] = [] self.album_refs: List[Album] = [] - self.song self.set_discography(discography) self.set_features(features) diff --git a/src/music_kraken/static_files/new_db.sql b/src/music_kraken/static_files/new_db.sql index b107bbf..70b83d5 100644 --- a/src/music_kraken/static_files/new_db.sql +++ b/src/music_kraken/static_files/new_db.sql @@ -33,7 +33,7 @@ CREATE TABLE Album date TEXT, country TEXT, barcode TEXT, - album_sort INT, + albumsort INT, is_split BOOLEAN NOT NULL DEFAULT 0 ); diff --git a/test.db b/test.db index 5fa740deaab7c7f41faf22537a1609db4a43d166..a34f49906b967a5490fdaa9095c4644414b6f130 100644 GIT binary patch delta 1809 zcmcIkO>Epm6kcb4y!QUMk%+coTg4%PG$f zw^z8^o-B!6{cGd2maiw352}xKyE3o;p#i;6{#?tcos#(O3$3L0ZyIW2YD(Gfi7V<` zf|Q%ODbE{MuUuVii6`oq_|~{6Z&%+Rud9v8N#&D|g;~D5{&$tRy4EsR!Qf6}7v!I3vk!hYgF?)>f96R{yFpFE78j6t1*POZI+Fe5GFyY1wVw zsj7|fai#xCLZVH!H0*O0YvRl53t~>6scw_4A!KX${gyb^Orh24g?hiGi(ks;m5L~8 zN8(7oD1OrFg=+trDxPZRm9o(ERMEuu`pbEJt}O2Gpk|ASLuI?-^Np|mSwi8pBb+c&cv$G|!TD_DuYWEdwPEi|U zW6Gz2IH~`5F6j`u@eE?{UK|*EB`0SH!%0WYS)+GzL=9(hxm@V`mK9r&f*5-NzzD}6 zKz0l$jbb}yj)g6_WOBOE-o9LQ6d~qZT?xC3)*RxDKGLsLr|7!lv z-iOxn#_Dw5O*c_=C!gG28>h3rU8hd z=K~x$1O!yB*Ru$-FygTjQ1NK-rRglFhxZ>E?`9ZtNIXmDniO9#j&sIwI(p-w0bf_D zA&|M@DQ6KQecJogn9AUW!@HW%qaLL$m->5lfB>d20ul5r;QEMRA3B73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