From f45afcb2ce85380ad691ff021f3fb6ba2b3903b7 Mon Sep 17 00:00:00 2001 From: Lars Noack Date: Tue, 22 Nov 2022 14:25:01 +0100 Subject: [PATCH] gotta fix fucking imports --- src/music_kraken/__init__.py | 7 +++++++ src/music_kraken/audio_source/fetch_audio.py | 14 ++++++-------- src/music_kraken/audio_source/fetch_source.py | 2 ++ src/music_kraken/audio_source/sources/musify.py | 14 +++++++------- src/music_kraken/audio_source/sources/source.py | 2 +- src/music_kraken/database/song.py | 8 +++++--- src/music_kraken/metadata/metadata_fetch.py | 2 ++ src/music_kraken/utils/shared.py | 8 -------- src/try-programming-interface.py | 12 ++++++++---- 9 files changed, 38 insertions(+), 31 deletions(-) diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index 99b9720..f83965c 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -14,11 +14,18 @@ from .audio_source import ( ) from .lyrics import lyrics +from .database.database import Database import logging import os +database = Database(os.path.join(temp_dir, DATABASE_FILE), + os.path.join(temp_dir, DATABASE_STRUCTURE_FILE), + DATABASE_STRUCTURE_FALLBACK, + DATABASE_LOGGER, + reset_anyways=False) + def get_existing_genre(): valid_directories = [] for elem in os.listdir(MUSIC_DIR): diff --git a/src/music_kraken/audio_source/fetch_audio.py b/src/music_kraken/audio_source/fetch_audio.py index b09f24c..3a22d9d 100644 --- a/src/music_kraken/audio_source/fetch_audio.py +++ b/src/music_kraken/audio_source/fetch_audio.py @@ -10,6 +10,7 @@ from .sources import ( musify, local_files ) +from ..database import song as song_objects logger = DOWNLOAD_LOGGER @@ -33,11 +34,8 @@ print(EasyID3.valid_keys.keys()) class Download: def __init__(self): for song in database.get_tracks_to_download(): - song['artist'] = [i['name'] for i in song['artists']] - song['file'] = os.path.join(MUSIC_DIR, song['file']) - song['path'] = os.path.join(MUSIC_DIR, song['path']) - if self.path_stuff(song['path'], song['file']): + if self.path_stuff(song.target): self.write_metadata(song, song['file']) continue @@ -93,12 +91,12 @@ class Download: audiofile.save(file_path, v1=2) @staticmethod - def path_stuff(path: str, file_: str): + def path_stuff(target: song_objects.Target): # returns true if it shouldn't be downloaded - if os.path.exists(file_): - logger.info(f"'{file_}' does already exist, thus not downloading.") + if os.path.exists(target.file): + logger.info(f"'{target.file}' does already exist, thus not downloading.") return True - os.makedirs(path, exist_ok=True) + os.makedirs(target.path, exist_ok=True) return False diff --git a/src/music_kraken/audio_source/fetch_source.py b/src/music_kraken/audio_source/fetch_source.py index c963832..2d449a1 100644 --- a/src/music_kraken/audio_source/fetch_source.py +++ b/src/music_kraken/audio_source/fetch_source.py @@ -6,6 +6,8 @@ from .sources import ( local_files ) +from .. import database + logger = URL_DOWNLOAD_LOGGER # maps the classes to get data from to the source name diff --git a/src/music_kraken/audio_source/sources/musify.py b/src/music_kraken/audio_source/sources/musify.py index 3029320..69fa613 100644 --- a/src/music_kraken/audio_source/sources/musify.py +++ b/src/music_kraken/audio_source/sources/musify.py @@ -26,11 +26,11 @@ session.proxies = proxies class Musify(AudioSource): @classmethod - def fetch_source(cls, row: dict) -> str | None: - super().fetch_source(row) + def fetch_source(cls, song: dict) -> str | None: + super().fetch_source(song) - title = row.title - artists = row.get_artist_names() + title = song.title + artists = song.get_artist_names() # trying to get a download link via the autocomplete api for artist in artists: @@ -73,9 +73,9 @@ class Musify(AudioSource): return None if r.status_code == 200: autocomplete = r.json() - for row in autocomplete: - if artist in row['label'] and "/track" in row['url']: - return cls.get_download_link(row['url']) + for song in autocomplete: + if artist in song['label'] and "/track" in song['url']: + return cls.get_download_link(song['url']) return None diff --git a/src/music_kraken/audio_source/sources/source.py b/src/music_kraken/audio_source/sources/source.py index b8df60c..a8e4e1f 100644 --- a/src/music_kraken/audio_source/sources/source.py +++ b/src/music_kraken/audio_source/sources/source.py @@ -19,5 +19,5 @@ class AudioSource: logger.info(f"try getting source {row['title']} from {cls.__name__}") @classmethod - def fetch_audio(cls, song: song_objects.Song, src: song_objects.Sourcet): + def fetch_audio(cls, song: song_objects.Song, src: song_objects.Source): logger.info(f"downloading {song}: {cls.__name__} {src.url} -> {song.target.file}") diff --git a/src/music_kraken/database/song.py b/src/music_kraken/database/song.py index b085086..dcf99ff 100644 --- a/src/music_kraken/database/song.py +++ b/src/music_kraken/database/song.py @@ -1,5 +1,7 @@ from typing import List -from ..utils.shared import * +from ..utils.shared import ( + MUSIC_DIR +) import os @@ -29,7 +31,7 @@ class Target: class Artist: def __init__(self, artist_data) -> None: - self.artist_data + self.artist_data = artist_data self.id = self.artist_data['id'] self.name = self.artist_data['name'] @@ -73,7 +75,7 @@ class Song: return self.isrc is not None def get_artist_names(self) -> List[str]: - return [a.name for a in self.aritsts] + return [a.name for a in self.artists] def __getitem__(self, item): if item not in self.json_data: diff --git a/src/music_kraken/metadata/metadata_fetch.py b/src/music_kraken/metadata/metadata_fetch.py index acb61f5..db8a803 100644 --- a/src/music_kraken/metadata/metadata_fetch.py +++ b/src/music_kraken/metadata/metadata_fetch.py @@ -1,6 +1,8 @@ from ..utils.shared import * from ..utils.object_handeling import get_elem_from_obj, parse_music_brainz_date +from .. import database + from typing import List import musicbrainzngs import logging diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index ce2dbe5..5fe8bf4 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -3,7 +3,6 @@ import logging import tempfile import os -from ..database.database import Database TEMP_FOLDER = "music-downloader" LOG_FILE = "download_logs.log" @@ -42,13 +41,6 @@ NOT_A_GENRE = ".", "..", "misc_scripts", "Music", "script", ".git", ".idea" MUSIC_DIR = os.path.expanduser('~/Music') -database = Database(os.path.join(temp_dir, DATABASE_FILE), - os.path.join(temp_dir, DATABASE_STRUCTURE_FILE), - DATABASE_STRUCTURE_FALLBACK, - DATABASE_LOGGER, - reset_anyways=False) - - TOR = False proxies = { 'http': 'socks5h://127.0.0.1:9150', diff --git a/src/try-programming-interface.py b/src/try-programming-interface.py index a90f1b6..edf1950 100644 --- a/src/try-programming-interface.py +++ b/src/try-programming-interface.py @@ -1,10 +1,14 @@ import music_kraken as mk print(mk.__path__) -# mk.fetch_source.Download() -db = mk.utils.shared.database -if len(db.get_custom_track([])) == 0: - mk.cli() +# mk.cli() + +mk.fetch_source.Download() +# db = mk.utils.shared.database +# if len(db.get_custom_track([])) == 0: + + +mk.target.set_target.UrlPath(genre="test") mk.fetch_audio.Download()