from pathlib import Path from serato_doctor.models.filesystem import BrokenSymlink, FilesystemScan from serato_doctor.models.track import DiskTrack AUDIO_SUFFIXES = {".mp3", ".m4a", ".wav", ".aif", ".aiff", ".flac"} def scan_filesystem(folder: Path) -> FilesystemScan: tracks = [] broken_symlinks = [] for path in folder.rglob("*"): if path.is_symlink() and not path.exists(): try: target = path.readlink() except OSError: target = None broken_symlinks.append(BrokenSymlink(path=path, target=target)) continue if not path.is_file(): continue if path.suffix.lower() not in AUDIO_SUFFIXES: continue try: stat = path.stat() except OSError: continue tracks.append( DiskTrack( path=path, filename=path.name, size=stat.st_size, suffix=path.suffix.lower(), ) ) return FilesystemScan( tracks=tuple(tracks), broken_symlinks=tuple(broken_symlinks), ) def scan_audio(folder: Path) -> list[DiskTrack]: """Scan audio files while preserving the prototype API.""" return list(scan_filesystem(folder).tracks)