# Shytify

A Windows desktop application for reading Spotify collection metadata, finding matching audio recordings on YouTube Music, and producing tagged MP3 files.

Built with **PySide6**, **ytmusicapi**, **yt-dlp**, **FFmpeg**, and **Mutagen**. The current application uses public metadata and does not require Spotify API credentials. Spotify is the metadata source, not the source of downloaded audio.

> Download only media you have permission to save. Shytify is not affiliated with Spotify, YouTube, or their rights holders.

## Current Status

- Current Python source includes custom-only filename templates and automatic cleanup of desktop run records and temporary cover images.
- `dist/shytify.exe`, when present, is an **unsigned Windows x64 candidate**. The existing candidate predates the latest custom-naming and cleanup changes; rebuild it to include them.
- Trusted signing, the full clean-Windows validation matrix, credential revocation and redistribution-license review remain release gates. Do not treat the candidate as a completed public release.

## Features

- Import public Spotify playlist, album and track URLs.
- Import normalized collection JSON or CSV files; inspect a local music folder without re-downloading it.
- Search YouTube Music's Songs catalog rather than regular YouTube video search.
- Match catalog audio using title, artist credits and duration, preferring matching albums.
- Download selected tracks with configurable concurrency and progress/activity views.
- Convert to MP3 and embed available metadata and cover artwork.
- Customize filenames with validated fields and a live preview.
- Keep desktop output folders free of newly generated reports and separate cover images after a run.
- Run local diagnostics and inspect bundled versions, licenses and logs.

## Run From Source

The verified packaging environment is **CPython 3.13.3 x64 on Windows**. Commands below use PowerShell from the project root.

For a fresh checkout, use the dedicated environment and hashed build lock. This also installs the test and packaging dependencies needed to prepare resources:

```powershell
py -3.13 -m venv .venv-build
.\.venv-build\Scripts\python.exe -m pip install --require-hashes -r packaging/build.lock
.\.venv-build\Scripts\python.exe packaging/prepare.py
.\.venv-build\Scripts\python.exe "FINAL SHYTIFY PROJECT.py"
```

Verify that `py -3.13` selects Python 3.13.3 when reproducing the pinned executable build. Preparation requires internet access to fetch pinned vendor tools and license notices. It verifies the vendor archive checksums, prepares the resource tree and generates the application icon/build manifest.

If the existing `.venv` and prepared resources are already available:

```powershell
.\.venv\Scripts\python.exe -m pip install -r requirements-shytify.lock
.\.venv\Scripts\python.exe "FINAL SHYTIFY PROJECT.py"
```

**Installing Python dependencies alone is not enough:** the current source resolves FFmpeg, ffprobe, Deno, assets and build metadata from `shytify/resources`. Globally installed tools on PATH are not a substitute for those resources.

## Desktop Workflow

1. Open **New import** and choose a source.
2. Paste a Spotify URL or select a supported local collection file.
3. Choose the destination and analyze the collection.
4. Select tracks and adjust the custom filename template in **Settings**.
5. Start the download and monitor progress in the queue/activity views.

Only MP3 output is implemented. Existing files follow the configured skip/overwrite behavior. The current controller treats **Ask before replacing** as skip; it does not yet present a per-file replacement prompt.

## Technical Architecture

```text
Spotify public metadata / local collection
                  |
         YouTube Music catalog search
                  |
       Recording validation and selection
                  |
       yt-dlp download by selected ID
                  |
       FFmpeg conversion -> ffprobe validation
                  |
       ID3 metadata and embedded artwork
                  |
       Destination staging -> atomic replacement
```

### Non-Blocking Processing

The PySide6 controller uses `QThreadPool` workers for background operations and signals to deliver progress to the UI. The processing pipeline uses a bounded `ThreadPoolExecutor`, submitting at most the configured worker count at a time instead of queuing an entire playlist upfront. Results are returned in playlist order even when downloads finish out of order.

Cancellation is cooperative: network operations have timeouts, processing stages check a cancellation event, and the FFmpeg subprocess wrapper terminates an active child when cancelled. Pause takes effect at pipeline checkpoints; it does not instantly suspend an in-flight network transfer.

### Media Integrity

- **Identity validation:** downloaded media must report the selected YouTube ID and produce a non-empty file in the expected work directory.
- **Duration validation:** ffprobe checks converted audio for a finite, positive duration within five seconds of the source metadata.
- **Controlled publication:** completed files are copied to a temporary file on the destination volume, flushed with `fsync`, then published using `os.replace`. This supports cross-volume work directories without exposing a partially copied final MP3.
- **Concurrent-run protection:** an OS-backed lock prevents cooperating Shytify processes from processing the same resolved output directory simultaneously.
- **Failure isolation:** track-level failures carry their stage and reason, allowing other tracks to complete without treating the whole collection as successful.

### Dependency And Runtime Controls

The packaging specification verifies pinned Python/package versions and vendor binary SHA-256 hashes before building. Runtime and build locks record exact wheel hashes. FFmpeg, ffprobe and Deno are resolved through absolute bundle-relative paths rather than discovered on the user's PATH.

yt-dlp receives explicit FFmpeg and Deno locations, while EJS scripts are shipped locally and remote component downloads are disabled. The application does not implement in-place dependency self-updates. Startup capability checks run off the UI thread and gate downloading until required tools and package versions pass their checks.

### Operational Diagnostics

