added length do db

This commit is contained in:
Lars Noack 2022-11-29 14:16:36 +01:00
parent 94a0ad6537
commit 87f4e66148
6 changed files with 20 additions and 11 deletions

View File

@ -147,7 +147,7 @@ from music_kraken import fetch_metadata
# might change and break after I add multiple metadata sources which I will # 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 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: have following values:

View File

@ -1,12 +1,13 @@
import music_kraken as mk import music_kraken as mk
print(mk.__file__) print(mk.__file__)
mk.clear_cache()
song_list = mk.cache.get_custom_track([]) song_list = mk.cache.get_custom_track([])
print(mk.cache, len(song_list)) 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: song = mk.cache.get_track_metadata(musicbrainz_releasetrackid=id_)
print()
print(song) print(song)
print(song.json_data) print(song.length)

View File

@ -106,7 +106,8 @@ class Database:
feature_aritsts: list, feature_aritsts: list,
tracknumber: str = None, tracknumber: str = None,
track: str = None, track: str = None,
isrc: str = None isrc: str = None,
length: int = None
): ):
# add adjacency # add adjacency
adjacency_list = [] adjacency_list = []
@ -118,8 +119,8 @@ class Database:
self.connection.commit() self.connection.commit()
# add track # add track
query = "INSERT OR REPLACE INTO track (id, release_id, track, isrc, tracknumber) VALUES (?, ?, ?, ?, ?);" query = "INSERT OR REPLACE INTO track (id, release_id, track, isrc, tracknumber, length) VALUES (?, ?, ?, ?, ?, ?);"
values = musicbrainz_releasetrackid, musicbrainz_albumid, track, isrc, tracknumber values = musicbrainz_releasetrackid, musicbrainz_albumid, track, isrc, tracknumber, length
self.cursor.execute(query, values) self.cursor.execute(query, values)
self.connection.commit() self.connection.commit()
@ -171,6 +172,7 @@ SELECT DISTINCT
'musicbrainz_albumtype', release_group.musicbrainz_albumtype, 'musicbrainz_albumtype', release_group.musicbrainz_albumtype,
'compilation', release_group.compilation, 'compilation', release_group.compilation,
'album_artist_id', release_group.album_artist_id, 'album_artist_id', release_group.album_artist_id,
'length', track.length,
'path', track.path, 'path', track.path,
'file', track.file, 'file', track.file,
'genre', track.genre, 'genre', track.genre,

View File

@ -47,6 +47,8 @@ class Song:
for key, value in self.json_data.items(): for key, value in self.json_data.items():
self.metadata[key] = value self.metadata[key] = value
self.metadata['artist'] = self.get_artist_names() self.metadata['artist'] = self.get_artist_names()
self.length = self.json_data['length']
# EasyID3.valid_keys.keys() # EasyID3.valid_keys.keys()
# the lyrics are not in the metadata class because the field isn't supported # the lyrics are not in the metadata class because the field isn't supported

View File

@ -279,6 +279,8 @@ class MetadataDownloader:
self.isrc = get_elem_from_obj(recording_data, ['isrc-list', 0]) self.isrc = get_elem_from_obj(recording_data, ['isrc-list', 0])
self.title = recording_data['title'] self.title = recording_data['title']
self.lenth = get_elem_from_obj(recording_data, ['length'])
self.save() self.save()
def __str__(self): def __str__(self):
@ -293,7 +295,8 @@ class MetadataDownloader:
feature_aritsts=[artist.musicbrainz_artistid for artist in self.artists], feature_aritsts=[artist.musicbrainz_artistid for artist in self.artists],
tracknumber=self.track_number, tracknumber=self.track_number,
track=self.title, track=self.title,
isrc=self.isrc isrc=self.isrc,
length=int(self.lenth)
) )
def append_artist(self, artist_id: str): def append_artist(self, artist_id: str):

View File

@ -62,5 +62,6 @@ CREATE TABLE source (
track_id TEXT NOT NULL, track_id TEXT NOT NULL,
src TEXT NOT NULL, src TEXT NOT NULL,
url 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 valid BOOLEAN NOT NULL DEFAULT 1
); );