# Bulk YouTube → MP3 v3.3 SearchBridge (macOS)

A small local app: paste a messy list of song names, or paste YouTube URLs and
let YouTube's autoplay mix decide what comes next.

The v3.3 app window must show **Bulk YouTube → MP3 v3.3 SearchBridge**, a
**Mode** toggle (Song list / Similar to URL(s)), an **Output format** dropdown,
a browser-cookies selector, and a **Test one song / Preview mix** button. If
not, an older copy is running.

## What changed in v3.3

- Similar-to-URL mode uses YouTube URLs for discovery, then downloads each
  Mix entry through the same title-search route that already works for Song
  list mode. This avoids repeatedly hitting blocked exact Mix video IDs.
- v3.3 restores the smooth Song-list behavior for Similar-mode downloads: it
  asks yt-dlp to walk a search batch and take the first usable MP3, instead of
  converting every result back into a restricted exact URL.
- Each Mix title gets multiple rescue attempts (`title + channel`, `title`, and
  `title official audio`) and the app tries several YouTube search results, not
  just the first one.
- If one Mix item is genuinely unavailable, SearchBridge replaces it with another
  related track from the same expanded Mix pool so the requested count is based
  on usable tracks, not just attempted URLs.
- Recovered tracks are logged as OK with a small "rescued via song search" note.
  Items that fail all rescue attempts are written to `blocked-restricted.txt`.

## Setup

No Xcode Command Line Tools and no Homebrew ffmpeg are needed. The packaged zip
includes yt-dlp, ffmpeg, and ffprobe. Python 3 and Tkinter usually ship with
macOS; if Python is missing, install the small Python package from python.org.

## Verify before a big batch

```bash
./Verify\ This\ Build.command
```

It tests one first-result YouTube download and one SearchBridge Similar-mode URL
with the exact bundled folder.

You can also run helpers directly:

```bash
# Single-song self-test
python3 tools/downloader.py --self-test "Qubool - Hashmat Sultana"

# Direct URL self-test for Similar mode
python3 tools/downloader.py --self-test-url "https://www.youtube.com/watch?v=G-97dXiY0sQ"

# Resolve a seed URL into its similar-songs queue (no download)
python3 tools/downloader.py --expand-mix "https://www.youtube.com/watch?v=G-97dXiY0sQ" --count 50
```

## Run it

```bash
python3 tools/downloader.py
```

A window opens. Pick a mode at the top.

### Mode: Song list

1. Pick an **Output folder** (default `~/Downloads/songs`).
2. Paste your song names into the big textbox.
3. Click **Test one song**, then Start.

### Mode: Similar to URL(s)

1. Switch the mode toggle to **Similar to URL(s)**.
2. Paste one or more YouTube URLs (`youtube.com/watch?v=…`, `youtu.be/…`,
   `music.youtube.com/…`), one per line.
3. Pick **Similar songs per seed**: 10 / 50 / 100 / 200 / 500.
4. Click **Preview mix** to confirm the first seed produces tracks.
5. Click Start. The app fetches each seed's YouTube Mix (`RD<videoId>`
   playlist), builds a larger related-track pool, dedupes across seeds via
   `.download-archive.txt`, and downloads each MP3 through title search first.

## What you get

In the output folder:

- `*.mp3` — one file per track, with embedded cover art and metadata.
- `results.csv` — every input line with status, matched YouTube title, URL,
  file path, error, seed URL, and timestamp.
- `failed.txt` — retryable failures from this run.
- `blocked-restricted.txt` — tracks that failed all rescue attempts; these are
  skipped cleanly so the rest can finish.
- `.download-archive.txt` — yt-dlp's record of video IDs already fetched.

## If YouTube pushes back

- Browser cookies are enabled by default and can be read from Chrome, Brave,
  Edge, Firefox, or Safari.
- If YouTube says "Sign in to confirm you're not a bot", open the selected
  browser, sign in to YouTube, play one normal video, then retry.
- If a few tracks are genuinely restricted, v3.3 records them as blocked and
  continues the batch rather than repeatedly failing on the same error.

No local downloader can guarantee every YouTube video when YouTube serves only
PO-token/SABR/DRM-restricted streams or blocks the account/IP. SearchBridge
searches for a downloadable matching upload and keeps everything else moving.

## Legal

Downloading copyrighted audio from YouTube may violate YouTube's Terms of
Service and copyright law in your jurisdiction. Use this tool only for content
you have the right to download. Your responsibility.