feat: --repair flag to re-tag existing downloads from source metadata

Walks <root>/<artist>/<source>/ (known yt-dlp source folders only; skips Lidarr
album dirs), re-queries each file's source by the [id] in its filename, and fixes
tags (album/year/artist/title) via mutagen. Honors --dry-run for preview. CLI-only
(not the REST API). Fixes downloads that landed with missing album / wrong year.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-09 19:11:43 -07:00
parent 74eb63b243
commit fdc3cc84a5
3 changed files with 289 additions and 4 deletions

View File

@@ -94,6 +94,7 @@ export LIDARR_API_KEY="your-lidarr-api-key"
| `--yt-only` | Skip Lidarr. |
| `-o`, `--root PATH` | Output root folder (default `/media/music`). |
| `--search-all` | Search all albums when adding an artist to Lidarr. |
| `--repair` | Re-tag existing downloads under `--root` from source metadata (see below). |
| `--debug` | Verbose output. |
### Examples
@@ -115,8 +116,26 @@ export LIDARR_API_KEY="your-lidarr-api-key"
# YouTube only, lossless preferred
./musicfetch --yt-only -q flac "Bonobo - Kerala"
# Download by URL (YouTube Music URL preferred for correct art)
# Download by URL (single track or playlist/set/album, any yt-dlp site)
./musicfetch "https://music.youtube.com/watch?v=xxxxxxxxxxx"
./musicfetch "https://soundcloud.com/artist/sets/my-mix"
```
### 🔧 Repair existing tags
`--repair` walks `<root>/<artist>/<source>/` (the `youtube`/`soundcloud`/… download
folders — Lidarr album folders are skipped), re-fetches authoritative metadata for each
file using the `[id]` in its filename, and fixes tags (album, year, artist, title). Useful
when downloads landed with missing album or wrong year. It re-queries the source over the
network, so run it occasionally, not constantly. Requires `mutagen` (a yt-dlp dependency,
usually already present). CLI-only — not exposed via the REST API.
```bash
# Preview what would change (writes nothing)
./musicfetch --repair -d
# Apply fixes under a specific root
./musicfetch --repair -o /media/music
```
### 📁 Output Structure
@@ -124,8 +143,10 @@ export LIDARR_API_KEY="your-lidarr-api-key"
```text
<root>/
├── Artist Name/
│ ├── Album Name/ (managed by Lidarr)
── youtube/ (yt-dlp downloads / fallbacks)
│ ├── Album Name/ (managed by Lidarr)
── youtube/ (YouTube / YouTube Music downloads)
│ ├── soundcloud/ (SoundCloud downloads)
│ └── <source>/ (one folder per yt-dlp source)
```
---