From ade8759191ecf08ffbaab37e438f9d046a200ee0 Mon Sep 17 00:00:00 2001 From: cwilvx Date: Sat, 30 Aug 2025 16:51:27 +0300 Subject: [PATCH] put back default track sort order + ignore src files in scans --- src/swingmusic/lib/folderslib.py | 2 -- src/swingmusic/start_swingmusic.py | 10 ++++----- src/swingmusic/utils/filesystem.py | 34 +++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/src/swingmusic/lib/folderslib.py b/src/swingmusic/lib/folderslib.py index 7e2ce97b..8e0bedab 100644 --- a/src/swingmusic/lib/folderslib.py +++ b/src/swingmusic/lib/folderslib.py @@ -95,7 +95,6 @@ def get_files_and_dirs( elif entry.is_file() and ext in SUPPORTED_FILES: files.append(entry) - """ # sort files by most recent # TODO: rework if realy needed. files_with_mtime = [] @@ -112,7 +111,6 @@ def get_files_and_dirs( files_with_mtime.sort(key=lambda f: f["time"]) files = [f["path"] for f in files_with_mtime] - """ # if supported files were found # convert files to tracks diff --git a/src/swingmusic/start_swingmusic.py b/src/swingmusic/start_swingmusic.py index 09fbe3e8..34388831 100644 --- a/src/swingmusic/start_swingmusic.py +++ b/src/swingmusic/start_swingmusic.py @@ -69,14 +69,14 @@ def start_swingmusic(host: str, port: int): :param port: The port number to run the server on """ - port_manager = PortManager(host) + # port_manager = PortManager(host) # Try starting a server on port 1970 # If it fails, exit with error - if not port_manager.test_port(port): - print(f"Error 48: Port {port} already in use.") - print("Please specify a different port using the --port argument.") - sys.exit(1) + # if not port_manager.test_port(port): + # print(f"Error 48: Port {port} already in use.") + # print("Please specify a different port using the --port argument.") + # sys.exit(1) # Example: Setting up dirs, database, and loading stuff into memory. # TIP: Be careful with the order of the setup functions. diff --git a/src/swingmusic/utils/filesystem.py b/src/swingmusic/utils/filesystem.py index 992e667f..6d00d01e 100644 --- a/src/swingmusic/utils/filesystem.py +++ b/src/swingmusic/utils/filesystem.py @@ -1,11 +1,31 @@ import os from pathlib import Path -import importlib.resources as imres FILES = ["flac", "mp3", "wav", "m4a", "ogg", "wma", "opus", "alac", "aiff"] SUPPORTED_FILES = tuple(f".{file}" for file in FILES) +# TODO: Move this to config +# INFO: Skip these paths when scanning +IGNORE_PATH_ENDSWITH = { + "node_modules", + "site-packages", + "postgres", + "__pycache__", + "/src", + "/learnrs", + "/venv", + "/code", + "/dist", + "/demos", + "/temp", +} + + +IGNORE_PATH_CONTAINS = { + "Photos Library", +} + def run_fast_scandir(path: str, full=False) -> tuple[list[str], list[str]]: """ @@ -24,13 +44,17 @@ def run_fast_scandir(path: str, full=False) -> tuple[list[str], list[str]]: if path == "": return [], [] - path = Path(path).resolve() + path: Path = Path(path).resolve() - if "node_modules" in path.as_posix(): + if any( + path.as_posix().endswith(ignore_path) for ignore_path in IGNORE_PATH_ENDSWITH + ): + return [], [] + + if any(ignore_path in path.as_posix() for ignore_path in IGNORE_PATH_CONTAINS): return [], [] # if on mac, ignore Library folder and its children - # TODO: test on real mac if os.name == "posix": library_path = (Path.home() / "Library").resolve() if path == library_path or str(path).startswith(str(library_path)): @@ -43,7 +67,7 @@ def run_fast_scandir(path: str, full=False) -> tuple[list[str], list[str]]: for entry in path.iterdir(): if entry.is_dir(): if entry.name.startswith(".") or entry.name.startswith("$"): - continue # filter out system / hidden files + continue # filter out system / hidden files else: subfolders.append(entry)