aria

Apple Music Lossless Audio Service — an HTTP API and pipeline for downloading Apple Music tracks in AAC 256k and Hi-Res ALAC (24-bit / 48kHz+).

ALAC 24-bit AAC 256k REST API 48/96/192 kHz

1. What is aria?

aria is a self-hosted service that downloads Apple Music tracks in lossless quality. Give it a song ID or album ID, and it returns a fully tagged .m4a file — with cover art, metadata, and bit-perfect audio.

It supports two quality tiers:

AAC 256k

Lossy, compact. Uses Widevine CDM + mp4decrypt. ~5 MB per track. Good for casual listening.

ALAC 24-bit / 48kHz

Lossless, Hi-Res. Uses FairPlay via sidecar. ~50 MB per track. Bit-for-bit identical to the studio master.

2. Audio Formats Explained

If you're new to lossless audio, here's what the terms mean:

FormatTypeBitrateQualityFile Size (4 min)
MP3 320kLossy320 kbpsGood~10 MB
AAC 256kLossy256 kbpsVery Good (better than MP3 at same rate)~8 MB
ALAC 16/44.1Lossless~900 kbpsCD Quality~27 MB
ALAC 24/48Lossless~2500 kbpsHi-Res (studio master)~50 MB
ALAC 24/192Lossless~9200 kbpsUltra Hi-Res~180 MB

ALAC (Apple Lossless Audio Codec) compresses audio without losing any data. When you decompress it, you get back the exact same samples the studio recorded. This is different from AAC/MP3, which permanently discard sounds your brain is less likely to notice (psychoacoustic masking).

Bit depth (16 vs 24) determines dynamic range — 24-bit can represent quieter details. Sample rate (44.1 vs 48 vs 192 kHz) determines the highest frequency that can be captured — 48kHz covers well beyond human hearing (20kHz).

3. How the Pipeline Works

When you request a track, aria goes through 9 steps to deliver a playable file:

1
You provide a song ID

e.g. python aria_lite.py 1615585008 --fmt alac

2
aria asks Apple for metadata

Calls the Apple Music catalog API to get the song's name, artist, album, artwork URL, and HLS playlist URL.

3
Apple returns an HLS master playlist

A .m3u8 file listing all available quality variants (AAC, ALAC at various sample rates).

4
aria picks the best variant

m3u8_select.py chooses the highest-quality ALAC stream (24-bit, up to 192kHz).

5
aria downloads the encrypted audio

The stream is a fragmented MP4 file (50+ MB) containing encrypted ALAC samples. Downloaded from Apple's CDN.

6
sidecar decrypts each sample

Samples are sent over TCP to the sidecar service, which decrypts them one by one using FairPlay. Pipelined for speed (15 MB/s).

7
aria repairs the container

m4a_writer.py patches the MP4: renames enca (encrypted) to alac in all sample descriptions, and neutralizes encryption metadata boxes.

8
aria writes metadata

Uses mutagen to embed title, artist, album, track number, cover art (1200x1200 JPEG) into the .m4a iTunes atoms.

9
You get a playable .m4a file

24-bit / 48kHz ALAC, fully tagged, ready for any player.

4. System Architecture

aria_lite.py client CLI aria server (Flask :8899) apple_api.py catalog + auth m3u8_select.py variant picker streaming_bmff.py zero-buffer parser (11 MB peak) Apple Music API amp-api.music.apple.com DecryptPool (round-robin, per-instance mutex) instance 0 :47010 / :47020 instance 1 :47011 / :47021 ... N :4701N sidecar (user namespace) :47010 dec :47020 m3u8 samples m4a_writer.py enca to alac + senc/saiz/saio to free mutagen title, artist, album, cover art Tagged .m4a

5. Fragmented MP4 Internals

Apple Music delivers audio as fragmented MP4 (fMP4). Understanding its structure is key to the container repair step.

Before (encrypted) vs After (decrypted) Before ftyp (file type) moov / trak / stsd enca (encrypted) enca (encrypted) moof / traf senc saiz saio trun mdat (encrypted samples) ... more moof + mdat fragments ... After (patched) ftyp (unchanged) moov / trak / stsd alac (decoded) alac (decoded) moof / traf free free free trun mdat (decrypted samples) ... patched fragments ... Key fixes in m4a_writer.py: 1. Rename ALL enca entries to alac (not just the first — the original bug) 2. Replace senc/saiz/saio with free boxes (same size, preserves byte offsets)

6. TCP Pipelined Protocol

The decrypt step uses a pipelined TCP protocol. Instead of send-wait-recv per sample (serial), aria uses two threads that run simultaneously:

