Files
kuentagym/docs/RADIO.md
T
dsantillan d5cf0d8d64
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s
Música se ordena: pestañas, buscador, y listas de diez con "Mostrar más"
La pantalla era una sola columna —radio, después podcasts, después listas— y tres
listas de veinte filas es una pantalla por la que se baja buscando lo que ya sabías
que querías. Ahora pregunta primero: **Radio | Podcasts | Listas**, una lista a la
vez, **diez filas** y un **"Mostrar más"** que dice cuántas esconde. Nada queda fuera
de alcance y nada más está en pantalla mientras decidís: el subtítulo también dice qué
estás mirando en vez de hablar siempre de listas.

El **buscador** busca lo que tengas abierto y en el origen, no en la página: `jazz`
le pregunta al directorio de emisoras y `crimen` al de podcasts de Apple —filtrado,
como siempre, a español, y pasando por **la misma** función de filtro que una
categoría, porque un segundo camino más barato al catálogo es como se pierde una
regla—. Con menos de dos letras no se busca ni se pide nada: una letra coincide con
todo y sería una petición por tecla para una respuesta inservible.

La búsqueda de emisoras **ordena por lo que se buscó**: el directorio coincide con
subcadenas en cualquier parte, así que *techno* devolvía "# TOP 100 CLUB CHARTS -
DANCE & DJ MIX RADIO" —real, con "techno" entre sus etiquetas— por delante de toda
emisora llamada Techno Algo. El nombre pesa antes que la popularidad y a igual peso
gana el nombre más corto; los canales de SomaFM y los mixes de Paradise que coinciden
van primero, porque no tienen publicidad y su stream ya se sabe que funciona. La
búsqueda del directorio va con `is_https=true`, cacheada por consulta.

`lib/paging.js` es puro y tiene test porque tiene un borde fácil de equivocar en un
componente: una lista que se encoge —una búsqueda nueva, una emisora desmarcada— no
puede dejar el tamaño de página pasado del final, que se ve como "Mostrar más" que no
hace nada.

Verificado contra los directorios reales: `radio?q=jazz` → Sonic Universe (SomaFM) y
después Jazz 24; `radio?q=miami` → Miami Beach Radio, 105 Miami; `podcasts?q=crimen`
→ 20 programas en español (es, es-ar) y `q=entrenamiento en casa` → 3; `?q=j` no
busca. `relevance` y `rankStations` se comprobaron por mutación: sacar el orden hace
fallar el test que lo mira de punta a punta.
2026-09-23 21:24:50 -04:00

8.3 KiB

Radio

Live stations, for the hour you're in the gym. Open Música → Radio, pick a genre, press a station, and it plays while you train — across screens, with the screen locked and the phone in your pocket.

It is radio, not a music library: you don't pick the song, and nobody has to. That is the whole reason it exists next to the Apple Music playlists on the same screen — one is what you listen to on purpose, the other is what plays while you count reps.

What is playing

There is also a search box above the tabs, and it searches the directory rather than the page you are looking at: jazz is every jazz station radio-browser knows, not the jazz stations that happened to be in the genre on screen. Results are ordered by the name first — a station called "Jazz 24" comes before one with "jazz" buried in a forty-character marketing name — and then by how many people listen. The curated channels and mixes that match come first of all: no advertising, and a stream already known to work.

Chips pick a genre. Ten of them: Workout / Rave, Techno / House, R&B / Soul, Latina, Hip-Hop, Reggae, Chill, Jazz, Rock, Electrónica. Each one is a list of SomaFM channels (curated by hand — a machine cannot know that Seven Inch Soul is the R&B one), the Radio Paradise mixes that fit, and the radio-browser tags that fill in the rest.

The ad-free ones come first in every genre: SomaFM is a listener-supported, commercial-free network of 46 channels, and Radio Paradise is four hand-mixed ones. Both publish their stream as a playlist .pls, which api/radio.js reads rather than guessing a bitrate into a URL — that is what makes the same code work for every channel, including the ones added after this was written.

