repositories

NixDaemon

NixOS pentest workstation as one flake — IceBreaker's successor

clonegit clone https://git.daemon-sec.xyz/NixDaemon.git
tagx.mdMarkdown179 lines8.5 KiBrendered raw download
# tagx — turn a download folder into a library

Downloaded music arrives with the downloader's filename and, usually, no tags at
all. Every player then files it under *Unknown Artist*. tagx does both halves of
the fix in one pass — clean the name, write the tags — and can file the result
into `Artist/Album` folders while it is there.
Quick card: **`tagx-cheat`**. Plan without touching anything: **`tagx … -n`**.

```
tagx -d ~/Music/gems --artist daemon --album daemon
```

## The one command
- **`tagx -d DIR --artist NAME --album NAME`** — the whole job: rename, tag, done.
- **`tagx DIR --artist NAME`** — a positional directory works as a synonym for `-d`.
- **`-n`** — print the plan and change nothing. The output is identical to the real run, because a preview that formats differently from the thing it previews is worthless.
- **`tagx`** with no arguments prints the banner and the full help rather than silently doing nothing.
- **`-R`** recurses. **`-v`** also lists the files that already need no change.

## What "clean the name" actually removes
Six steps, applied in this order. Each one has its own off switch.

| # | What | Example |
|---|---|---|
| 1 | yt-dlp's video id | `song [dQw4w9WgXcQ].mp3` → `song.mp3` |
| 2 | fullwidth stand-ins | `| ? : / *` → `- ` `` `: / ` (nothing) |
| 3 | decorative unicode | `𝐃𝐄𝐅𝐄𝐍𝐃 𝐖𝐇𝐀𝐓'𝐒 𝐎𝐔𝐑𝐒` → `Defend What's Ours` |
| 3 | smart punctuation | `" " ' ' – — …` → `" " ' ' - - ...` |
| 4 | uploader furniture | `(REUPLOAD)` `(Official Video)` `(Lyrics)` `(HD)` `(Free Download)` |
| 5 | title case | `PART OF ME (HARDSTYLE)` → `Part of Me (Hardstyle)` |
| 6 | spacing | ` - ` evened out, runs of spaces collapsed, trailing junk trimmed |

**Why step 2 exists at all.** `|` `?` `:` `/` `*` `<` `>` `\` are illegal in
filenames, so yt-dlp substitutes fullwidth lookalikes — `|` `?` `:` `/` `*`.
Those are perfectly legal characters, which is exactly the problem: nothing ever
removes them again. They survive into the tag, the playlist, the phone, and every
search you ever run against the library.

**Why step 3 exists.** People title videos in 𝐛𝐨𝐥𝐝 and 𝓼𝓬𝓻𝓲𝓹𝓽 because YouTube
strips markup but not codepoints. Those characters sort and search as nothing at
all. tagx walks each character's Unicode decomposition back to ASCII.

## Why title-casing needs a word list and not a rule
There is no rule. Every shortcut has a counterexample:

- `str.title()` gives you **`Ex'S And Oh'S`** — it capitalises after every non-letter.
- "short and uppercase means acronym" gives you **`Part of ME`** and **`Viva LA Vida`**, because `ME` and `LA` are as short and as uppercase as `NATO`.

So tagx carries two lists instead:

- **ACRONYMS** stay capitalised — `NATO RDA USA UK EU DJ MC ET TV OK XO EDM BPM VIP NRG HQ OG AM PM II III IV 4K 8D 3D LSD DNB UKG AKA`. Extend it per run with **`--acronym WORD`** (repeatable).
- **Small words** drop to lowercase when they land mid-title — `a an the and but or nor for on at to from by of in with vs as into onto over`. Never at position 0, and never straight after an opening bracket, so you get `(In the End)` and not `(in the End)`.

Anything containing non-ASCII is left **completely** alone. `билборды - снег` has
no title case worth guessing at, and guessing would only damage it.

## Tags
| Flag | ID3 (mp3) | MP4 (m4a) | Vorbis (flac/opus) |
|---|---|---|---|
| `--artist` | `TPE1` | `©ART` | `ARTIST` |
| `--album` | `TALB` | `©alb` | `ALBUM` |
| `--albumartist` | `TPE2` | `aART` | `ALBUMARTIST` |
| `--genre` | `TCON` | `©gen` | `GENRE` |
| `--year` / `--date` | `TDRC` | `©day` | `DATE` |
| `--number` | `TRCK` | `trkn` | `TRACKNUMBER` |
| (title, always) | `TIT2` | `©nam` | `TITLE` |
| `--cover` | `APIC` | `covr` | `PICTURE` |

- **`--albumartist` defaults to `--artist`.** Without it, players that group by album artist scatter one album across as many "albums" as it has track artists.
- **`--number`** writes `1/N` … `N/N` in sort order.
- **The title is not a separate decision.** It is always set from the cleaned filename, so the name and the tag can never drift apart. **`--no-title`** opts out.

## ID3v2.3, deliberately
mutagen defaults to **2.4**. 2.4 is the better spec and it is also the one that
**Windows Explorer, several car head units, and older rekordbox/Serato builds
cannot read** — a DJ-adjacent library saved as 2.4 shows up blank in exactly the
places it matters. So every `.mp3` is saved `v2_version=3`.

Other containers are unaffected: m4a gets atoms, flac and opus get Vorbis
comments, and none of them have a 2.3-vs-2.4 question. That cross-format writing
goes through mutagen's `easy` mapping — one dict of plain names, three different
tag systems underneath.

## Cover art
The one field with **no** `easy` mapping, because every container stores the
bytes its own way:

- **mp3** — `APIC` frame, type 3 (front cover), existing ones replaced.
- **flac** — `PICTURE` block, existing pictures cleared first.
- **m4a / mp4 / aac** — `covr` atom, PNG or JPEG chosen from the file's extension.
- Anything else — reported and skipped. Not fatal to the run.

```
tagx -d ~/Music/gems --artist daemon --album daemon --cover ~/art/gems.jpg
```

## Filing into folders
**`--organize`** moves each file to `DIR/Artist/Album/Title.ext`. It needs both
`--artist` and `--album`, and it refuses to combine with `--no-rename` — moving a
file *is* renaming it.

Tag values used as directory names get the same sanitising as filenames:
`/ \ : * ? " < > |` become `-`.

