diff --git a/src/create_custom_objects.py b/src/create_custom_objects.py index cdd54ca..7fac0a0 100644 --- a/src/create_custom_objects.py +++ b/src/create_custom_objects.py @@ -20,6 +20,9 @@ from music_kraken.tagging import ( import music_kraken.database.new_database as db import pycountry +import logging + +logging.disable() def div(msg: str = ""): @@ -31,6 +34,8 @@ cache.reset() def print_song(song_: Song): print(str(song_.metadata)) + print("----album--") + print(song_.album) print("----src----") print("song:") print(song_.source_list) @@ -79,18 +84,15 @@ print_song(song) +div() song_ref = song.reference - cache.push([song]) -exit() - - # getting song by song ref -div() song_list = cache.pull_songs(song_ref=song_ref) song_from_db = song_list[0] +print_song(song_from_db) # 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 e7d7d7f..452793a 100644 --- a/src/music_kraken/database/new_database.py +++ b/src/music_kraken/database/new_database.py @@ -27,7 +27,7 @@ logger = logging.getLogger("database") # use complicated query builder SONG_QUERY = """ SELECT -Song.id AS song_id, Song.name AS title, Song.isrc AS isrc, Song.length AS length, Song.album_id, Song.tracksort, +Song.id AS song_id, Song.name AS title, Song.isrc AS isrc, Song.length AS length, Song.album_id as album_id, Song.tracksort, Target.id AS target_id, Target.file AS file, Target.path AS path, Song.genre AS genre FROM Song LEFT JOIN Target ON Song.id=Target.song_id @@ -119,10 +119,6 @@ class Database: if type(db_object) == Album: return self.push_album(album=db_object) - if issubclass(type(db_object), SourceAttribute): - for source in db_object.source_list: - self.push_source(source=source) - logger.warning(f"type {type(db_object)} isn't yet supported by the db") def push(self, db_object_list: List[Song | Lyrics | Target | Artist | Source | Album]): @@ -163,7 +159,8 @@ class Database: self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference) self.push_artist(artist) - for source in album.sources: + for source in album.source_list: + source.type_enum = SourceTypes.ALBUM self.push_source(source=source) def push_song(self, song: Song): @@ -213,6 +210,9 @@ class Database: self.push_artist_song(artist_ref=Reference(feature_artist.id), song_ref=Reference(song.id), is_feature=True) self.push_artist(artist=feature_artist) + if song.album is not None: + self.push_album(song.album) + def push_lyrics(self, lyrics: Lyrics, ): if lyrics.song_ref_id is None: logger.warning("the Lyrics don't refer to a song") @@ -321,7 +321,8 @@ class Database: for album in artist.main_albums: self.push_artist_album(artist_ref=artist.reference, album_ref=album.reference) - for source in artist.sources: + for source in artist.source_list: + source.type_enum = SourceTypes.ARTIST self.push_source(source) def pull_lyrics(self, song_ref: Reference = None, lyrics_ref: Reference = None) -> List[Lyrics]: @@ -437,7 +438,7 @@ class Database: artist_obj = Artist( id_=artist_id, name=artist_row['artist_name'], - sources=self.pull_sources(artist_ref=Reference(id_=artist_id)) + source_list=self.pull_sources(artist_ref=Reference(id_=artist_id)) ) if flat: return artist_obj @@ -506,11 +507,12 @@ class Database: file=song_result['file'], path=song_result['path'] ), - sources=self.pull_sources(song_ref=Reference(id_=song_id)), + source_list=self.pull_sources(song_ref=Reference(id_=song_id)), lyrics=self.pull_lyrics(song_ref=Reference(id_=song_id)), ) if Album not in exclude_relations and song_result['album_id'] is not None: + print(dict(song_result)) album_obj = self.pull_albums(album_ref=Reference(song_result['album_id']), exclude_relations=new_exclude_relations) if len(album_obj) > 0: @@ -580,7 +582,7 @@ class Database: barcode=album_result['barcode'], is_split=album_result['is_split'], albumsort=album_result['albumsort'], - sources=self.pull_sources(album_ref=Reference(id_=album_id)) + source_list=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 732bc5d..f534ce4 100644 --- a/src/music_kraken/database/objects/song.py +++ b/src/music_kraken/database/objects/song.py @@ -138,8 +138,6 @@ class Song(DatabaseObject, SourceAttribute, MetadataAttribute): if source_list: self.source_list = source_list - self.album = album - self.target = Target() if target is not None: self.target = target diff --git a/src/music_kraken/tagging/id3.py b/src/music_kraken/tagging/id3.py index a037897..affd63d 100644 --- a/src/music_kraken/tagging/id3.py +++ b/src/music_kraken/tagging/id3.py @@ -22,7 +22,7 @@ class AudioMetadata: self.file_location = file_location def add_song_metadata(self, song: Song): - for key, value in song.metadata: + for value in song.metadata: """ https://www.programcreek.com/python/example/84797/mutagen.id3.ID3 """ diff --git a/test.db b/test.db index d16bfd8..516b94c 100644 Binary files a/test.db and b/test.db differ