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
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:

View File

@ -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)

View File

@ -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,

View File

@ -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

View File

@ -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):

View File

@ -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
);