diff --git a/src/music_kraken/__init__.py b/src/music_kraken/__init__.py index f83965c..5caaca0 100644 --- a/src/music_kraken/__init__.py +++ b/src/music_kraken/__init__.py @@ -19,12 +19,16 @@ from .database.database import Database import logging import os +logging.getLogger("musicbrainzngs").setLevel(logging.WARNING) +musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeIIow2/music-downloader") +""" 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 = [] diff --git a/src/music_kraken/audio_source/fetch_audio.py b/src/music_kraken/audio_source/fetch_audio.py index 3a22d9d..0176b10 100644 --- a/src/music_kraken/audio_source/fetch_audio.py +++ b/src/music_kraken/audio_source/fetch_audio.py @@ -11,6 +11,7 @@ from .sources import ( local_files ) from ..database import song as song_objects +from ..database.temp_database import temp_database logger = DOWNLOAD_LOGGER @@ -33,15 +34,15 @@ print(EasyID3.valid_keys.keys()) class Download: def __init__(self): - for song in database.get_tracks_to_download(): + for song in temp_database.get_tracks_to_download(): if self.path_stuff(song.target): - self.write_metadata(song, song['file']) + self.write_metadata(song, song.target.file) continue # download_success = Download.download_from_src(song['src'], song) for source in song.sources: - download_success = Download.download_from_src(source.src, source.url, song) + download_success = Download.download_from_src(song, source) if download_success != -1: break else: @@ -59,12 +60,12 @@ class Download: self.write_metadata(song, song['file']) @staticmethod - def download_from_src(src, url, song): - if src not in sources: - raise ValueError(f"source {src} seems to not exist") - source_subclass = sources[src] + def download_from_src(song, src): + if src.src not in sources: + raise ValueError(f"source {src.src} seems to not exist") + source_subclass = sources[src.src] - return source_subclass.fetch_audio(url, song) + return source_subclass.fetch_audio(song, src) @staticmethod def write_metadata(song, file_path): diff --git a/src/music_kraken/audio_source/fetch_source.py b/src/music_kraken/audio_source/fetch_source.py index 2d449a1..3c24d6b 100644 --- a/src/music_kraken/audio_source/fetch_source.py +++ b/src/music_kraken/audio_source/fetch_source.py @@ -6,7 +6,7 @@ from .sources import ( local_files ) -from .. import database +from ..database.temp_database import temp_database logger = URL_DOWNLOAD_LOGGER @@ -21,7 +21,7 @@ class Download: def __init__(self) -> None: self.urls = [] - for row in database.get_tracks_without_src(): + for row in temp_database.get_tracks_without_src(): row['artists'] = [artist['name'] for artist in row['artists']] id_ = row['id'] diff --git a/src/music_kraken/database/temp_database.py b/src/music_kraken/database/temp_database.py new file mode 100644 index 0000000..9d25232 --- /dev/null +++ b/src/music_kraken/database/temp_database.py @@ -0,0 +1,15 @@ +from .database import Database + +from ..utils.shared import ( + TEMP_DATABASE_PATH, + DATABASE_STRUCTURE_FILE, + DATABASE_STRUCTURE_FALLBACK, + DATABASE_LOGGER +) + +class TempDatabase(Database): + def __init__(self) -> None: + super().__init__(TEMP_DATABASE_PATH, DATABASE_STRUCTURE_FILE, DATABASE_STRUCTURE_FALLBACK, DATABASE_LOGGER, False) + + +temp_database = TempDatabase() diff --git a/src/music_kraken/target/set_target.py b/src/music_kraken/target/set_target.py index 96aa83f..485f359 100644 --- a/src/music_kraken/target/set_target.py +++ b/src/music_kraken/target/set_target.py @@ -2,6 +2,7 @@ import os.path import logging from ..utils.shared import * +from ..database.temp_database import temp_database logger = PATH_LOGGER @@ -21,7 +22,7 @@ class UrlPath: self.genre = genre - for row in database.get_tracks_without_filepath(): + for row in temp_database.get_tracks_without_filepath(): # print(row) file, path = self.get_path_from_row(row) logger.info(f"setting target to {file}") diff --git a/src/music_kraken/utils/shared.py b/src/music_kraken/utils/shared.py index 5fe8bf4..60ea2a7 100644 --- a/src/music_kraken/utils/shared.py +++ b/src/music_kraken/utils/shared.py @@ -6,13 +6,15 @@ import os TEMP_FOLDER = "music-downloader" LOG_FILE = "download_logs.log" -DATABASE_FILE = "metadata.db" +TEMP_DATABASE_FILE = "metadata.db" DATABASE_STRUCTURE_FILE = "database_structure.sql" DATABASE_STRUCTURE_FALLBACK = "https://raw.githubusercontent.com/HeIIow2/music-downloader/master/assets/database_structure.sql" temp_dir = os.path.join(tempfile.gettempdir(), TEMP_FOLDER) if not os.path.exists(temp_dir): os.mkdir(temp_dir) +TEMP_DATABASE_PATH = os.path.join(temp_dir, TEMP_DATABASE_FILE) + # configure logger default logging.basicConfig( level=logging.INFO, @@ -34,9 +36,6 @@ DOWNLOAD_LOGGER = logging.getLogger("download") LYRICS_LOGGER = logging.getLogger("lyrics") GENIUS_LOGGER = logging.getLogger("genius") -logging.getLogger("musicbrainzngs").setLevel(logging.WARNING) -musicbrainzngs.set_useragent("metadata receiver", "0.1", "https://github.com/HeIIow2/music-downloader") - NOT_A_GENRE = ".", "..", "misc_scripts", "Music", "script", ".git", ".idea" MUSIC_DIR = os.path.expanduser('~/Music')