Music Quality Upgrader
I DJ, and part of my library was MP3s picked up in a hurry. This tool checks the quality of every track in a playlist, searches for a better file, files it where the old one was and moves the old one to a review playlist. The same code also brings in new tracks: found on SoundMesh, a peer-to-peer network, downloaded at the best available quality, converted to lossless and filed in their playlist, ready for rekordbox.
Python · Docker · ffmpeg · AppleScript
The upgrade loop
One playlist in, better files out. The old file is never deleted.
Pick a playlist
meshd upgrade-batch --playlist=X runs a dry run first: the list of candidates, the plan and the estimated time. Nothing changes until I add --apply.
Check the quality of every track
Everything below lossless is a candidate, MP3 320 included. Already lossless or already upgraded: skipped.
Search for a better file
A track under 320 kbps accepts lossless or MP3 320. A 320 MP3 accepts lossless only. The search widens step by step, and a match check discards files that are not the right track.
Download and convert
If a source fails, the next one takes over. FLAC and WAV become AIFF, metadata travels with the file.
File the new track where the old one was
The new file joins every playlist of the old one, before the old one leaves them. Genre is forced on the new file.
Move the old file to review
The old file goes to a playlist of legacy files to review and delete by hand. It is never deleted automatically.
Nothing found
A 320 MP3 stays as it is, and the miss is logged. Below 320, the track joins the retry queue and the nightly job tries again.
How a run ends With one recap line: upgraded, no lossless found, pending, errors. Past ten tracks, the batch runs in the background and its status is one command away.
How a new track gets in
One command, seven steps, zero intervention. Each step was hardened against a problem hit in real use.
One command
meshd track "Artist" "Title" "Playlist" is the only input needed.
Library check
Already lossless: it stops there. Only in MP3: it switches to the upgrade loop. No duplicates.
Escalating search
A precise query first, then wider and wider until a valid source shows up. The network connection repairs itself if it drops.
Quality and error filter
Lossless first, MP3 320 accepted, everything else rejected. A match check discards files that are not the right track (unwanted remix, another title by the same artist).
Download with fallback
If a source rejects or blocks, the next one takes over, up to five tries. Metadata (genre, artist, title) travels with the file.
Automatic conversion and import
FLAC and WAV become AIFF (lossless, readable by the decks), MP3 320 is kept as is. The file lands in the Music app import folder, which ingests it on its own.
Filing
Genre tagged from the playlist name, track added to that playlist: it is ready to play.
What if the track can't be found? It joins a persistent queue. A nightly job retries the entries that are due: rarities eventually resolve as other peers come online.
The tools
The core flow only needs Docker and the Python standard library.
- meshd (CLI)
- A single-file Python orchestrator, around 3,000 lines. Drives the daemon's REST API and the Music app via AppleScript.
- P2P daemon
- Self-hosted SoundMesh client in Docker, local REST API for search and transfers.
- Conversion hook
- Shell script triggered on every finished download: ffmpeg transcode, real bitrate check, MIME check, metadata.
- Music app
- Watched folder for automatic import; reads and writes genres, playlists and tags via AppleScript.
- Queue
- Retry with a file lock, normalized keys (artist order, accents) and due dates: no duplicates, no network spam.
Two modes
The same code serves two distinct uses.
Upgrade
Replace the library's MP3s with lossless, playlists preserved; the old file goes to a review list, never deleted blindly.
meshd upgrade-batch --playlist=X --applyDownload
Acquire a new track, from search to filing.
meshd track "Artist" "Title" "Playlist"Three iterations
Each version closed a family of problems seen in real use, no speculative features.
Foundations
API search and download · quality filter · session cache
Automation
conversion hook · embedded metadata · playlist by genre · multi-source fallback · lossless upgrade flow
Robustness
upstream de-duplication · escalating search · auto-reconnect · bad-file guard · normalized queue · dated nightly retry · secrets out of code
What's next
The owned backlog: leads identified, noted, and deliberately left aside until the pain justifies them.
Search by compilation
When a single can't be found on its own, look for it through the artist's known albums and compilations already in the library.
Package and share
Extract the personal config, document the install and publish the tool so another DJ can deploy it.
SoundMesh is presented here as a generic peer-to-peer network for freely licensed, self-produced audio. The engineering described (self-hosted daemon, REST orchestration, conversion pipeline, library integration) is independent of the source and applies to any catalog the user can legitimately access.