fixed dependency

This commit is contained in:
Lars Noack 2022-11-22 14:53:29 +01:00
parent f45afcb2ce
commit 993545eb9d
6 changed files with 35 additions and 15 deletions

View File

@ -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 = []

View File

@ -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):

View File

@ -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']

View File

@ -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()

View File

@ -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}")

View File

@ -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')