From 8d484bde689a8ae525ab09561ad62ad330351b51 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Wed, 30 Nov 2022 16:15:38 +0100 Subject: [PATCH] refactor --- src/goof.py | 26 ++++++++----------- src/music_kraken/__init__.py | 1 + src/music_kraken/audio_source/fetch_source.py | 7 ++--- src/music_kraken/database/__init__.py | 2 +- src/music_kraken/database/get_song.py | 2 +- src/music_kraken/database/song.py | 13 ++++++++++ src/music_kraken/database/target.py | 3 +++ 7 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/goof.py b/src/goof.py index 4a136ff..1e3ae83 100644 --- a/src/goof.py +++ b/src/goof.py @@ -1,19 +1,15 @@ -import music_kraken as mk -print(mk.__file__) +import music_kraken -""" -mk.clear_cache() -song_list = mk.cache.get_custom_track([]) -print(mk.cache, len(song_list)) -id_="694bfd3c-9d2d-4d67-9bfc-cee5bf77166e" -id_="5cc28584-10c6-40e2-b6d4-6891e7e7c575" -mk.fetch_metadata(id_=id_, type_="recording") +artist = music_kraken.Artist( + name="I'm in a Coffin" +) + +song = music_kraken.Song( + title="Vein Deep in the Solution", + release="One Final Action", + artists=[artist] +) -song = mk.cache.get_track_metadata(musicbrainz_releasetrackid=id_) print(song) -print(song.length) -mk.set_targets(genre="test") -song = mk.cache.get_track_metadata(musicbrainz_releasetrackid=id_) -""" -mk.fetch_audios(mk.cache.get_tracks_to_download()) +music_kraken.fetch_sources([song]) diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index 733f72d..0b1b976 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -39,6 +39,7 @@ musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeI # define the most important values and function for import in the __init__ file Song = database.Song +Artist = database.Artist MetadataSearch = metadata.MetadataSearch MetadataDownload = metadata.MetadataDownload diff --git a/src/music_kraken/audio_source/fetch_source.py b/src/music_kraken/audio_source/fetch_source.py index f13f058..4e3d5d2 100644 --- a/src/music_kraken/audio_source/fetch_source.py +++ b/src/music_kraken/audio_source/fetch_source.py @@ -39,9 +39,10 @@ class Download: @classmethod def fetch_sources(cls, songs: List[song_object], skip_existing_files: bool = False): for song in songs: - if os.path.exists(song.target.file) and skip_existing_files: - logger.info(f"skipping the fetching of the download links, cuz {song.target.file} already exists.") - continue + if song.target.is_set(): + if os.path.exists(song.target.file) and skip_existing_files: + logger.info(f"skipping the fetching of the download links, cuz {song.target.file} already exists.") + continue sucess = False for src in AUDIO_SOURCES: diff --git a/src/music_kraken/database/__init__.py b/src/music_kraken/database/__init__.py index c45423e..58217a1 100644 --- a/src/music_kraken/database/__init__.py +++ b/src/music_kraken/database/__init__.py @@ -8,7 +8,7 @@ from . import ( ) Song = song.Song -Artist = artist.Artist +Artist = song.Artist Source = source.Source Target = target.Target Metadata = metadata.Metadata diff --git a/src/music_kraken/database/get_song.py b/src/music_kraken/database/get_song.py index 9b13972..c7d46b3 100644 --- a/src/music_kraken/database/get_song.py +++ b/src/music_kraken/database/get_song.py @@ -13,7 +13,7 @@ from .song import ( def get_song_from_response(response: dict) -> Song: # artists - artists = [Artist(a) for a in response['artists']] + artists = [Artist(id_=a['id'], name=a['name']) for a in response['artists']] # metadata metadata = Metadata() diff --git a/src/music_kraken/database/song.py b/src/music_kraken/database/song.py index bc1284c..f31d9de 100644 --- a/src/music_kraken/database/song.py +++ b/src/music_kraken/database/song.py @@ -6,6 +6,19 @@ from .source import Source from .target import Target +class Artist: + def __init__(self, id_: str = None, name: str = None) -> None: + self.id = id_ + self.name = name + + def __eq__(self, __o: object) -> bool: + if type(__o) != type(self): + return False + return self.id == __o.id + + def __str__(self) -> str: + return self.name + class Lyrics: def __init__(self, text: str, language: str) -> None: diff --git a/src/music_kraken/database/target.py b/src/music_kraken/database/target.py index a8c490b..35b5a81 100644 --- a/src/music_kraken/database/target.py +++ b/src/music_kraken/database/target.py @@ -25,6 +25,9 @@ class Target: if self._path is None: return None return os.path.join(MUSIC_DIR, self._path) + + def is_set(self) -> bool: + return not (self._file is None or self._path is None) file = property(fget=get_file, fset=set_file) path = property(fget=get_path, fset=set_path)