# roccobalocco/youmusicdownloader architecture

> Architecture diagram of the GitHub repository roccobalocco/youmusicdownloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/roccobalocco/youmusicdownloader
- Repository: https://github.com/roccobalocco/youmusicdownloader

## Overview

#### Purpose and Entry Points
Desktop Python application for downloading YouTube audio, including batches from direct URLs, YouTube playlists, and Spotify playlists. The main executable/UI entry point is `youMusicDownloader.py`; `executor.ipynb` appears to be an interactive development or execution notebook.

#### GUI Orchestration
`youMusicDownloader.py` owns the PySimpleGUI window, user inputs, option checkboxes, and download actions. It coordinates URL submission, playlist modes, progress/display behavior, and calls into service-specific utilities. GUI rendering support is separated into `utils/drawer.py`.

#### YouTube Acquisition Pipeline
YouTube-specific retrieval and audio download logic is concentrated in `utils/ytFuns.py`. This layer likely isolates `pytube` interactions: resolving individual video URLs or playlist entries, selecting audio streams, and saving downloaded media. The GUI should treat this as the boundary for YouTube network/API behavior.

#### Spotify-to-YouTube Resolution
`utils/sptFuns.py` handles Spotify integration through `spotipy`. Spotify playlist URLs are expanded into track metadata, then those tracks must be converted into searchable/downloadable YouTube targets through the YouTube pipeline. Spotify authentication is an external-service boundary; the README notes an initial OAuth-style console login flow.

#### Batch and Concurrent Downloads
`utils/threadDownloader.py` provides the multi-download execution layer. It is the likely boundary between UI control flow and worker-thread download tasks, allowing playlist and multi-URL requests to run without blocking the desktop interface. It coordinates work derived from `utils/ytFuns.py` and potentially Spotify-expanded track lists.

#### Control and Data Flow
1. A user enters one or more YouTube, playlist, or Spotify playlist URLs in `youMusicDownloader.py`.
2. GUI options determine whether URLs are treated as individual media, YouTube playlists, or Spotify playlists.
3. Spotify inputs pass through `utils/sptFuns.py` to obtain track candidates.
4. Download targets pass to `utils/threadDownloader.py` for batch/concurrent execution.
5. Workers invoke `utils/ytFuns.py` to fetch maximum-bitrate audio and write files locally.
6. UI feedback is rendered or updated through `youMusicDownloader.py` and `utils/drawer.py`.

#### Runtime and External Dependencies
The application runs as a local Python desktop process. Core runtime dependencies are PySimpleGUI for the interface, `pytube` for YouTube access/downloads, and `spotipy` for Spotify playlist access and authentication. Network access to YouTube and Spotify is required; downloaded audio is persisted to the local filesystem.

#### Architectural Boundaries
Keep UI event handling in `youMusicDownloader.py`, presentation helpers in `utils/drawer.py`, service adapters in `utils/ytFuns.py` and `utils/sptFuns.py`, and concurrency/task execution in `utils/threadDownloader.py`. These boundaries are important because provider authentication, URL parsing, media extraction, and thread lifecycle failures should not directly leak into GUI event logic.

