---
name: Prepare Discography
description: Scan an artist's album folders, identify exact release editions, and produce a discography summary.
version: 1
mode: agentic
triggers:
  - type: directory
inputs:
  artist_name:
    type: string
    description: Artist / band name
    autofill: entry_name
---

# Prepare Discography

You are given an artist/band directory containing one subfolder per album. Your job is to identify the **exact release edition** of each album and produce a `discography.md` summary file.

## Why this matters

Album folders often contain special editions, anniversary reissues, deluxe multi-disc sets, etc. A naive search for "The Doors 1967" returns the original 11-track release, but the folder might contain a 50th Anniversary 3CD edition with 30+ tracks. You must identify the **specific edition** the user has.

## Process

For each album subfolder in the artist directory:

### 1. Analyze local signals

Gather as much information as possible from the folder itself **before** searching the web:

- **Folder name**: often contains year and album title, sometimes edition hints like `(3CD)`, `(Deluxe)`, `(Remaster)`
- **Disc structure**: count `CD1/`, `CD2/`, etc. subdirectories — this tells you how many discs the release has
- **Track count per disc**: list audio files in each disc folder (or root if single-disc)
- **Track names**: the filenames often contain track titles (e.g. `01 - Break on Through.flac`)
- **Audio tags**: use the `mutagen` tool with `action: read` on 1-2 representative tracks per disc to get tagged metadata (artist, album, year, genre, label, etc.)
- **Existing files**: check for `album-info.md`, `Front.jpg`, `cover.jpg`, or `Scans/` — these provide additional context

### 2. Build a search profile

From the local signals, construct a profile:
- Artist name (from tags or folder name)
- Album title (from tags or folder name)
- Release year (from tags or folder name)
- Number of discs
- Track count per disc
- Any edition keywords (deluxe, remaster, anniversary, etc.)

### 3. Search for the exact release

Use `web_search` to find the specific edition:
- Search Wikipedia first: `"<artist> <album> wikipedia"` — Wikipedia often has edition/reissue details
- Search MusicBrainz: `"<artist> <album> musicbrainz"` — MusicBrainz catalogs every pressing and edition
- If the disc/track count doesn't match the first result, refine: `"<artist> <album> deluxe 3CD"` or similar
- Use `web_fetch` on the most relevant pages to confirm the tracklist matches your local files

### 4. Confirm the match

Compare the web result against local signals:
- Does the disc count match?
- Does the track count per disc match (approximately)?
- Do track names align?
- If there's a mismatch, search for alternative editions until you find the best match

### 5. Rename the album folder

Once you have confidently identified the release, rename the album folder to the standardized format:

```
[YYYY] Album Title (Edition Marker)
```

- **YYYY** = original release year (NOT the reissue/special edition year)
- **Album Title** = canonical album name
- **Edition Marker** = only if it's not the standard original release. Examples: `50th Anniversary 3CD Deluxe Edition`, `2017 Remaster`, `Deluxe Edition`
- If it IS the plain original release, omit the parenthetical: `[1967] The Doors`

Use `mv` via Bash to rename. Do this **before** writing discography.md so the file references the new folder names.

## Output

Write a `discography.md` file in the **artist directory** (the target directory from Context) with this structure:

```markdown
# Artist Name — Discography

## Albums

### [YYYY] Album Title (Edition Marker)
- **Folder**: `[YYYY] Album Title (Edition Marker)/`
- **Format**: FLAC / MP3 / Mixed
- **Discs**: N
- **Tracks**: N (or N per disc: D1: X, D2: Y, ...)
- **Year**: YYYY (original release) / YYYY (this edition)
- **Label**: ...
- **Genre**: ...
- **Edition**: 50th Anniversary Deluxe Edition / Original / Remaster / etc.
- **Wikipedia**: https://en.wikipedia.org/wiki/... (if found)
- **MusicBrainz**: https://musicbrainz.org/release/... (if found)
- **Notes**: ...

### [YYYY] Another Album
...
```

Sort albums chronologically by original release year.

Include **direct URLs** to the sources used (Discogs release page, Wikipedia article, MusicBrainz release) — these will be used by downstream tasks to avoid redundant searching.

## Important

- **Accuracy over speed**: it's better to correctly identify 3 out of 4 albums than to guess all 4 wrong
- **Wikipedia and MusicBrainz are your primary sources** for edition identification
- **Use mutagen sparingly**: read 1-2 tracks per disc, not every file
- **Track count is the strongest signal** for distinguishing editions — a 3CD set with 10+12+8 tracks is very different from a single-disc 11-track original
- **Folder name hints**: `(3CD)`, `(2LP)`, `(Deluxe)`, `(Remaster)`, `(Anniversary)` in the folder name are strong clues
- **Do NOT make up information**. If you cannot confidently identify an edition, note what you found and flag the uncertainty
- The artist name in the folder may be formatted as `Last, First` or `Name, The` — normalize it when searching (e.g. `Doors, the` → `The Doors`)
