Skip to content

Agahni: My Spotify Replacement, Streamed From My Own Server

Agahni is my replacement for Spotify: an iPhone and iPad app that plays my own music library, streamed from my own Jellyfin server, with no subscription.

I built it to take back my freedom and privacy. I don't trust big tech with what I listen to.

Jellyfin is open-source media server software that I host myself. It holds the files and the metadata. Agahni streams and downloads from it and leaves library management to Jellyfin. There is no Agahni account and no Agahni cloud.

It is built for a household. Each person on a shared device gets a local profile with their own playlists, likes, history and server login. The app speaks English, German, Spanish, French and Arabic. The repository has 371 commits, from February to October 2026.

What it does

  • A Home page of shelves I can reorder, with suggestions from my listening history and Jellyfin's own similar-items endpoints.
  • Browse the server by songs, albums and artists, and search it. Likes and play counts sync back.
  • Gapless playback, crossfade, a ten-band equalizer, volume leveling from the server's loudness measurements, a sleep timer and lyrics.
  • Offline downloads, with a storage cap and a Wi-Fi-only option.
  • Siri and Shortcuts in all five languages, and four widgets, one of them a lock-screen sleep timer.

How it is built

About 46,000 lines of Swift in 167 files, SwiftUI, and no third-party packages. Every target builds in Swift 6 language mode, so a data race is a compile error, not a warning.

  • AppState is one observable class, split across 60 extension files by topic: playback, streaming, downloads, profiles.
  • JellyfinService is the whole server client: sign-in, library listing, incremental sync, stream and download URLs, artwork.
  • One playback path. Until October, streams played through AVPlayer and downloaded files through an AVAudioEngine graph. Every fix had to land twice, and the two drifted apart. On 8 October every track moved to AVPlayer and the engine graph was deleted. Gapless now uses a queue player: once a track passes 60%, the next one waits behind it.
  • Streaming goes through Jellyfin's transcoding endpoint with a bitrate cap. An optional data saver caps cellular streams, at 320 kbps by default.

Offline

Downloads run in a background URLSession, so they keep going while the app is suspended. Deleting a download turns the song back into a stream instead of removing it. When the storage cap is reached, the app never evicts the playing song, the queue, liked songs or pinned playlists.

Smart downloads are opt-in. They keep pinned playlists and most-played songs on the phone, only on Wi-Fi, and do nothing while the network type is still unknown. A failed download retries after 2, 4, 8, 16, 32 and 60 minutes.

Privacy and security

  • Server credentials live in the Keychain, per profile. The token and password can only be read on this device, while it is unlocked.
  • Removing a household member deletes their credentials, settings, library and downloads. An early version removed only the name and left a working server token behind.
  • Certificate pinning is opt-in. A pin is the SHA-256 of the server's public keys, so a renewal that keeps the key still passes. On a mismatch the app offers "Trust current certificate" but never trusts on its own: a rotation and an interception look the same.
  • One gap: stream URLs still carry the token, because AVPlayer has no supported way to send a header. On the wire they rely on HTTPS and, when it is on, the pin.

Some features use third-party services. Each has its own switch in Settings:

  • Enrich Song Metadata sends a 12-second audio fingerprint to Apple's Shazam service through ShazamKit, and looks the match up on MusicBrainz. Off by default.
  • Third-Party Lyrics sends artist, title and album to LRCLIB, then lyrics.ovh. It is on by default, but only runs when I open lyrics and my server has none.
  • Scrobbling to ListenBrainz or Last.fm. Off by default.

Everything else stays between the phone and my server.

Testing

scripts/gates.sh runs every check in one command: every string key exists, a dead-code scanner, the simulator build and 298 unit tests, plus an optional screenshot sweep and headless UI probes. One probe finds an album and plays it against a deliberately slow mock Jellyfin server. Nothing is committed while a gate fails.

The sweep captures 13 screens in five languages at three text sizes, and I compare them by eye. Bugs like "1 songs", wrong Arabic plurals or a player that clipped its controls on a small phone never showed up in unit tests. They were obvious in a screenshot.

What real phones taught me

  • Opening Settings crashed a phone but never the simulator. A phone gives the main thread 1 MB of stack, the simulator 8 MB, and one huge generic view type overflowed it.
  • In Swift 6 mode, a main-actor callback that the system calls from another thread traps. MetricKit did that at launch and reports each crash on the next launch, so the app crashed on every start. A test now calls each delegate from a background queue.
  • A sync once deleted library entries because it compared against one page of server results. Pruning now only accepts a type built from a complete, verified ID list, so that mistake no longer compiles.

Shipping

Agahni is not in the App Store. One script builds a Release copy and installs it on the household's phones. A free Apple account signs builds for seven days, so a background job on my Mac reinstalls a phone when its build has under two days left and the phone is home and unlocked. The build number is the commit count, and a diagnostics button copies the last 20 minutes of the app's log with any crash reports.

What I'd do next

  • Get a paid Apple developer account: year-long signing, TestFlight, and the right to request the CarPlay audio entitlement.
  • Register a Mac runner with my Forgejo. The workflow that runs the gates on every push waits in the queue until one exists.
  • Check on a phone that a song the server no longer has gets found again or skipped. So far only tests against a mock server cover it.