From f4d0dd0089e0950658289ef4e0819b05ba19cf8a Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 27 Oct 2022 15:55:16 +0200 Subject: [PATCH] continued at step from prev commit --- src/metadata/database.py | 9 ++++--- src/metadata/download.py | 56 +++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/src/metadata/database.py b/src/metadata/database.py index 038ce5e..4a323ca 100644 --- a/src/metadata/database.py +++ b/src/metadata/database.py @@ -2,8 +2,6 @@ import sqlite3 import os import logging -logging.basicConfig(level=logging.DEBUG) - def get_temp_dir(): import tempfile @@ -90,5 +88,10 @@ def add_release( cursor.execute(query, values) connection.commit() -if __name__ == "__main__": +def add_track( + +): pass + +if __name__ == "__main__": + logging.basicConfig(level=logging.DEBUG) diff --git a/src/metadata/download.py b/src/metadata/download.py index 35ee02f..7dabeb7 100644 --- a/src/metadata/download.py +++ b/src/metadata/download.py @@ -15,7 +15,7 @@ mb_log.setLevel(logging.WARNING) musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeIIow2/music-downloader") -# IMPORTANT +# IMPORTANT DOCUMENTATION WHICH CONTAINS FOR EXAMPLE THE INCLUDES # https://python-musicbrainzngs.readthedocs.io/en/v0.7.1/api/#getting-data class Artist: @@ -54,6 +54,10 @@ class Artist: artists=[self], albumsort=i + 1 )) + + def __str__(self): + newline = "\n" + return f"id: {self.musicbrainz_artistid}\nname: {self.artist}\n{newline.join([str(release_group) for release_group in self.release_groups])}" def save(self): logging.info(f"artist: {self}") @@ -62,10 +66,6 @@ class Artist: artist=self.artist ) - def __str__(self): - newline = "\n" - return f"id: {self.musicbrainz_artistid}\nname: {self.artist}\n{newline.join([str(release_group) for release_group in self.release_groups])}" - class ReleaseGroup: def __init__( @@ -112,15 +112,8 @@ class ReleaseGroup: newline = "\n" return f"{newline.join([str(release_group) for release_group in self.releases])}" - def append_artist(self, artist_id: str) -> Artist: - for existing_artist in self.artists: - if artist_id == existing_artist.musicbrainz_artistid: - return existing_artist - new_artist = Artist(artist_id, release_groups=[self], new_release_groups=False) - self.artists.append(new_artist) - return new_artist - def save(self): + logging.info(f"caching release_group {self}") database.add_release_group( musicbrainz_releasegroupid=self.musicbrainz_releasegroupid, artist_ids=[artist.musicbrainz_artistid for artist in self.artists], @@ -130,6 +123,14 @@ class ReleaseGroup: compilation=self.compilation ) + def append_artist(self, artist_id: str) -> Artist: + for existing_artist in self.artists: + if artist_id == existing_artist.musicbrainz_artistid: + return existing_artist + new_artist = Artist(artist_id, release_groups=[self], new_release_groups=False) + self.artists.append(new_artist) + return new_artist + def append_release(self, release_data: dict): musicbrainz_albumid = get_elem_from_obj(release_data, ['id']) if musicbrainz_albumid is None: @@ -178,6 +179,18 @@ class Release: self.save() self.append_recordings(recording_datas) + def __str__(self): + return f"{self.title} ©{self.copyright}" + + def save(self): + logging.info(f"caching 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 append_recordings(self, recording_datas: dict): for recording_data in recording_datas: musicbrainz_releasetrackid = get_elem_from_obj(recording_data, ['id']) @@ -186,17 +199,6 @@ 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}" class Track: @@ -213,6 +215,12 @@ class Track: self.musicbrainz_releasetrackid = musicbrainz_releasetrackid self.release = release + def __str__(self): + return "this is a track" + + def save(self): + logging.info("caching track {self}") + def download(option: dict): type_ = option['type']