How casualsnek/onthespot works
Project type and purpose
• Onthespot is a standalone, Qt-based desktop music downloader written in Python. There is no remote backend—everything runs on the user’s machine. It provides a GUI frontend, a set of background workers, and integrations with external services (Spotify API, FFmpeg).
File structure
• Top-level:
• build scripts and packaging (build_*.sh / .bat, PKGBUILD)
• pyproject.toml, requirements.txt, setup.cfg for build & packaging
• src/onthespot: core Python package
• Inside src/onthespot:
• gui/ (GUI layer: main windows, dialogs, Qt .ui files)
• worker/ (background tasks: downloader, media conversion, session management)
• utils/ (Spotify API wrappers, generic utilities)
• otsconfig.py and runtimedata.py (configuration & runtime state)
• exceptions.py (error definitions)
• __main__.py (entrypoint)
• portable.py provides a uniform entrypoint for portable builds.
Key insights from README
• The app requires Python3, Qt, FFmpeg, and Spotify credentials.
• It spawns multiple download “workers” (threads) to fetch and convert media.
• Builds can be packaged into platform-specific binaries or wheels.
Main components
a. Frontend (GUI Layer)
• MainUI, MiniDialog, DL_ProgressBtn, ThumbListItem
• Qt UI definitions (.ui files)
b. Application Core
• Controller logic in __main__.py and mainui.py
• Configuration manager (otsconfig.py)
• Runtime state (runtimedata.py)
c. Background Workers
• Session manager (worker/session.py) – handles Spotify OAuth & requests
• Downloader (worker/downloader.py) – fetches raw audio chunks
• Media processor (worker/media.py) – uses FFmpeg for conversion & metadata
• Utility worker functions (worker/utility.py)
d. Utilities
• Spotify API wrapper (utils/spotify.py)
• File & path utilities (utils/utils.py)
e. External Services
• Spotify Web API (network calls)
• FFmpeg CLI (conversion subprocess)
f. File System
• Download directory, chunk storage, metadata & thumbnails
g. Packaging / Build System (optional)
• build scripts, pyproject.toml, setup.cfg
Relationships & data flows
• User clicks “Search” / “Download” in GUI → Controller reads config, pushes tasks into Worker Pool
• Session Manager authenticates & queries Spotify → returns track/album metadata
• Downloader fetches audio data in chunks → posts progress updates back to GUI
• Media Processor invokes FFmpeg subprocess → converts, tags, embeds thumbnail
• Final file is written to disk → GUI Progress Tab is updated
• All errors flow through exceptions.py and are surfaced in dialogs
Architectural patterns & design principles
• Layered architecture: GUI → Controller → Background Workers → External Services → File System
• Separation of concerns:
• gui/ holds only presentation logic
• worker/ handles heavy I/O & CPU work off the main thread
• utils/ isolates third-party API calls
• Thread-safe communication: use Qt’s signal/slot or thread-safe queues for progress updates
• Configuration & runtime state centralized in otsconfig.py and runtimedata.py
• Component names (e.g., MainUI, SessionManager, Downloader)
• Module paths (e.g., src/onthespot/worker/downloader.py)
• Data flows with labels (“search request,” “audio chunk,” “conversion command”)
• Threading boundary between GUI thread and Worker threads
• Configuration load → global settings
• Packaging boundary, if relevant (pyproject.toml → wheel/binary)