diff --git a/sql.db b/sql.db deleted file mode 100644 index e69de29..0000000 diff --git a/src/metadata/database.py b/src/metadata/database.py index 1264b81..038ce5e 100644 --- a/src/metadata/database.py +++ b/src/metadata/database.py @@ -73,7 +73,22 @@ def add_release_group( connection.commit() # add release group - query = "INSERT INTO release_group (id, albumartist, albumsort, musicbrainz_albumtype, compilation) VALUES (?, ?);" + query = "INSERT INTO release_group (id, albumartist, albumsort, musicbrainz_albumtype, compilation) VALUES (?, ?, ?, ?, ?);" + values = musicbrainz_releasegroupid, albumartist, albumsort, musicbrainz_albumtype, compilation + cursor.execute(query, values) + connection.commit() + +def add_release( + musicbrainz_albumid: str, + release_group_id: str, + title: str = None, + copyright_: str = None +): + query = "INSERT INTO release_ (id, release_group_id, title, copyright) VALUES (?, ?, ?, ?);" + values = musicbrainz_albumid, release_group_id, title, copyright_ + + cursor.execute(query, values) + connection.commit() if __name__ == "__main__": pass diff --git a/src/metadata/database_structure.sql b/src/metadata/database_structure.sql index 0a2fae0..5d6542f 100644 --- a/src/metadata/database_structure.sql +++ b/src/metadata/database_structure.sql @@ -28,8 +28,9 @@ CREATE TABLE release_group ( DROP TABLE IF EXISTS release_; CREATE TABLE release_ ( id TEXT PRIMARY KEY NOT NULL, - release_group TEXT NOT NULL, - name TEXT + release_group_id TEXT NOT NULL, + title TEXT, + copyright TEXT ); DROP TABLE IF EXISTS track; diff --git a/src/metadata/download.py b/src/metadata/download.py index ca66306..35ee02f 100644 --- a/src/metadata/download.py +++ b/src/metadata/download.py @@ -1,13 +1,9 @@ -import imp from typing import List - import musicbrainzngs import pandas as pd import logging from datetime import date -import sqlite3 - from object_handeling import get_elem_from_obj, parse_music_brainz_date import database @@ -179,7 +175,7 @@ class Release: self.title = get_elem_from_obj(release_data, ['title']) self.copyright = get_elem_from_obj(label_data, [0, 'label', 'name']) - logging.info(f"release {self}") + self.save() self.append_recordings(recording_datas) def append_recordings(self, recording_datas: dict): @@ -190,6 +186,15 @@ class Release: self.tracklist.append(musicbrainz_releasetrackid) + def save(self): + logging.info(f"release {self}") + database.add_release( + musicbrainz_albumid=self.musicbrainz_albumid, + release_group_id=self.release_group.musicbrainz_releasegroupid, + title=self.title, + copyright_=self.copyright + ) + def __str__(self): return f"{self.title} ©{self.copyright}" @@ -457,7 +462,6 @@ if __name__ == "__main__": os.mkdir(TEMP_DIR) """ logging.basicConfig(level=logging.DEBUG) - sqliteConnection = sqlite3.connect('sql.db') download({'id': '5cfecbe4-f600-45e5-9038-ce820eedf3d1', 'type': 'artist'}) # download({'id': '4b9af532-ef7e-42ab-8b26-c466327cb5e0', 'type': 'release'})