```
tagx -d ~/Music --artist VA --album Rips -R --organize     # flatten a messy tree
```

## Collisions
Two differently-named downloads that clean to the same title are usually **two
different rips**, not a duplicate. So the second one gets a ` (2)` suffix and
nothing is ever overwritten:

```
Clarity (Hardstyle).mp3
Clarity (Hardstyle) (2).mp3
```

## Undo
Renaming is the half you cannot retype, so every run that moved anything writes
**`.tagx-undo.json`** into the directory it worked on, and:

```
tagx -d DIR --undo
```

walks it backwards and then deletes the journal.

- **Tags are not rolled back.** They are overwrites of fields you asked to set, not deletions — there is no previous value worth restoring.
- **One journal per directory.** A second run replaces the first's, so undo reaches back exactly one run.
- Undo **skips** any file that has since moved away, or whose old name is now occupied, and names each one it skipped.

## Turning parts off
| Flag | Effect |
|---|---|
| `--no-rename` | tag only — filenames untouched |
| `--no-tags` | rename only — the audio files are never opened |
| `--no-title` | set artist/album but leave each title tag alone |
| `--keep-case` | no title-casing (a library that is already correct) |
| `--keep-ids` | keep the trailing `[videoid]` |
| `--keep-noise` | keep `(Official Video)`, `(REUPLOAD)`, `(HD)` |
| `--acronym WORD` | one more word that stays capitalised, repeatable |
| `--ext mp3,flac` | which extensions count as audio |

`--no-rename` together with `--no-tags` is refused: it leaves nothing to do.

## Formats
Handled: `mp3 m4a mp4 aac flac ogg opus oga wav aiff aif wma wv ape mpc`.
mutagen decides what a file really is by reading it, not by trusting the
extension — `--ext` only controls which files are *offered* to it.

## Inspecting
```
tagx -d ~/Music/gems --show          # one line per file: name, artist · album
tagx -d ~/Music/gems --show -v       # plus the title tag
```
`--show` writes to stdout unstyled when piped, so `tagx --show | grep -c daemon`
means something.

## End to end
```bash
ytget -a 'https://youtube.com/playlist?list=…' -o ~/Music/gems   # 1. grab
tagx -d ~/Music/gems --artist daemon --album daemon -n           # 2. look
tagx -d ~/Music/gems --artist daemon --album daemon --number     # 3. do it
tagx -d ~/Music/gems --show                                      # 4. check
tagx -d ~/Music/gems --undo                                      # 5. or not
```

Re-running is safe and cheap: a clean name cleans to itself, so a second pass
renames nothing and simply rewrites the same tags.

## Colour and environment
Rose Pine via `ricefx`, which sits beside it in `~/.local/bin`. A standalone copy
on another box has no sibling to import — the built-in ramp takes over and the
tool works unchanged. **`NO_COLOR`**, **`RICEFX_OFF`**, **`--raw`**, and a
non-tty stderr each drop it to plain text.

Requires **mutagen** (`pip install mutagen`). Without it, `--no-tags` still works
— that path never opens an audio file.