From 23b3ab0101939d0d79d2b75703c51e25efe550fb Mon Sep 17 00:00:00 2001 From: Hellow Date: Fri, 16 Dec 2022 16:59:21 +0100 Subject: [PATCH] afsafdf --- src/.fuse_hidden000083f100000001 | Bin 0 -> 65536 bytes src/goof.py | 10 ++ src/music_kraken/database/new_database.py | 135 ++++++++++++++++++---- src/music_kraken/database/objects/song.py | 121 +++++++++---------- src/test.db | Bin 65536 -> 65536 bytes 5 files changed, 178 insertions(+), 88 deletions(-) create mode 100644 src/.fuse_hidden000083f100000001 diff --git a/src/.fuse_hidden000083f100000001 b/src/.fuse_hidden000083f100000001 new file mode 100644 index 0000000000000000000000000000000000000000..6a74b7527f6663d009eb4bc6c93db6bdcefba700 GIT binary patch literal 65536 zcmeI*-*4N-0S9nO^6$i9@{kI~UasgvY$O+v6e*D{y4Goxz>8xqw%9g6G2=)cWi~S9 zl2ld$`+>OYfW2%FeaqYaf&lvi_Pn>f2K!6)wjD`Pvb;H=i#bTTFJY6?kv!gg?sO7) z{IUCRGe|h`2hjmbNK?8hRVvcQgh-O~j`+VS{)=HjyqGE8h-u}->$6_IBi;V|XUpB^twzc1IWB$pmtezBxpy0!GLMY=Sz@W(}IJ`%GrKmY;|fWZH^z|$|~`TBeB zRgQm~FsIMg`_AxSJxYQ&Iq~x9Cp(?>ZijT&?`(F+i5W|)OC%duy53&k1^EFBKJFwR*N{+$WG^OXQ#9ENoP0T*lOUd6|qgNQN%pGN*0=~ zv$S@+a%H~$?z@$5f1PD-cM$gS+)ZA|Q<nkgj zryt}cpJgD&S)L-v!$us_MNHQ1?)KismRSBlXRAwozO(UQedkeHoOvEXc97+@+xeoq zw03iOuKv+VMG8WXe-nS*7e9vf*f1Gn@AvZU?5X+m%G2&rmcDOmS^74QqQH&w@ujKs ze8o~#QeYjW9=5(bxEW{~G)PtB*7 zpWdI(4359f47x1p@gyHFOc~^1rwm55@Kt5x2mMpIJY>m!Dl*Y1@;!>u-r9I*cXE<* zWPR~vS-Bo&yU+8woV8-P6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9AnpGzb4(!X|1WbmAn*V8B>6A0 z_j+K dZ{!975P$##AOHafKmY;|fB*y_0D)w^jfE literal 0 HcmV?d00001 diff --git a/src/goof.py b/src/goof.py index 14dbc4d..93957c2 100644 --- a/src/goof.py +++ b/src/goof.py @@ -21,6 +21,8 @@ main_artist = Artist( name="I'm in a coffin" ) +artist_ref = main_artist.reference + split_artist = Artist( name="split" ) @@ -94,3 +96,11 @@ div() album_output_list = cache.pull_albums(song_ref=song_ref) print(album_output_list) print("len of album ->", len(album_output_list[0]), album_output_list[0], sep=" | ") + +# get artist +div() +artist_output = cache.pull_artists(artist_ref=artist_ref)[0] +print(artist_output) +print(artist_output.main_albums) +print(artist_output.main_songs) +print(artist_output.feature_songs) diff --git a/src/music_kraken/database/new_database.py b/src/music_kraken/database/new_database.py index b36213f..c06c9c8 100644 --- a/src/music_kraken/database/new_database.py +++ b/src/music_kraken/database/new_database.py @@ -148,6 +148,12 @@ class Database: self.cursor.execute(query, values) self.connection.commit() + for song in album.tracklist: + self.push_song(song) + for artist in album.artists: + self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference) + self.push_artist(artist) + def push_song(self, song: Song): # ADDING THE DATA FOR THE SONG OBJECT """ @@ -184,7 +190,7 @@ class Database: for main_artist in song.main_artist_list: self.push_artist_song(artist_ref=Reference(main_artist.id), song_ref=Reference(song.id), is_feature=False) - self.push_artist(artist=main_artist) + self.push_artist(artist=main_artist) for feature_artist in song.feature_artist_list: self.push_artist_song(artist_ref=Reference(feature_artist.id), song_ref=Reference(song.id), is_feature=True) @@ -257,6 +263,24 @@ class Database: self.cursor.execute(query, values) self.connection.commit() + def push_artist_album(self, artist_ref: Reference, album_ref: Reference): + table = "AlbumArtist" + # checking if already exists + query = f"SELECT * FROM {table} WHERE album_id=\"{album_ref.id}\" AND artist_id=\"{artist_ref.id}\"" + self.cursor.execute(query) + if len(self.cursor.fetchall()) > 0: + # join already exists + return + + query = f"INSERT OR REPLACE INTO {table} (album_id, artist_id) VALUES (?, ?);" + values = ( + album_ref.id, + artist_ref.id + ) + + self.cursor.execute(query, values) + self.connection.commit() + def push_artist(self, artist: Artist): table = "Artist" query = f"INSERT OR REPLACE INTO {table} (id, name) VALUES (?, ?);" @@ -268,6 +292,16 @@ class Database: self.cursor.execute(query, values) self.connection.commit() + for song in artist.feature_songs: + self.push_artist_song(artist_ref=artist.reference, song_ref=song.reference, is_feature=True) + self.push_song(song=song) + + for song in artist.main_songs: + self.push_artist_song(artist_ref=artist.reference, song_ref=song.reference, is_feature=False) + self.push_song(song=song) + + for album in artist.main_albums: + self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference) def pull_lyrics(self, song_ref: Reference = None, lyrics_ref: Reference = None) -> List[Lyrics]: """ @@ -331,7 +365,7 @@ class Database: where_str = "" if len(wheres) > 0: where_str = "WHERE " + " AND ".join(wheres) - + query = f"SELECT * FROM {table} {where_str};" self.cursor.execute(query) joins = self.cursor.fetchall() @@ -342,17 +376,71 @@ class Database: bool(join["is_feature"]) ) for join in joins] - def get_artist_from_row(self, artist_row, exclude_relations: set = None) -> Artist: + def pull_artist_album(self, album_ref: Reference = None, artist_ref: Reference = None) -> List[tuple]: + table = "AlbumArtist" + wheres = [] + if album_ref is not None: + wheres.append(f"album_id=\"{album_ref.id}\"") + if artist_ref is not None: + wheres.append(f"artist_id=\"{artist_ref.id}\"") + where_str = "" + if len(wheres) > 0: + where_str = "WHERE " + " AND ".join(wheres) + + query = f"SELECT * FROM {table} {where_str};" + self.cursor.execute(query) + joins = self.cursor.fetchall() + + return [( + Reference(join["album_id"]), + Reference(join["artist_id"]) + ) for join in joins] + + def get_artist_from_row(self, artist_row, exclude_relations: set = None, flat: bool = False) -> Artist: if exclude_relations is None: exclude_relations = set() new_exclude_relations: set = set(exclude_relations) - new_exclude_relations.add(Song) - return Artist( - id_=artist_row['artist_id'], + new_exclude_relations.add(Artist) + + artist_id = artist_row['artist_id'] + + artist_obj = Artist( + id_=artist_id, name=artist_row['artist_name'] ) + if flat: + return artist_obj + + # fetch songs :D + for song_ref, _, is_feature in self.pull_artist_song(artist_ref=Reference(id_=artist_id)): + new_songs = self.pull_songs(song_ref=song_ref, exclude_relations=new_exclude_relations) + if len(new_songs) < 1: + continue + new_song = new_songs[0] + + if is_feature: + artist_obj.feature_songs.append(new_song) + else: + artist_obj.main_songs.append(new_song) + + # fetch albums + for album_ref, _ in self.pull_artist_album(artist_ref=Reference(id_=artist_id)): + new_albums = self.pull_albums(album_ref=album_ref, exclude_relations=new_exclude_relations) + if len(new_albums) < 1: + continue + artist_obj.main_albums.append(new_albums[0]) + + return artist_obj + + def pull_artists(self, artist_ref: Reference = None, exclude_relations: set = None, flat: bool = False) -> List[Artist]: + """ + + :param artist_ref: + :param exclude_relations: + :param flat: if it is true it ONLY fetches the artist data + :return: + """ - def pull_artists(self, artist_ref: Reference = None, exclude_relations: set = None) -> List[Artist]: where = "1=1" if artist_ref is not None: where = f"Artist.id=\"{artist_ref.id}\"" @@ -362,10 +450,10 @@ class Database: artist_rows = self.cursor.fetchall() return [( - self.get_artist_from_row(artist_row) + self.get_artist_from_row(artist_row, exclude_relations=exclude_relations, flat=flat) ) for artist_row in artist_rows] - def get_song_from_row(self, song_result, exclude_relations: set = set()) -> Song: + def get_song_from_row(self, song_result, exclude_relations: set = None) -> Song: if exclude_relations is None: exclude_relations = set() new_exclude_relations: set = set(exclude_relations) @@ -396,19 +484,18 @@ class Database: if len(album_obj) > 0: song_obj.album = album_obj[0] + flat_artist = Artist in exclude_relations + main_artists = [] feature_artists = [] - if Artist not in exclude_relations: - for song_ref, artist_ref, is_feature in self.pull_artist_song(song_ref=Reference(song_id)): - print(artist_ref) - if is_feature: - feature_artists.extend(self.pull_artists(artist_ref=artist_ref)) - else: - main_artists.extend(self.pull_artists(artist_ref=artist_ref)) - - song_obj.main_artist_list = main_artists - song_obj.feature_artist_list = feature_artists + for song_ref, artist_ref, is_feature in self.pull_artist_song(song_ref=Reference(song_id)): + if is_feature: + feature_artists.extend(self.pull_artists(artist_ref=artist_ref, flat=flat_artist)) + else: + main_artists.extend(self.pull_artists(artist_ref=artist_ref, flat=flat_artist)) + song_obj.main_artist_list = main_artists + song_obj.feature_artist_list = feature_artists return song_obj @@ -472,9 +559,17 @@ class Database: ) album_obj.set_tracklist(tracklist=tracklist) + flat_artist = Artist in exclude_relations + for _, artist_ref in self.pull_artist_album(album_ref=Reference(id_=album_id)): + artists = self.pull_artists(artist_ref, flat=flat_artist, exclude_relations=new_exclude_relations) + if len(artists) < 1: + continue + album_obj.artists.append(artists[0]) + return album_obj - def pull_albums(self, album_ref: Reference = None, song_ref: Reference = None, exclude_relations: set = None) -> List[Album]: + def pull_albums(self, album_ref: Reference = None, song_ref: Reference = None, exclude_relations: set = None) -> \ + List[Album]: """ This function is used to get matching albums/releses from one song id (a reference object) diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index 9932a53..c424fe2 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -17,7 +17,7 @@ All Objects dependent class SongAttribute: - def __init__(self, song = None): + def __init__(self, song=None): # the reference to the song the lyrics belong to self.song = song @@ -150,7 +150,7 @@ class Song(DatabaseObject): target: Target = None, lyrics: List[Lyrics] = None, metadata: dict = {}, - album = None, + album=None, main_artist_list: list = [], feature_artist_list: list = [] ) -> None: @@ -293,6 +293,7 @@ class Album(DatabaseObject): self.albumsort: int | None = albumsort self.tracklist: List[Song] = [] + self.artists: List[Artist] = [] def __str__(self) -> str: return f"Album: \"{self.title}\"" @@ -321,94 +322,78 @@ All objects dependent on Artist class Artist(DatabaseObject): + """ + main_songs + feature_song + + albums + """ + def __init__( self, id_: str = None, name: str = None, - discography: List[Album] = [], - features: List[Song] = [] + main_songs: List[Song] = None, + feature_songs: List[Song] = None, + main_albums: List[Song] = None ): DatabaseObject.__init__(self, id_=id_) + if main_albums is None: + main_albums = [] + if feature_songs is None: + feature_songs = [] + if main_songs is None: + main_songs = [] + self.name: str | None = name - self.main_songs = [] - self.feature_songs = [] + self.main_songs = main_songs + self.feature_songs = feature_songs - self.main_albums = [] - self.feature_albums = [] - - self.songs: List[Song] = [] - self.album_refs: List[Album] = [] - - self.set_discography(discography) - self.set_features(features) + self.main_albums = main_albums def __str__(self): 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 - """ + def __repr__(self): + return self.__str__() - 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): - self.album_refs.append(album) - - for song in album.tracklist: - song.__class__ = ArtistSong - song.is_feature = False - - self.songs.append(song) - - def set_discography(self, discography: List[Album]): - """ - :param discography: - :return: - """ - for album in discography: - self.add_album(album) - - def get_discography(self) -> List[Album]: - flat_copy_discography = self.discography.copy() + def get_features(self) -> Album: feature_release = Album( title="features", copyright_=self.name, - album_status="dynamically generated", + album_status="dynamic", is_split=True, albumsort=666, dynamic=True ) - for song in self.songs: - if song.is_feature: - feature_release.add_song(song) + for feature in self.feature_songs: + feature_release.add_song(feature) + + return feature_release + + def get_songs(self) -> Album: + song_release = Album( + title="song collection", + copyright_=self.name, + album_status="dynamic", + is_split=False, + albumsort=666, + dynamic=True + ) + for song in self.main_songs: + song_release.add_song(song) + for song in self.feature_songs: + song_release.add_song(song) + return song_release + + def get_discography(self) -> List[Album]: + flat_copy_discography = self.discography.copy() + flat_copy_discography.append(self.get_features()) - flat_copy_discography.append(feature_release) return flat_copy_discography - def set_features(self, feature_tracks: List[Song]): - for song in feature_tracks: - song.__class__ = ArtistSong - song.is_feature = True - - self.songs.append(song) - - def get_features(self) -> List[ArtistSong]: - feature_releases = [] - for song in self.songs: - if song.is_feature: - feature_releases.append(song) - return feature_releases - - discography = property(fget=get_discography, fset=set_discography) - features = property(fget=get_features, fset=set_features) + discography: List[Album] = property(fget=get_discography) + features: Album = property(fget=get_features) + songs: Album = property(fget=get_songs) diff --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