From e51d4ca4678b6a21eae24162a029dcd211f32cac Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 23 Jan 2023 13:49:07 +0100 Subject: [PATCH] added Source objects to album --- src/goof.py | 7 ++++++- src/music_kraken/database/new_database.py | 13 +++++++++---- src/music_kraken/database/objects/song.py | 17 ++++++++++++++++- test.db | Bin 65536 -> 65536 bytes 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/goof.py b/src/goof.py index 1441abf..35fa00f 100644 --- a/src/goof.py +++ b/src/goof.py @@ -51,7 +51,10 @@ album_input = Album( title="One Final Action", date=ID3Timestamp(year=1986, month=3, day=1), language=pycountry.languages.get(alpha_2="en"), - label="cum productions" + label="cum productions", + sources=[ + Source(SourcePages.ENCYCLOPAEDIA_METALLUM, "https://www.metal-archives.com/albums/I%27m_in_a_Coffin/One_Final_Action/207614") + ] ) album_input.artists = [ main_artist, @@ -110,6 +113,8 @@ print("--src--") for source in song.sources: print(source) +print("album", song.album.sources) + # try writing metadata write_metadata(song) diff --git a/src/music_kraken/database/new_database.py b/src/music_kraken/database/new_database.py index 5777e40..6d12a95 100644 --- a/src/music_kraken/database/new_database.py +++ b/src/music_kraken/database/new_database.py @@ -159,6 +159,9 @@ class Database: self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference) self.push_artist(artist) + for source in album.sources: + self.push_source(source=source) + def push_song(self, song: Song): # ADDING THE DATA FOR THE SONG OBJECT """ @@ -224,7 +227,7 @@ class Database: def push_source(self, source: Source): if source.song_ref_id is None: - logger.warning("the Source don't refer to a song") + logger.warning(f"the Source {source} don't refer to a song") table = "Source" query = f"INSERT OR REPLACE INTO {table} (id, type, song_id, src, url) VALUES (?, ?, ?, ?, ?);" @@ -315,7 +318,6 @@ class Database: self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference) for source in artist.sources: - source.add_song(artist) self.push_source(source) def pull_lyrics(self, song_ref: Reference = None, lyrics_ref: Reference = None) -> List[Lyrics]: @@ -344,7 +346,7 @@ class Database: language=lyrics_row['language'] ) for lyrics_row in lyrics_rows] - def pull_sources(self, artist_ref: Reference = None, song_ref: Reference = None, source_ref: Reference = None) -> List[Source]: + def pull_sources(self, artist_ref: Reference = None, song_ref: Reference = None, source_ref: Reference = None, album_ref: Reference = None) -> List[Source]: """ Gets a list of sources. if source_ref is passed in the List will most likely only contain one Element if everything goes accordingly. @@ -362,6 +364,8 @@ class Database: where = f"id=\"{source_ref.id}\" AND type=\"{SourceTypes.SONG.value}\"" elif artist_ref is not None: where = f"song_id=\"{artist_ref.id}\" AND type=\"{SourceTypes.ARTIST.value}\"" + elif album_ref is not None: + where = f"song_id=\"{album_ref.id}\" AND type=\"{SourceTypes.ALBUM.value}\"" query = SOURCE_QUERY.format(where=where) self.cursor.execute(query) @@ -571,7 +575,8 @@ class Database: country=album_result['country'], barcode=album_result['barcode'], is_split=album_result['is_split'], - albumsort=album_result['albumsort'] + albumsort=album_result['albumsort'], + sources=self.pull_sources(album_ref=Reference(id_=album_id)) ) if Song not in exclude_relations: diff --git a/src/music_kraken/database/objects/song.py b/src/music_kraken/database/objects/song.py index e296cb3..6eb7ce1 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -239,7 +239,8 @@ class Album(DatabaseObject, ID3Metadata): barcode: str = None, is_split: bool = False, albumsort: int = None, - dynamic: bool = False + dynamic: bool = False, + sources: List[Source] = None ) -> None: DatabaseObject.__init__(self, id_=id_, dynamic=dynamic) self.title: str = title @@ -260,6 +261,9 @@ class Album(DatabaseObject, ID3Metadata): self.tracklist: List[Song] = [] self.artists: List[Artist] = [] + self._sources = [] + self.sources = sources + def __str__(self) -> str: return f"Album: \"{self.title}\"" @@ -304,6 +308,16 @@ class Album(DatabaseObject, ID3Metadata): return self.language.alpha_3 + def set_sources(self, source_list: List[Source]): + if source_list is None: + return + + self._sources = source_list + for source in self._sources: + source.add_song(self) + source.type_enum = SourceTypes.ALBUM + + sources: List[Source] = property(fget=lambda self: self._sources, fset=set_sources) copyright = property(fget=get_copyright) iso_639_2_language = property(fget=get_iso_639_2_lang) @@ -412,6 +426,7 @@ class Artist(DatabaseObject, ID3Metadata): self._sources = source_list for source in self._sources: + source.add_song(self) source.type_enum = SourceTypes.ARTIST sources: List[Source] = property(fget=lambda self: self._sources, fset=set_sources) diff --git a/test.db b/test.db index e33bf422fa692a3fd5ace0129c6352837d3a34a4..6398dffd56d13dc1cfcb34a67fa4fc01fc2c52ff 100644 GIT binary patch literal 65536 zcmeI*%X8$!9S87vc>UV7#U{15T;w1MQfp_oZM`2*K+G~rob}paZH16zakZpwd)TqY zj5I6`6%sFjOAa~ZLUH2{pep$%I3=f4Q8`k{A^$;+`APDOJqCk9pt3H$+VzaAN9)(0 z)@UqstF`&kT00Y}?DqC}rkb@!YV~^UhpJku)t;oEN9boTOw!2M;1_zYpBO)D^vT-N z%Rin`{#{eX->l94Uis^#zs$aR@!3lsPCt6_^7KEZzBBc&$#n9c6ED+j3=n_-1R(G& z5IFp$GBNkW6ZHqb$#~ciE1j^vx6;enX?9}tksEhfD_bpfYvuX1mU?2w^un}S3_M?N zyB(LmJ-_iX98!Mq~5!OYQlH#hFIR$p9KZ?#@o7^JbN-f7)z-D$1gXl<4oTWH6N zgVaXW7^FP9N-;HGXL|9${OrWsl<6@da$-O2#XIwDFn_~sGV+0!Lxo(U)^T^(!|{SeEsn0vgC^llsGdZB;~Xtj?p4kSAwmL?bUT!{&s79OZ~~6)!Qp~ zUdfBI%tONWio9;MezrBecx`5U?z#DTt)0Z;&GhvS{l&A*`&qa6eY@PwwqCx^9&Sw+ z@x9Y5;#)iDwWG9ry*LtIIqg(@1#qz&erb%Ecrz2gV z6w6=6N0f>q*D0hy$ydb6+F7Y}v|d4^7Du`c4@GB?+=yOzWJ@#p=%@Jt$F3*$ve7v) zr_+HG!|^&%x1VIagW2o+p?CfLG^y1?9 z_}nvdXMTE%Zved@o_J@bS?ss(_KWh^?Dl(+C|}1$N~E0jIYm;nI1cuQ+0Ao1JeVGR zT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