# Recipes

Working examples for the things people actually do with `btdl`.
Every one of these is copy-pasteable; each ends with a one-line
explanation of the contract it relies on.

## Download an artist’s whole discography

```console
$ btdl artist albums https://tidal.com/artist/1234567 --json \
    | jq -r '.[] | "https://tidal.com/album/\(.id)"' > /tmp/artist_albums.txt
$ btdl plan-many $(cat /tmp/artist_albums.txt) --json \
    | jq '[.[].download_count] | add'          # 143 tracks to fetch
$ btdl download-many $(cat /tmp/artist_albums.txt)
```

`plan-many` spends no stream: check the numbers first, then commit.
One dead album id never sinks the batch (per-URL isolation).

## What will this album actually play as?

```console
$ btdl resolve https://tidal.com/album/1234 --json | jq '.id'
$ btdl tracks https://tidal.com/album/1234 --json | jq -r '.[].id' > /tmp/ids.txt
$ btdl playback-many $(cat /tmp/ids.txt) --json \
    | jq -r '.[] | select(.ok) | .delivered_quality' | sort | uniq -c
```

The count of `LOSSLESS` vs `HI_RES_LOSSLESS` is what your plan’s
ceiling will actually deliver — before a single download.

## Stream a track into the player (no file on disk)

```console
$ btdl stream https://tidal.com/track/5678 | ffplay -f wav -
```

Without `--out`, the plaintext bytes *are* the stdout payload;
progress stays on stderr. (`ffplay -f wav -` for a 30 s preview:
add `--preview`.)

## Pre-flight a download without touching disk

```console
$ btdl plan https://tidal.com/playlist/12345 --json \
    | jq "{ total, download_count, skip_count, video_count, dest, quality }"
```

`skip_count` is your resume state: re-run `plan` any time and the
already-complete files stay skipped (the HEAD size check only
triggers a re-download when it *can* determine truncation).

## Retry only the items that failed

```console
$ btdl download https://tidal.com/album/1234 --json 2> /dev/null \
    | jq -r '.items[] | select(.status == "failed") | "\(.id) \(.reason)"'
```

The report is the payload; a failed item is a *row*, not a crash.
Fix the cause (subscription, region) and re-run the download —
everything already on disk is skipped.

## Check one local file against a link

```console
$ btdl check "$HOME/Music/btdl/Artist/Album/01 - Title.flac" \
    https://tidal.com/track/5678 --verify --json | jq '.satisfied'
```

`--verify` runs the library’s media verification (ffprobe) instead
of trusting file size alone.

## Two accounts, one terminal

```console
$ btdl --token ~/.config/btdl/family.json auth device-login
$ btdl --token ~/.config/btdl/family.json -q master download <url>
$ btdl auth token        # the default account stays independent
```

The token file is the whole “session”: point `--token` (or
`BTDL_TOKEN`) at a different file and every command — including
`download`’s output layout — runs for that account.

## Batch: every album from a genre, in the background

```console
$ btdl genre-items "Electronic" --type albums --limit 50 --json \
    | jq -r '.items[] | "https://tidal.com/\(.kind)/\(.id)"' \
    | xargs -n1 btdl download >> /tmp/btdl.log 2>&1 &
```

Progress lands in the log (stderr); the machine-readable reports
are the `--json` ones — add the flag per invocation if you want to
collect them.

## Transcode a finished download for the CDJ

```console
$ btdl maintain transcode \
    "$HOME/Music/btdl/Artist/Album/01 - Title.flac" \
    "$HOME/Music/cdj/01 - Title.wav" --preset cdj2000
$ btdl maintain probe "$HOME/Music/cdj/01 - Title.wav" --json \
    | jq '.container, .codec, .duration'
```

Presets are the library’s CDJ profiles; `probe` confirms the
result’s container/codec facts.
