# vgmdb-cuefixer

> **Status:** Active
> **Category:** Audio & CUE Tools
> **Language:** Python 3
> **Script file:** `fixcue.py`

## Purpose

Fixes the `FILE` directive in `.cue` sheets so it matches the actual audio file present in each album folder. Useful when CUE sheets downloaded from VGMdb or generated by other tools reference the wrong filename or file extension.

## Requirements

### Dependencies

Python standard library only — no `pip` installs required.

```
os  (built-in)
```

## Input

| Item | Description | Example |
|------|-------------|---------|
| Root directory | Hardcoded `root_dir` variable inside `fixcue.py` | `C:\trial` |
| Audio + CUE pairs | Each subfolder must contain exactly one audio file and one CUE file | `Album.flac` + `Album.cue` |

### Supported audio formats

| Extension | CUE filetype assigned |
|-----------|----------------------|
| `.flac` | `FLAC` |
| `.tak` | `WAVE` |
| `.wav` | `WAVE` |
| `.tta` | `WAVE` |
| `.ape` | `WAVE` |

## Output

| Item | Description |
|------|-------------|
| Updated `.cue` file | The `FILE "..." <FORMAT>` line is rewritten to match the actual audio file |
| `<name>.cue.bak` | Backup of the original CUE file, created before any change is made |
| Console log | Per-folder status messages printed to stdout |

## Usage

1. Open `fixcue.py` and set the `root_dir` variable to your music library path:

```python
fix_cue_strict(r"C:\MyMusicLibrary")
```

2. Run the script:

```bash
python fixcue.py
```

## Examples

```bash
# After editing root_dir in the script:
python fixcue.py

# Console output example:
# Checking folder: C:\MyMusic\Artist - Album
#   Cue files: ['Album.cue']
#   Audio files: ['Album.flac']
#   → Fixed C:\MyMusic\Artist - Album\Album.cue, backup at C:\MyMusic\Artist - Album\Album.cue.bak

# Checking folder: C:\MyMusic\Artist - Album2
#   Cue files: ['Album2.cue']
#   Audio files: ['Album2.flac']
#   → No changes needed
```

## Notes

- **Hardcoded path:** The target directory is set inside the script (`fix_cue_strict(r"C:\trial")`). Edit this before running.
- Folders with **zero audio files** or **more than one audio file** are skipped automatically.
- Folders with **no CUE file** are skipped automatically.
- Folders with **more than one CUE file** are not explicitly skipped — the first CUE file found will be processed.
- The backup file `.cue.bak` is only created when a change is actually needed. Files that are already correct are left untouched.
- Non-FLAC formats (`.tak`, `.wav`, `.tta`, `.ape`) are all assigned the `WAVE` filetype in the CUE `FILE` line, which is standard behaviour for these containers.

## Related Scripts

- [vgmdb-cuefixer-reverse](vgmdb-cuefixer-reverse.md) — Restore `.cue.bak` backups to undo changes made by this script
- [beets-cuemaker](beets-cuemaker.md) — Generate CUE sheets from scratch
- [vgmdb-cuesplitter](vgmdb-cuesplitter.md) — Split single-file rips using CUE sheets