Rotating structured logs, per-track failure details and offline diagnostics support troubleshooting without a terminal. Frozen-build smoke tests exercise Qt resources, local conversion/tagging/probing, EJS resource loading and Deno execution. Online extraction checks are separate so an offline machine can still verify its bundled runtime.

## Matching And Accuracy

The matcher accepts only catalog results marked as audio tracks (`MUSIC_VIDEO_TYPE_ATV`). It requires matching normalized titles and artist-credit sets, plus a duration difference of no more than five seconds. Matching album names rank first. Converted audio duration is checked again before publication.

There is **no fallback to music videos**. A missing or unsuitable recording fails with an explanation instead of silently selecting a video soundtrack.

This is conservative metadata matching, not acoustic fingerprint verification. Differences in artist credits or transliteration can reject a valid recording; identically labeled clean/explicit versions or different masters may remain indistinguishable. Public Spotify pages can omit ISRC, album or other fields. Missing metadata is not invented. Unofficial service interfaces and online availability can change.

## Diagnostics

Offline capability check:

```powershell
.\.venv-build\Scripts\python.exe "FINAL SHYTIFY PROJECT.py" --diagnose --output diagnostics.json
```

Add `--smoke-test` to exercise the UI, logo, local synthetic audio conversion/tagging/probing, EJS resources and Deno evaluation. Add `--online-test` explicitly to test song matching and extraction online without downloading a complete song.

For the windowed executable, wait for completion before reading the result:

```powershell
Start-Process -FilePath .\dist\shytify.exe -ArgumentList '--diagnose --output diagnostics.json' -Wait
```

Without `--output`, diagnostics are written to `%LOCALAPPDATA%/Shytify/logs/diagnostics.json`. Settings are under `%LOCALAPPDATA%/Shytify/config`; operational work/locks also use per-user storage. Error dialogs provide **Open logs** and **Copy diagnostics**. Review logs before sharing them.

## Command-Line Usage

Use the Python entry point for console output:

```powershell
.\.venv-build\Scripts\python.exe "FINAL SHYTIFY PROJECT.py" doctor --json
.\.venv-build\Scripts\python.exe "FINAL SHYTIFY PROJECT.py" info "https://open.spotify.com/playlist/PLAYLIST_ID" --json
.\.venv-build\Scripts\python.exe "FINAL SHYTIFY PROJECT.py" download --input collection.json --output downloads --workers 3
.\.venv-build\Scripts\python.exe "FINAL SHYTIFY PROJECT.py" retry --manifest downloads/.shytify-manifest.jsonl
.\.venv-build\Scripts\python.exe "FINAL SHYTIFY PROJECT.py" retag --manifest downloads/.shytify-manifest.jsonl
```

Replace the example playlist ID with a real one. Run a command with `--help` to see its options. **CLI downloads retain manifests and reports** for retry/retagging; desktop custom-naming settings and output cleanup do not apply to this separate workflow. A dry run searches without downloading media but can write dry-run reports.

## Build A Single EXE

After preparing `.venv-build` and resources:

```powershell
powershell -File packaging/build.ps1 -DebugBuild
powershell -File packaging/build.ps1
```

The windowed artifact is `dist/shytify.exe`. Python, Qt, FFmpeg, ffprobe, Deno and Python dependencies are bundled; recipients should not need to install them separately. The one-file executable extracts resources at startup and still needs internet for online actions.

See [packaging instructions](packaging/README.md), the [packaging plan](shytify_WINDOWS_SINGLE_EXE_PACKAGING_PLAN.md) and the [candidate build report](SHYTIFY_SINGLE_EXE_IMPLEMENTATION_REPORT.md). The build report describes the earlier candidate, not subsequent source changes. Revalidate and regenerate release checksums after rebuilding or signing.

## Tests

```powershell
.\.venv-build\Scripts\python.exe -m pytest tests_shytify tests/ui -q
```

The last recorded suite run passed **121 tests**, including custom filename validation, matching rejection cases, pipeline processing, temporary-cover naming and cleanup on success/failure/cancellation. This is not a guarantee of all network, crash or clean-machine scenarios.

## Project Layout

| Path | Responsibility |
| --- | --- |
| `FINAL SHYTIFY PROJECT.py` | Desktop/CLI entry point and diagnostics dispatch |
| `shytify/` | PySide6 UI, controllers, settings and runtime resource handling |
| `shytify_core/` | Metadata, matching, downloading, naming, conversion and tagging |
| `shytify/resources/` | Prepared assets, bundled tools, licenses and build metadata |
| `packaging/` | PyInstaller spec, hashed locks, preparation/build scripts and checks |
| `tests_shytify/`, `tests/ui/` | Core and desktop regression tests |
| `dist/` | Built executable and release verification sidecars |

Legacy copy scripts are reference material, not the current app entry point.

## Known Limitations And Distribution

- The MP3 quality dropdown is not currently wired to separate encoder settings; conversion uses the existing LAME VBR `-q:a 0` setting, not guaranteed 320 kbps CBR.
- Private/restricted Spotify collections and incomplete public metadata may be unavailable.
- End-user single-EXE compatibility still requires the clean-Windows tests specified in the packaging plan.
- The current candidate is unsigned. Windows may warn or block it; do not disable security protections to bypass a warning.
- Previously exposed Spotify credentials must be revoked by their owner. Removing literals from legacy files does not revoke them.
- Third-party notices are included in the resource tree and About view. Public redistribution still requires review of the bundled dependencies' obligations, including FFmpeg GPLv3 corresponding source and Qt/PySide6 terms. Do not assume the entire project has a permissive distribution license.
