From 87f4e661480faa5401e41c0d8ca0a00ce70cf131 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Tue, 29 Nov 2022 14:16:36 +0100 Subject: [PATCH] added length do db --- README.md | 2 +- src/goof.py | 13 +++++++------ src/music_kraken/database/database.py | 8 +++++--- src/music_kraken/database/song.py | 2 ++ src/music_kraken/metadata/metadata_fetch.py | 5 ++++- .../static_files/temp_database_structure.sql | 1 + 6 files changed, 20 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index daf3a97..f78724b 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ from music_kraken import fetch_metadata # might change and break after I add multiple metadata sources which I will -fetch_metadata(id_=musicbrainz_id, type=metadata_type) +fetch_metadata(id_=musicbrainz_id, type_=metadata_type) ``` The option type is a string (*I'm sorry for not making it an enum I know its a bad pratice*), which can have following values: diff --git a/src/goof.py b/src/goof.py index bcbaae3..76d11d5 100644 --- a/src/goof.py +++ b/src/goof.py @@ -1,12 +1,13 @@ import music_kraken as mk print(mk.__file__) +mk.clear_cache() song_list = mk.cache.get_custom_track([]) - print(mk.cache, len(song_list)) -print(song_list) +#recording/694bfd3c-9d2d-4d67-9bfc-cee5bf77166e +id_="694bfd3c-9d2d-4d67-9bfc-cee5bf77166e" +mk.fetch_metadata(id_=id_, type_="recording") -for song in song_list: - print() - print(song) - print(song.json_data) +song = mk.cache.get_track_metadata(musicbrainz_releasetrackid=id_) +print(song) +print(song.length) diff --git a/src/music_kraken/database/database.py b/src/music_kraken/database/database.py index af7eb3c..6c7a9cf 100644 --- a/src/music_kraken/database/database.py +++ b/src/music_kraken/database/database.py @@ -106,7 +106,8 @@ class Database: feature_aritsts: list, tracknumber: str = None, track: str = None, - isrc: str = None + isrc: str = None, + length: int = None ): # add adjacency adjacency_list = [] @@ -118,8 +119,8 @@ class Database: self.connection.commit() # add track - query = "INSERT OR REPLACE INTO track (id, release_id, track, isrc, tracknumber) VALUES (?, ?, ?, ?, ?);" - values = musicbrainz_releasetrackid, musicbrainz_albumid, track, isrc, tracknumber + query = "INSERT OR REPLACE INTO track (id, release_id, track, isrc, tracknumber, length) VALUES (?, ?, ?, ?, ?, ?);" + values = musicbrainz_releasetrackid, musicbrainz_albumid, track, isrc, tracknumber, length self.cursor.execute(query, values) self.connection.commit() @@ -171,6 +172,7 @@ SELECT DISTINCT 'musicbrainz_albumtype', release_group.musicbrainz_albumtype, 'compilation', release_group.compilation, 'album_artist_id', release_group.album_artist_id, + 'length', track.length, 'path', track.path, 'file', track.file, 'genre', track.genre, diff --git a/src/music_kraken/database/song.py b/src/music_kraken/database/song.py index 89f0e8a..1af427d 100644 --- a/src/music_kraken/database/song.py +++ b/src/music_kraken/database/song.py @@ -47,6 +47,8 @@ class Song: for key, value in self.json_data.items(): self.metadata[key] = value self.metadata['artist'] = self.get_artist_names() + + self.length = self.json_data['length'] # EasyID3.valid_keys.keys() # the lyrics are not in the metadata class because the field isn't supported diff --git a/src/music_kraken/metadata/metadata_fetch.py b/src/music_kraken/metadata/metadata_fetch.py index 45145cb..81cdc38 100644 --- a/src/music_kraken/metadata/metadata_fetch.py +++ b/src/music_kraken/metadata/metadata_fetch.py @@ -279,6 +279,8 @@ class MetadataDownloader: self.isrc = get_elem_from_obj(recording_data, ['isrc-list', 0]) self.title = recording_data['title'] + self.lenth = get_elem_from_obj(recording_data, ['length']) + self.save() def __str__(self): @@ -293,7 +295,8 @@ class MetadataDownloader: feature_aritsts=[artist.musicbrainz_artistid for artist in self.artists], tracknumber=self.track_number, track=self.title, - isrc=self.isrc + isrc=self.isrc, + length=int(self.lenth) ) def append_artist(self, artist_id: str): diff --git a/src/music_kraken/static_files/temp_database_structure.sql b/src/music_kraken/static_files/temp_database_structure.sql index 293f428..4b84f1e 100644 --- a/src/music_kraken/static_files/temp_database_structure.sql +++ b/src/music_kraken/static_files/temp_database_structure.sql @@ -62,5 +62,6 @@ CREATE TABLE source ( track_id TEXT NOT NULL, src TEXT NOT NULL, url TEXT NOT NULL, + certainty INT NOT NULL DEFAULT 0, -- certainty=0 -> it is definitly a valid source valid BOOLEAN NOT NULL DEFAULT 1 );