Fbrowser/python-src/ScanOrg100.py
stan44 565be4e1e7 Migrate Fbrowser to Rust and Tauri desktop app
- Replace the Python/Docker setup with a Rust workspace and Tauri frontend
- Add core crates for archive, audio, MIDI, plugin, and desktop UI layers
- Refresh the app scaffolding, build config, and documentation
2026-03-30 16:18:26 -05:00

70 lines
2.2 KiB
Python

import os
from PyQt6.QtCore import QThread, pyqtSignal
class FileScanner(QThread):
items_found = pyqtSignal(list)
scan_complete = pyqtSignal()
def __init__(self, path):
super().__init__()
self.path = path
self.stop_requested = False
self.allowed_extensions = {
'.mid', '.midi', '.mp3', '.wav', '.ogg', '.flac', '.aac', '.m4a', '.wma',
'.flp', '.als', '.logic', '.logicx', '.ptx', '.pts', '.cpr', '.rpp',
'.reason', '.sng', '.ardour', '.bwproject'
}
def run(self):
self.scan_directory(self.path)
self.scan_complete.emit()
def scan_directory(self, path):
try:
items = []
with os.scandir(path) as entries:
for entry in entries:
if self.stop_requested:
return
if entry.is_dir():
items.append((entry.path, True))
elif entry.is_file() and entry.name.lower().endswith(tuple(self.allowed_extensions)):
items.append((entry.path, False))
self.items_found.emit(items)
except PermissionError:
print(f"Permission denied: {path}")
except OSError as e:
print(f"Error accessing {path}: {e}")
def stop(self):
self.stop_requested = True
class Organizer:
def __init__(self):
self.file_list = []
self.dir_list = []
self.scanner = None
def start_scan(self, path):
self.file_list.clear()
self.dir_list.clear()
self.scanner = FileScanner(path)
self.scanner.items_found.connect(self.add_items)
self.scanner.scan_complete.connect(self.scan_finished)
self.scanner.start()
def add_items(self, items):
for path, is_dir in items:
if is_dir:
self.dir_list.append(path)
else:
self.file_list.append(path)
def scan_finished(self):
print(f"Scan complete. Found {len(self.dir_list)} directories and {len(self.file_list)} files.")
def stop_scan(self):
if self.scanner:
self.scanner.stop()
self.scanner.wait()