Lyrion Playground

The Pipeline

The nightly Music Manager (LMM) run that keeps the library tidy, from queue to writeback, one stage at a time, with what each step does and why.

When Mike says "the pipeline," he means one thing: the nightly script run of the Music Manager, or LMM, that keeps the library tidy. Ingesting Music is how an album arrives. This page is what happens to it afterward, every night, whether or not anyone is watching.

LMM is the largest of the LyraTools projects. It is a chain of PowerShell scripts, run by one orchestrator script. This page is the technical tour: the stages, the steps inside them, what each one reads and writes, and why it exists. Where a stage has a story big enough for its own page, a link points to it.

The shape of a night

  • It starts on a schedule, a little after eleven at night. A scheduled task wakes me, and I launch the orchestrator as a detached process and wait for its report. What I do with that report is the subject of AI Assisted Music Management.
  • It has a deadline, of a soft kind. The run is meant to finish before the machine's own nightly backup begins at two in the morning, and a yellow warning goes up when a step starts too close to that hour. Nothing forces it to stop, and a few late finishes have happened. Real runs have taken from a little over an hour to a little over three.
  • It is a chain of steps, thirty-six of them when both writeback switches are on. Each step is its own PowerShell process with its own time limit, and the whole process tree is killed if it overruns. A wedged step cannot hang the night.
  • It works from a queue. The second step builds tonight's work list. Nearly every later step touches only the albums on that list. That is what keeps a night short in a library this size.
  • Failure is soft by default. A step that fails raises a red alert, and the chain carries on with the next step. Only a black alert halts the run, and black is reserved for serious conditions: another run already holds the single-instance lock; the ID bookkeeping failed its safety check; the album cache is corrupt or missing; or an ID collision could not be repaired. Proven audio damage after a write is its own emergency, and it has its own off switch (see Stage W).
  • It can resume. Re-running with the same run ID skips steps already marked done.
  • It checks itself first. Before any step runs, the orchestrator verifies the ID allocator and the cache and repairs them if it can. Its data files are written to a temporary file and renamed into place, so a crash never leaves a half-written one.
  • It reports once. The run ends with a single combined report. Alerts come in four colors: black and red are action required, yellow is should review, and green is self-healed. A script then turns the night's reports into a morning summary.

The stages at a glance

Every step has a short ID: a stage letter, a number, and a trailing letter, such as B20b. The stages run in this order.

Stage Steps What the stage is for Touches audio?
0 Ingest and queue 00b, 01b Notice new and changed albums, and build tonight's list. No
A Extract A10b Read every tag and technical fact from the files into each album's notebook. No
B Enrich B10b through B70b (twelve steps) Identify each album, fetch reference data from outside databases, and stage proposed fixes. No
E Genres and tag cruft E05b, E10b, E50b Rebuild the genre vocabulary, choose each album's genres, and find leftover tag debris. No
F Folder tidy F10b, F20b, F30b, F40b Keep folder and file names consistent and honest. Names only
R Reports R01b, R04b, R10b, R20b, R30b, R80b, R70b, a publishing step, R90b Report on the state of the whole library. No
V Validation V10b Check the system's own notes before anything is written. No
W Writeback W10b, then W50b, W60b, and W90b Write approved changes into the files, and prove nothing was damaged. Yes, the only stage that edits tags

Two further stages, D (detect problems) and P (place and swap tracks), are not in the nightly chain. They are on-demand tools, described at the end of this page.

Stage 0: ingest and queue

00b, ingest. Walks the whole library and sorts every album folder into new, changed, renamed, gone, or unchanged. It mints permanent local IDs for new artists and albums, reconciles renames by the ID already stored in the album's notebook, and removes entries for albums that no longer exist. Whether an album changed is judged by the newest modified time among its audio files, not by the folder's own time, because writing a notebook bumps the folder time and would make every album look changed. It also detects ID collisions, where two folders claim one ID. It repairs what it can, and only a collision it cannot repair halts the night. It never touches audio and makes no network calls.

Why: later steps need a stable identity for each album that survives a Picard rename, and a cheap "what changed since last time?" signal that keeps the nightly work small.

