From bfcec43433fcd41ae8510281c09c0976dd49ad74 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 30 Jan 2023 16:35:29 +0100 Subject: [PATCH] addepted the database binding tp the changes to the structure --- src/create_custom_objects.py | 12 +++++++----- src/music_kraken/database/new_database.py | 22 ++++++++++++---------- src/music_kraken/database/objects/song.py | 2 -- src/music_kraken/tagging/id3.py | 2 +- test.db | Bin 65536 -> 65536 bytes 5 files changed, 20 insertions(+), 18 deletions(-) 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 d16bfd80a972112424eeb4a124e2a33ec40e0800..516b94cb48b7b6f8206c2d995336e0b935b2018a 100644 GIT binary patch delta 1946 zcmb7EO>bL86n)M!)Gi9ssG?R?P+b}*YBcf8y!m8PP$eWpN>Hn}iXtNejtvVIuI3XUQf@??vR!}OB zAaO`Z#*L7cFWY|rnu55VWm$dwNd~?G7he2w{mI$JrQg=)$E|v^Y^md|Ml&N)dXAic zT>IG0ItvYz4vIn{!M!O0Q@U?v13$E%+5Tv(z3b`rz)y9*KN~!pPRElsJDtPB!|mz~ z>I3_*_lciu+tHv?{Wi9yWR)pZ3^#xQk>PC^WP+J{I@`4m7a80?_2h-kU`fS`DJSAuJ(EXd+iW(+D z5b?!YqkQS=ZlhUpD!H>lL(Kw;-K~boY6Z3TmMdR4tHgrc*}9*yk>yVAAW?D95|;zeK*Dv1OntWW|Ml6l7#KcBvuHuqa+U@wJbWtf!KE5GDmF9W}T zZ@}KU&vBlYH<$~^D^DP^%tETQS!rP)R>X5+hzr!;pM}t?d?DBJvf~Pb2qqYM!f`yx z!9x}AD-75p%8ZVq(#dGxyOVLhH|?Gu8(z!HEvB*bE?#LZG;75(9nB$)$I!$}VXbD; zQ?mH$*UJ}kaFWGDo~$z2{`5SPDO9Vdr4X!?`v;%@pi?Q=1XnV!1P)w@(lx+*C$E=f gGsPY$q<7XLS|bJR>0}@Oul75&RJfG+fBfLm->?JDge+!JOt^9W&)h17r6vL4VVn8$rqwzYZXwtz?+b{P zq=~-QS)@*9YZ1RgtSxk+UtpSn3&T0*{?1)4$IIpT{dzt9u<@jxem#D$wLr==7m0#V zGJzD{g13r-*NJ&4xs#lAr(1ksl}e5xg`kW9*#-yRNCXunb($&{5c}hw5m1eEP`qS04zB$xa ze@Or89oaUSd~1$c5UHk~dYy;v^bIcyJHI500>NI0QnLWA^$db=358b1 ziP(KRyI;0;?&w8H%6}b|SYKalO)e^OG0f)Y