diff --git a/app/api/settings.py b/app/api/settings.py index 45cbebf..2f065a5 100644 --- a/app/api/settings.py +++ b/app/api/settings.py @@ -51,26 +51,3 @@ def get_root_dirs(): dirs = sdb.get_root_dirs() return {"dirs": dirs} - - -# CURRENTLY UNUSED ROUTE 👇 -@api.route("/settings/remove-root-dirs", methods=["POST"]) -def remove_root_dirs(): - """ - Remove custom root directories from the database. - """ - msg = {"msg": "Failed! No directories were given."} - - data = request.get_json() - - if data is None: - return msg, 400 - - try: - dirs = data["dirs"] - except KeyError: - return msg, 400 - - sdb.remove_root_dirs(dirs) - - return {"msg": "Removed root directories from the database."} diff --git a/app/lib/populate.py b/app/lib/populate.py index 7a6fce5..ef1d99e 100644 --- a/app/lib/populate.py +++ b/app/lib/populate.py @@ -1,4 +1,5 @@ from concurrent.futures import ThreadPoolExecutor +import os from tqdm import tqdm from app import settings @@ -24,17 +25,31 @@ class Populate: """ def __init__(self) -> None: + messages = { + "root_unset": "The root directory is not set. Trying to scan the default directory: %s", + "default_not_exists": "The directory: %s does not exist. Please open the app in your web browser to set the root directory.", + "no_tracks": "No tracks found in: %s. Please open the app in your web browser to set the root directory.", + } tracks = get_all_tracks() tracks = list(tracks) dirs_to_scan = sdb.get_root_dirs() + initial_dirs_count = len(dirs_to_scan) + + def_dir = "~/Music" if len(dirs_to_scan) == 0: - log.error( - "The root directory is not set. No folders will be scanned for music files. Open the app in your web browser to configure." - ) - return + log.warning(messages["root_unset"], def_dir) + print("...") + + exists = os.path.exists(settings.MUSIC_DIR) + + if not exists: + log.warning(messages["default_not_exists"], def_dir) + return + + dirs_to_scan = [settings.MUSIC_DIR] files = [] @@ -43,6 +58,26 @@ class Populate: untagged = self.filter_untagged(tracks, files) + if initial_dirs_count == 0 and len(untagged) == 0: + log.warning(messages["no_tracks"], def_dir) + return + + if initial_dirs_count == 0 and len(untagged) > 0: + log.info( + "%sFound %s tracks 💪 %s", + settings.TCOLOR.OKGREEN, + len(untagged), + settings.TCOLOR.ENDC, + ) + log.info( + "%s%s saved as the default root directory. 😶%s", + settings.TCOLOR.OKGREEN, + def_dir, + settings.TCOLOR.ENDC, + ) + sdb.add_root_dirs(dirs_to_scan) + return + if len(untagged) == 0: log.info("All clear, no unread files.") return diff --git a/app/settings.py b/app/settings.py index 1fd3e0d..529332f 100644 --- a/app/settings.py +++ b/app/settings.py @@ -46,6 +46,7 @@ ARTIST_IMG_LG_PATH = os.path.join(ARTIST_IMG_PATH, "large") THUMBS_PATH = os.path.join(IMG_PATH, "thumbnails") SM_THUMB_PATH = os.path.join(THUMBS_PATH, "small") LG_THUMBS_PATH = os.path.join(THUMBS_PATH, "large") +MUSIC_DIR = os.path.join(USER_HOME_DIR, "Music") # TEST_DIR = "/home/cwilvx/Downloads/Telegram Desktop"