From 0f25833da057b20de643ef75a119c39e3bfdc7ba Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Mon, 21 Nov 2022 12:25:40 +0100 Subject: [PATCH] fixed db src a bit --- src/music_kraken/audio_source/fetch_source.py | 1 - src/music_kraken/utils/database.py | 24 +++++++++++-------- src/try-programming-interface.py | 13 ++++++++-- 3 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/music_kraken/audio_source/fetch_source.py b/src/music_kraken/audio_source/fetch_source.py index e241df0..c963832 100644 --- a/src/music_kraken/audio_source/fetch_source.py +++ b/src/music_kraken/audio_source/fetch_source.py @@ -58,7 +58,6 @@ class Download: res = Download.fetch_from_src(row, src) if res is not None: Download.add_url(res, src, id_) - break logger.warning(f"Didn't find any sources for {row['title']}") diff --git a/src/music_kraken/utils/database.py b/src/music_kraken/utils/database.py index aa55136..e262c08 100644 --- a/src/music_kraken/utils/database.py +++ b/src/music_kraken/utils/database.py @@ -147,15 +147,15 @@ SELECT DISTINCT 'source', json_group_array( ( SELECT DISTINCT json_object( - 'src', src_.src, - 'url', src_.url, - 'valid', src_.valid + 'src', src_table.src, + 'url', src_table.url, + 'valid', src_table.valid ) ) ), 'id', track.id, 'tracknumber', track.tracknumber, - 'titlesort ', track.tracknumber, + 'titlesort', track.tracknumber, 'musicbrainz_releasetrackid', track.id, 'musicbrainz_albumid', release_.id, 'title', track.track, @@ -180,12 +180,12 @@ SELECT DISTINCT 'src', track.src, 'lyrics', track.lyrics ) -FROM track, release_, release_group, artist, artist_track -LEFT JOIN release_ id ON track.release_id = release_.id -LEFT JOIN release_group id ON release_.id = release_group.id -LEFT JOIN artist_track track_id ON track.id = artist_track.track_id -LEFT JOIN artist id ON artist_track.artist_id = artist.id -LEFT JOIN source src_ ON track.id = src_.track_id +FROM track +LEFT JOIN release_ ON track.release_id = release_.id +LEFT JOIN release_group ON release_.id = release_group.id +LEFT JOIN artist_track ON track.id = artist_track.track_id +LEFT JOIN artist ON artist_track.artist_id = artist.id +LEFT JOIN source src_table ON track.id = src_table.track_id WHERE {where_arg} GROUP BY track.id; @@ -242,6 +242,10 @@ WHERE '{track_id}' == id; """ self.cursor.execute(query, (url, src)) self.connection.commit() + + query = "INSERT OR REPLACE INTO source (track_id, src, url) VALUES (?, ?, ?);" + self.cursor.execute(query, (track_id, src, url)) + self.connection.commit() def set_filepath(self, track_id: str, file: str, path: str, genre: str): query = f""" diff --git a/src/try-programming-interface.py b/src/try-programming-interface.py index e075326..2d3caf9 100644 --- a/src/try-programming-interface.py +++ b/src/try-programming-interface.py @@ -1,4 +1,13 @@ -from music_kraken.__main__ import cli +import music_kraken as mk +print(mk.__path__) + +# mk.fetch_source.Download() +db = mk.utils.shared.database +if len(db.get_custom_track([])) == 0: + mk.cli() if __name__ == "__main__": - cli() + db = mk.utils.shared.database + for elem in db.get_custom_track([]): + print(elem) + print()