Main entry points: [`youMusicDownloader.py`](https://github.com/roccobalocco/youmusicdownloader/blob/main/youMusicDownloader.py) (GUI event controller), [`utils/threadDownloader.py`](https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/threadDownloader.py) (Batch task executor), [`utils/ytFuns.py`](https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/ytFuns.py) (YouTube acquisition), [`utils/sptFuns.py`](https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/sptFuns.py) (Spotify playlist resolver)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop application"]
  node_user(("User<br/>actor"))
  node_gui["GUI event controller<br/>PySimpleGUI app"]
  node_drawer["GUI rendering<br/>presentation helper<br/>[drawer.py]"]
  node_notebook["Interactive executor<br/>development notebook<br/>[executor.ipynb]"]
end

subgraph group_services["Download services"]
  node_thread_downloader["Batch task executor<br/>threaded downloader"]
  node_youtube_adapter["YouTube acquisition<br/>pytube adapter<br/>[ytFuns.py]"]
  node_spotify_adapter["Spotify playlist resolver<br/>spotipy adapter<br/>[sptFuns.py]"]
end

subgraph group_external["External systems"]
  node_youtube{{"YouTube<br/>media service"}}
  node_spotify{{"Spotify<br/>playlist and OAuth service"}}
  node_audio_files[("Local audio files<br/>filesystem output")]
end

node_url_inputs["URLs and options<br/>request data"]
node_download_targets["Download targets<br/>target list"]

node_user -->|"submits"| node_gui
node_gui -->|"reads"| node_url_inputs
node_gui -->|"updates UI"| node_drawer
node_gui -->|"Spotify playlist mode"| node_spotify_adapter
node_gui -->|"starts batch"| node_thread_downloader
node_spotify_adapter -->|"OAuth and playlist lookup"| node_spotify
node_spotify_adapter -->|"track candidates"| node_download_targets
node_gui -->|"YouTube URLs or playlists"| node_download_targets
node_thread_downloader -->|"consumes"| node_download_targets
node_thread_downloader -->|"worker downloads"| node_youtube_adapter
node_youtube_adapter -->|"resolves and fetches audio"| node_youtube
node_youtube_adapter -->|"writes audio"| node_audio_files
node_thread_downloader -.->|"progress and results"| node_gui
node_notebook -.->|"interactive execution"| node_gui

click node_gui "https://github.com/roccobalocco/youmusicdownloader/blob/main/youMusicDownloader.py"
click node_drawer "https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/drawer.py"
click node_notebook "https://github.com/roccobalocco/youmusicdownloader/blob/main/executor.ipynb"
click node_thread_downloader "https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/threadDownloader.py"
click node_youtube_adapter "https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/ytFuns.py"
click node_spotify_adapter "https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/sptFuns.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_user,node_gui,node_drawer,node_notebook toneBlue
class node_thread_downloader,node_youtube_adapter,node_spotify_adapter toneAmber
class node_youtube,node_spotify,node_audio_files toneMint
class node_url_inputs,node_download_targets toneNeutral
```

## Components

### Desktop application

- **User**: actor
- [GUI event controller](https://github.com/roccobalocco/youmusicdownloader/blob/main/youMusicDownloader.py): PySimpleGUI app · Collects URLs, modes, and download options. · `youMusicDownloader.py`
- [GUI rendering](https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/drawer.py): presentation helper · `utils/drawer.py`
- [Interactive executor](https://github.com/roccobalocco/youmusicdownloader/blob/main/executor.ipynb): development notebook · `executor.ipynb`

### Download services

- [Batch task executor](https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/threadDownloader.py): threaded downloader · Runs multi-target downloads off the UI path. · `utils/threadDownloader.py`
- [YouTube acquisition](https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/ytFuns.py): pytube adapter · Resolves videos or playlists and saves maximum-bitrate audio. · `utils/ytFuns.py`
- [Spotify playlist resolver](https://github.com/roccobalocco/youmusicdownloader/blob/main/utils/sptFuns.py): spotipy adapter · Expands Spotify playlists into track candidates. · `utils/sptFuns.py`

### External systems

- **YouTube**: media service
- **Spotify**: playlist and OAuth service
- **Local audio files**: filesystem output

### Other components

- **URLs and options**: request data
- **Download targets**: target list · Video URLs, playlist entries, or Spotify-derived candidates.

## Connections

- User → GUI event controller: submits
- GUI event controller → URLs and options: reads
- GUI event controller → GUI rendering: updates UI
- GUI event controller → Spotify playlist resolver: Spotify playlist mode
- GUI event controller → Batch task executor: starts batch
- Spotify playlist resolver → Spotify: OAuth and playlist lookup
- Spotify playlist resolver → Download targets: track candidates
- GUI event controller → Download targets: YouTube URLs or playlists
- Batch task executor → Download targets: consumes
- Batch task executor → YouTube acquisition: worker downloads
- YouTube acquisition → YouTube: resolves and fetches audio
- YouTube acquisition → Local audio files: writes audio
- Batch task executor → GUI event controller: progress and results
- Interactive executor → GUI event controller: interactive execution
