# Headless YouTube Video Search

Search YouTube for videos, playlists, and metadata without `yt-dlp` or API keys — pure `curl` + regex scraping of YouTube's public search results.

Use when `yt-dlp` is not installed or when you need lightweight discovery (titles, IDs, playlist contents) without downloading.

## Basic Video Search

```bash
QUERY="American Dragon Deutsch ganze Folge"

curl -s "https://www.youtube.com/results?search_query=$QUERY" \
  -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36" \
  -H "Accept-Language: de-DE,de;q=0.9" 2>&1 | grep -oP '"videoId":"[^"]+"' | sort -u
```

Output: `"videoId":"7uIlK37rx-s"` etc. — deduplicate with `sort -u`.

## Extract Video Titles

For each video ID, get the title from the watch page:

```bash
curl -s "https://www.youtube.com/watch?v=$VIDEO_ID" \
  -H "User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36" \
  -H "Accept-Language: de-DE,de;q=0.9" 2>&1 | grep -oP '"title":"[^"]*"' | head -1 | sed 's/"title":"//;s/"$//'
```

## Find Playlists in Search Results

```bash
curl -s "https://www.youtube.com/results?search_query=$QUERY" \
  -H "User-Agent: Mozilla/5.0 ..." 2>&1 | grep -oP '"playlistId":"[^"]+"' | sort -u
```

Exclude `"playlistId":"WL"` (Watch Later — always present).

## Read Playlist Contents

```bash
PLAYLIST="PL7AIGnoKwKLNRpA3-qHYZ-ybBNozO0RFQ"

# Playlist title
curl -s "https://www.youtube.com/playlist?list=$PLAYLIST" \
  -H "User-Agent: Mozilla/5.0" 2>&1 | grep -oP '"title":"[^"]*"' | head -1

# Videos in playlist (count and IDs)
curl -s "https://www.youtube.com/playlist?list=$PLAYLIST" \
  -H "User-Agent: Mozilla/5.0" 2>&1 | grep -oP '"videoId":"[^"]+"' | sort -u
```

## Language Targeting

Set `Accept-Language: de-DE,de;q=0.9` for German results. The header influences YouTube's ranking but doesn't guarantee monolingual results — titles still need manual review.

## Limitations

- **No metadata** (duration, view count, upload date) without deeper page parsing
- **First page only** (~20 results per search) — no pagination implemented
- **Heuristic extraction** — regex patterns may break if YouTube changes its HTML/JS structure
- **Rate limiting**: Don't exceed ~30 requests/minute or YouTube may start returning captchas