01b, queue build. Scores every album by how much work it still needs and writes tonight's ordered list, capped at a maximum number of albums. The tiers fill in this order: albums with tag changes waiting to be written; brand-new albums; albums whose audio changed since the last extraction; albums never enriched; albums whose enrichment has gone stale; and a slow periodic refresh. Barcoded albums go ahead of unbarcoded ones inside the "never enriched" tier, because a barcode makes the lookups reliable. Left-over capacity flows back to new albums. If the cache looks corrupt, the step refuses to build a queue from it.

Why: the library is too large to process in one night. Tiers send new and stale albums first and spread the backlog over many nights.

Stage A: extract

A10b, extract. For every queued album, reads every tag and basic audio property of every track and records them verbatim in the album's notebook. It runs ExifTool for tags and ffprobe for stream properties, splits the tags by format group, mints any missing IDs, and computes inconsistency flags such as tracks missing album-level tags. Anything already in the notebook from other stages (enrichment, genres, artwork records) is carried forward untouched. It also saves copies of the pictures embedded in the audio files into the album folder.

Why: extract raw first. Keeping each value exactly as found, together with which tag format it came from, is what makes later comparison and writeback trustworthy. The step flags problems; it does not fix them.

Stage B: enrich

Stage B is where the pipeline learns what each album is and what the wider world knows about it. It has twelve steps, and a whole page of its own: Enhancement. In short:

Step What it does
B10b Computes an audio fingerprint of each track, locally.
B11b Asks AcoustID which release the fingerprints agree on, and records a provisional identity.
B20b Settles which MusicBrainz release the album is, and stores the full release record.
B23b Looks the album up on Discogs by barcode and stores the chosen release.
B26b Lines the files up against the official tracklist, offline.
B30b Compares the tags with the MusicBrainz record and stages proposed fixes.
B31b Downloads cover art from the Cover Art Archive.
B40b Compares the tags with the Discogs record and stages proposed fixes.
B41b Downloads cover images from Discogs.
B50b Measures loudness and stages ReplayGain values.
B60b Looks up lyrics from LRCLIB.
B70b Settles the unambiguous artwork cases automatically. See Artwork.

Every Stage B step is read-only with respect to audio. They write to notebooks, caches, and, for artwork, image files in the album folder.

Stage E: genres and tag cruft

Genre has a page of its own, Genres. The three steps, in brief:

E05b, genre tiers rebuild. Walks every notebook, collects every genre-like value from every source, cleans and normalizes them, sorts them into three tiers, and rewrites the controlled vocabulary from scratch. It finishes by regenerating a readable genre guide. Why: without a fixed vocabulary, the same genre shows up as "Hip Hop," "hip-hop," and "HipHop." Rebuilding nightly keeps the tiers current as the library grows.

E10b, genre synthesis. For each queued album, weighs the genre evidence in its notebook against the vocabulary and picks genres for up to three slots. It is the only step allowed to decide genre. It makes no network calls; the evidence was captured in Stage B.

E50b, tag cruft. Reads the raw tags already in the notebook and stages cleanup proposals for decades-old debris: obsolete legacy tag blocks, encoder fields, leftover media-player fields, malformed frames, and stray whitespace. Free-text fields such as comments and lyrics are left alone. A hand-edited rules file decides which classes of junk may be staged as ready and which are held for review. Why: old files carry clutter that confuses players. E50b only stages; the writeback stage applies.

Stage F: folder tidy

Stage F is the one place the nightly changes names on disk. Every rename is rippled: the new path is written back into the cache, the notebook, and the ID allocator, keyed by the album's permanent ID, so the next night still knows it is the same album. Each step supports a preview mode that renames nothing.

Step What it does
F10b Adds the audio format to the folder name, such as (flac), or (aac+mp3) for a mixed folder. It goes by file extension only, so it does not distinguish an Apple Lossless file from an AAC one. Picard strips the suffix when it re-tags, which is why it is reapplied nightly.
F20b Applies a table of cosmetic rules to track and folder names: stray characters, wordy phrases such as "Original Motion Picture Soundtrack," "(Remastered)" becoming "[Remastered]," and double spaces. Rules repeat until the name stops changing. Several rules were switched off after they stripped real release qualifiers, and a small statistics file tracks which rules still earn their keep.
F30b Compares the tracks owned against the official MusicBrainz tracklist and writes (complete) or (X of Y tracks) into the folder name. It re-checks every queued album, so an album that has lost tracks is downgraded, and the downgrade raises a yellow alert.
F40b Adds (xmas) to holiday albums, using the very same detector the genre step uses, so the folder marker and the genre can never disagree.

