From 5d61721b608ba793be0d1b54de65095c68098873 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Thu, 24 Nov 2022 14:34:36 +0100 Subject: [PATCH] refactored imports, so every important function can be imported directly from the 'root module' music_kraken --- src/goof.py | 13 +++++++++---- src/music_kraken/__init__.py | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/goof.py b/src/goof.py index 2987213..e0c2dbb 100644 --- a/src/goof.py +++ b/src/goof.py @@ -1,14 +1,19 @@ import music_kraken as mk print(mk.__file__) +""" from music_kraken.audio_source import ( fetch_sources, fetch_audios ) print(fetch_sources) -cache = mk.database.temp_database.temp_database -print(cache, len(cache.get_tracks_without_src())) +from music_kraken.database import ( + cache +) +""" -fetch_sources(cache.get_tracks_without_src(), skip_existing_files=False) -fetch_audios(cache.get_tracks_to_download(), override_existing=True) +print(mk.cache, len(mk.cache.get_tracks_without_src())) + +mk.fetch_sources(mk.cache.get_tracks_without_src(), skip_existing_files=False) +mk.fetch_audios(mk.cache.get_tracks_to_download(), override_existing=True) diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index 70c524c..1c0c92f 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -1,7 +1,13 @@ +from typing import List import musicbrainzngs import logging import os +from . import ( + database, + audio_source +) + from .utils.shared import ( MUSIC_DIR, NOT_A_GENRE @@ -20,6 +26,17 @@ from .lyrics import lyrics logging.getLogger("musicbrainzngs").setLevel(logging.WARNING) musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeIIow2/music-downloader") +# define the most important values and function for import in the __init__ file +Song = database.song.Song + +cache = database.cache + +def fetch_sources(songs: List[Song], skip_existing_files: bool = True): + audio_source.fetch_sources(songs=songs, skip_existing_files=skip_existing_files) + +def fetch_audios(songs: List[Song], override_existing: bool = False): + audio_source.fetch_audios(songs=songs, override_existing=override_existing) + def get_existing_genre(): valid_directories = [] @@ -125,11 +142,11 @@ def cli(start_at: int = 0, only_lyrics: bool = False): if start_at <= 2 and not only_lyrics: logging.info("Fetching Download Links") - fetch_source.Download() + fetch_sources(cache.get_tracks_without_src()) if start_at <= 3 and not only_lyrics: logging.info("starting to download the mp3's") - fetch_audio.Download() + fetch_audios(cache.get_tracks_to_download()) if start_at <= 4: logging.info("starting to fetch the lyrics")