Behind them is radio-browser, a public, community-run directory of tens of thousands of stations. It is filtered hard: HTTPS only (a page served over HTTPS cannot play an http:// stream at all — the browser blocks it as mixed content, so offering one would be offering a station that silently does nothing), hidebroken=true, ordered by how many people actually listen to it.

Where the audio goes

From the station to your phone. Never through this server.

The api hands out the list — each station with its stream URL already resolved — and after that it sees nothing: no traffic, no disk, no byte of audio. On a small VPS that is the difference between a feature and a bandwidth bill, and it is also why nothing here ever downloads, records or keeps a copy of anything.

Two kinds of request do reach out from the server, and both are for the list and its caption:

Call To Why
channel list + .pls somafm.com to resolve a channel into a stream URL
bytagexact search all.api.radio-browser.info the directory's stations per genre
now_playing api.radioparadise.com the cover and the track for the bar

All of them are cached for ten minutes, so opening the screen twice is one round of requests. Every outgoing call goes through one function with a host allowlist (RADIO_HOSTS) — the api container sits on the owner's own network, so the set of hosts it will talk to is a security boundary, not a convenience.

So the server does see something: which genre chip was pressed, and — only for the two sources that publish what they play — which station the bar is asking about, once every 45 seconds while it plays. Nothing is written down: those are requests, not records, and there is no table, log or file where listening would accumulate. (The request log in the admin dashboard is the activity log, and it carries sign-ins and admin actions, not this.)

Why the stream URL arrives in the list

iOS only lets audio start inside the gesture that asked for it. Anything asynchronous between the finger and the play() — a fetch, a state update, a re-render — is a press that does nothing, with no error anywhere. So the list arrives complete: by the time a station has been drawn on the screen, its stream URL is already in the object the row holds, and the press calls play() synchronously.

The <audio> element lives in frontend/src/lib/player.js, outside React, as a module-level singleton — the same element the podcasts use, which is also what keeps a station and an episode from ever playing at once. An element owned by a component is unmounted when the component is, which is how a player stops the moment you change screens — and changing screens mid-session is the normal case here, not the edge case.

The bar, and the lock screen

While something is playing, a bar sits above the tab bar (the same place and the same glass as the rest timer, on purpose — a second floating bar with its own look reads as a second app):

  • the station, and what it says it is playing
  • pause — keeps the station, so the same one is still there after the rest
  • stop — takes the bar and the station away

Media Session is what puts the station, the track and the controls on the lock screen and in the car, and it is what makes "screen off, phone in pocket" work: the audio is played by the browser underneath the page, not by the page's timers. Those timers — the 45-second poll for what is playing — are suspended while the screen is locked, so the caption simply stops moving until you look again. It is a caption; the music is unaffected.

On the native Android/iOS shells the same rules apply, with one addition: keeping audio alive under a locked screen in a WebView needs UIBackgroundModes: audio (iOS) and a foreground service (Android) in the shell's own config. Neither is set today — that is described in docs/MOBILE.md, and it only affects the packaged builds, not the PWA.

When the radio isn't there

Two situations look like a bug and are not, so the screen says which one it is instead of showing a request that failed:

  • Nobody is signed in. Guest mode is client-side only and never talks to the api, and the station list is the server's job — so the section says the radio needs a profile. No request is made.
  • The api is older than the app. They ship separately: web is rebuilt from source on every deploy, while the api's code lives inside its container, so a deploy can leave a new screen on top of an api that has never heard of /api/radio. GET /api/config lists what that api can do (features, and this build answers radio), so "old server" is detectable — the section says so, quietly, rather than offering chips that 404. The same list is what keeps the Salud screen from blaming the data when it is really the container.

Saving a station

The star on a row saves the station to your profile (music.stations), and saved ones are pinned above the list. They are stored with the rest of your profile's client state — they contain nothing about your listening, just the station you liked.

What this deliberately is not

  • Not a YouTube/Spotify front end. Ripping streams or playing someone else's catalogue through an unofficial API breaks those services' terms and this project's licence is AGPL; the honest version of "radio" is radio.
  • Not a proxy. No endpoint here relays audio. Every /api/radio response is JSON, and the routes are session-gated so the list cannot be borrowed by somebody else's page.
  • Not a downloader. There is no record button and no cache of audio anywhere.
  • Not HLS. Stations that only stream HLS are skipped: playing them in a browser needs hls.js, and a dependency-light project does not take a media stack on for a feature whose whole point is that it makes no new dependency necessary.

Credits and licences

  • SomaFM — listener-supported, commercial-free; the channels used here are theirs, and their stream URLs are resolved through their own public .pls.
  • Radio Paradise — listener-supported, and the now_playing endpoint that gives the bar its cover art.
  • radio-browser — the directory itself is AGPL-3.0, same family as this project, and it is the reason the long tail of stations is reachable at all.

These are third-party services this app does not control: a station that goes off the air disappears from the list on the next refresh, and a genre that comes back thin is the directory having a bad day, not the app.