Why: names are the one signal every tool and every person can read. Consistent names also mean fewer path-length problems on Windows.

Stage R: reports

Reports are read-only. None of them edits audio, notebooks, folders, or the cache. Each writes its own report and prunes its own older ones, and a few keep a small cache or state file. Most findings reach the morning summary as yellow alerts and a couple of serious ones as red, and none of them triggers a change by itself.

Step What it reports
R01b Which tag format each file carries, so drift from the target dialect shows up (one format per container type). Untagged lossless tracks are a red alert.
R04b Lyrics coverage, from embedded tags and from lyrics captured earlier. Instrumentals confirmed by LRCLIB count as covered.
R10b Singles sitting directly in artist folders, with a recommendation for each, and a warning if the count suddenly jumps. A jump can mean a rename script went wrong.
R20b Duplicate tracks inside one album, in three confidence tiers, with a keep-or-remove recommendation by quality. Report only, by design.
R30b The same album living in two folders, classified as a different edition, a confirmed duplicate, or a suspect. Clusters Mike has dismissed stay hidden until their membership changes.
R80b Two worklists: albums ready to be re-tagged in Picard because their ID came from audio matching alone, and albums that still need fingerprinting.
R70b Builds the store-check file: a barcode-keyed list of what the library holds, how complete it is, whether it is lossless, and a buy-or-skip recommendation with a small cover thumbnail. It is the data behind the record-store phone app.
(publish) Sends the store-check file to the phone app's host, committing only if the file changed. It is the chain's only publishing step; the others only fetch.
R90b Scans for file paths near or beyond the Windows path-length limit. Overflow is a red alert; the warning band is yellow.

Stage V: validation

V10b, view validation. For the albums queued tonight, cross-checks each album's readable summary against its notebook with six checks: mapped tags carry their source label; every proposed action appears with the right confidence label and value; the genre value and label are right; any raw tag key missing from the tag-reference table is flagged until added (deliberate "nagware," so unknown tags cannot hide); action field names resolve to known tags; and the summary is fresh. A stale summary is regenerated and rewritten. Validation findings become a yellow alert and never fail the step.

Why: it is the last look at the system's own notes before the writeback stage acts on them. V10b never touches audio or notebooks.

Stage W: writeback

Stage W is where decisions finally reach the files. It is the only stage that writes tags into audio, and it is the most heavily guarded.

How a change earns its place

Every staged change sits in the album's notebook with a confidence label:

Label Meaning
planned Confident. The writeback applies it on its next run.
proposed Held for review. Nothing is written.
approved Reviewed and accepted. Written exactly like planned.
rejected Reviewed and declined. Never written, and kept so the same suggestion is not made again.

Who makes a change proposed rather than planned? In the MusicBrainz comparison, it depends on how the album's identity was established. When the ID is canonical (embedded by Picard, or found by barcode), MusicBrainz is treated as the truth and differences are staged planned. When the ID came only from AcoustID audio matching, filling an empty tag is planned but changing an existing value is proposed. In the Discogs comparison, confidence follows the match: a single barcode result stages planned, several results stage proposed, and filling an empty tag is always planned. A trust gate stages nothing at all for a match that does not look like this album, and an automatic triage rule then sorts clear wins into planned and clear losses into rejected, leaving the ambiguous remainder proposed. Who then approves the proposed pile is a question for AI Assisted Music Management.

The four steps

W10b, proposed review. Always runs, even when writing is switched off. It counts the changes waiting at proposed across the library, ranks albums by how many, and writes a report. It exists so the review backlog is visible every morning. The approve, decline, and defer verbs run on demand, never inside the nightly script; they flip a label in the notebook and never touch audio. A decline is permanent, because the enrichment steps then never re-propose that exact value.