Serial (4.36s) send s1 -> wait -> recv p1 send s2 -> wait -> recv p2 send s3 -> wait -> recv p3 ... (2650 round-trips, one at a time) Pipelined (3.12s) Writer: send s1, s2, s3, s4, s5... Reader: recv p1, p2, p3, p4, p5... Semaphore gate: max 64 in-flight (both run simultaneously, full duplex) 10.9 MB/s 15.3 MB/s TCP_NODELAY is required Without it, Nagle's algorithm delays small packets and the connection resets (timeout). With TCP_NODELAY + pipelining: 57x faster than the original Go implementation (193s to 3.4s).

7. Usage Examples

Single track (AAC)

aria_lite.py
$ python aria_lite.py 1615585008

    ┌─────────────────────────────────────────────┐
    │  aria_lite — Apple Music Audio Pipeline      │
    └─────────────────────────────────────────────┘
    remote  http://your-server  via proxy
    aria    connected via LAN direct

09:12:30 [    init] song_id=1615585008
09:12:30 [     key] key=7c9cd95cb929... cached=True stream=yes
09:12:31 [   fetch] ██████████████████████████████ 100% 5718/5718 KB
09:12:31 [ decrypt] mp4decrypt done
09:12:31 [  verify] valid audio — 167.4s

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  Result
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  1 downloaded
  duration 2:47 · size 5.5 MB · elapsed 1.2s

Hi-Res ALAC

ALAC 24-bit/48kHz
$ python aria_lite.py 1850496033 --fmt alac

09:14:22 [    aria] downloading ALAC via aria service
09:14:35 [    aria] 48861 KB downloaded
09:14:35 [  verify] valid ALAC — 226.1s (2650 packets, 48000Hz, 24bit)
09:14:36 [     tag] tagged: The Fate of Ophelia — Taylor Swift

  1 downloaded · duration 3:46 · size 47.7 MB · elapsed 13.2s

Album download (parallel)

Album + concurrent workers
$ python aria_lite.py --album 1850496031 --fmt alac -j 2

09:20:10 [   album] The Life of a Showgirl — Taylor Swift — 19 tracks
09:20:10 [   album] output: output/album.1850496031.Taylor Swift - .../

09:20:22 [  verify] valid ALAC — 226.1s  The Fate of Ophelia
09:20:38 [  verify] valid ALAC — 208.3s  Elizabeth Taylor
09:20:55 [  verify] valid ALAC — 235.4s  Opalite
...
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  The Life of a Showgirl + Acoustic Collection
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  19 downloaded
  duration 68:58 · size 849.7 MB · elapsed 347.9s

Track metadata

--info mode
$ python aria_lite.py 1615585008 --info

  As It Was
  ──────────────────────────────────────────
        artist  Harry Styles
         album  Harry's House
      duration  2:47
            id  1615585008
          isrc  USSM12200612
         genre  Pop, Music
       quality  atmos, lossless, lossy-stereo, spatial

8. API Reference

All endpoints except / and /health require Authorization: Bearer TOKEN.

MethodEndpointDescription
GET/healthService health (no auth)
GET/search?q=term&type=songsSearch songs, albums, artists
GET/song/<id>Song metadata
GET/album/<id>Album + track list
GET/artist/<id>Artist + albums
GET/download/<id>?fmt=alacDownload (default AAC; ?fmt=alac for Hi-Res)
GET/album/<id>/downloadDownload album as ZIP
POST/batchBatch download: {"ids":[...],"fmt":"alac"}

9. Performance

Pipeline breakdown (47.7 MB ALAC track)

PhaseTimeShare
m3u8 resolve0.44s5%
CDN download1.80s22%
fMP4 parse45ms1%
Decrypt (pipelined)3.12s38%
m4a write~100ms1%
Audio verify~0.5s6%
Total~8.3s100%

sidecar v4 vs wrapper vs wrapper-v2

Metricwrapperwrapper-v2sidecar v4
Cold startup2338 ms~5000 ms (est.)2163 ms
Decrypt15.0 MB/s~15 MB/s15.3 MB/s
Memory53.8 MB~150 MB (est.)52.3 MB
ContainerNoDockerNo
SourceClosedRust (open)C 935 lines

Key optimizations

OptimizationBeforeAfterImpact
TCP_NODELAYConnection reset4.36sRequired
Pipelining4.36s3.12s1.4x
Streaming BMFF179 MB peak11 MB94% memory
Namespace reductionUSER+NS+PIDUSER+PID7.5% startup

10. Configuration

Environment VariableDefaultDescription
API_TOKEN(required)Auth token for protected endpoints
ARIA_INSTANCES1Number of sidecar decrypt instances
STOREFRONTusApple Music region
CACHE_DIR/tmp/am_cacheDecrypted file cache
ARIA_HOST127.0.0.1sidecar host
ARIA_DECRYPT_PORT47010sidecar decrypt port
ARIA_M3U8_PORT47020sidecar m3u8 port