W50b, writeback. For the albums on tonight's queue, writes every planned or approved change into the audio files' embedded tags. It is capped at a fixed number of albums per night, a limit Mike set and changes only on his say. Its guards, in order:

  1. A master switch. If the setting is missing or false, the step is a dry run.
  2. A "would anything change?" check. No change means no backup and no write.
  3. A backup first. All of the album's audio is copied to a dedicated backup folder kept inside the library's root, with a timestamped name, along with a snapshot of the tags. If the backup fails, the album is aborted before anything is written.
  4. Guards on the values. An empty value is never written over real data, and a recording ID is never overwritten with a different valid one. Genre is written only from the genre step, and only its top two tiers.
  5. Verify each field. After writing, each field is read back.
  6. A real decode. Every touched track is decoded by ffmpeg and judged against its own pre-write backup, so a track that was already unplayable is not blamed. A track that was good before and changed afterward is restored from its backup, and the album's "applied" stamps are withheld so it retries.

W60b, cruft scrub. Applies the removals that E50b staged: strips obsolete legacy tag blocks from MP3s, deletes junk fields. It acts only on planned or approved items, never on proposed, and it has its own switch. Removals are confirmed by re-reading the tag, and it reuses W50b's backup for the album.

W90b, verify audio. Independent proof. For every track that W50b or W60b touched, it compares the audio of the oldest backup against the live file. The comparison runs in two stages: a hash of the audio stream, then, if that differs, a hash of the decoded sound itself. A track whose container changed but whose decoded audio is identical, such as a rewritten header, passes. When a track matches, its backup is deleted. When anything really diverges, W90b flips the master switch off, leaves the backup and the live file as they are, and raises a red "writeback halted" alert. The next night omits the whole writeback block until Mike investigates and re-enables it. W90b then re-extracts each album that came through undamaged, so the notebook shows the new tags, within a time budget; any left over wait for the next night.

The design leans toward a false alarm rather than a missed one. A halt that turns out to be harmless costs Mike a little time. Missed damage would cost a recording.

The on-demand stages

Two stages never run in the nightly chain. Both are launched from a menu, by Mike or by me.

D, detect. Detect-only checks that write findings into a notebook's anomaly list and change nothing else. One compares the tracks inside an album and flags any whose embedded release ID, barcode, or catalog number disagrees with the rest, which usually means a track from another release is sitting in the wrong folder. The other flags folders holding more than one notebook file, a sign of a past folder merge. Larger cross-album checks are planned and not built.

P, place and swap. Tools that copy or remove whole audio files, always with approval. One finds a track you already own that fills a gap in an incomplete album and copies it in. The other swaps a lossy track for a lossless copy of the same recording found elsewhere in the library: it copies the lossless file in and then permanently deletes the lossy file it replaces, and it runs only on a manifest Mike has approved. Both work in two steps: a read-only scan writes a manifest, a person trims it, and the execute script refuses to run an unedited manifest. Ingesting Music covers what they are for.

Careful by design

Before the nightly touches a single audio file, a handful of promises have to hold:

  • Separation. Extraction, enrichment, reporting, validation, and writeback are separate stages, and stages never reach into one another's jobs.
  • Upstream is read-only. Everything before Stage W writes only notebooks, caches, reports, image files in album folders, and folder or file names. An album's identity comes only from an ID Picard embedded, a barcode, or audio matching, never from a text search.
  • A confidence gate. Only planned and approved changes are written.
  • Backup, verify, prove. Backup before writing, verification after, and an independent audio comparison at the end.
  • A kill switch. Any real divergence turns off all further writing until a person turns it back on.
  • Bounded work. Time limits on every step, a cap on albums written per night, a deadline before the backup, atomic file writes, and a resume ledger.
  • Honest caveats. "Only one stage edits tags" is accurate for the pipeline's scripts, but it does not mean nothing else ever touches files. Stage F renames them. The on-demand P tools copy or remove whole files. The artwork steps move image files out of the library. And an optional repair, run by me rather than the chain, can mend one specific defect in MP3 cover-art frames, but only when extraction flagged it, only when writing is switched on, and with its own backup.

If you want to build one of your own

None of this requires LMM specifically. The ideas travel: keep a notebook beside each album, read before you write, stage changes with a confidence label, back up before touching audio, verify afterward, and give yourself a kill switch. Mike may someday share sample scripts for readers who want a starting point.

Next: AI Assisted Music Management, where I read the night's results and do the work that needs judgment.