Radio: estaciones en vivo mientras entrenás
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
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 tiene una sección **Radio**: estaciones en vivo por género (Workout/Rave, Techno/House, R&B/Soul, Latina, Hip-Hop, Reggae, Chill, Jazz, Rock, Electrónica), sin publicidad primero —SomaFM y Radio Paradise— y detrás el directorio público de radio-browser. Nada de esto suma dependencias: la lista la arma api/radio.js. Tres decisiones que no se ven en la pantalla y son las que hacen que funcione: - **El audio no pasa por el servidor.** La api entrega la lista y después no ve un byte: el teléfono habla con la estación. Sin ancho de banda, sin disco, sin copias. - **La URL del stream viene resuelta en la lista**, porque iOS sólo deja arrancar audio dentro del gesto del toque: cualquier cosa asíncrona entre el dedo y el play() es un botón que no hace nada, sin error en ninguna parte. - **El `<audio>` vive fuera de React** (lib/radio-player.js): un elemento dentro de un componente se desmonta con él, y eso es la música cortándose al cambiar de pantalla — justo lo que no puede pasar en medio de una serie. Barra arriba de la barra de pestañas con pausa (deja la estación donde estaba) y parar; Media Session pone estación, pista y controles en la pantalla bloqueada, y las canciones siguen con el teléfono en el bolsillo. Qué suena lo dicen SomaFM y Radio Paradise y nadie más: en el resto la barra muestra la estación en vez de inventar una pista. api/test/server-radio.test.js guarda las dos puertas (sesión obligatoria, `src`+`id` reconstruidos en vez de confiar en el objeto del cliente); RadioBar.test.jsx y el caso de la fila en Music.test.jsx guardan lo demás. También: radio.js en el COPY del Dockerfile —importar un archivo que no está copiado es un contenedor que arranca en ERR_MODULE_NOT_FOUND—, /api/radio y /api/radio/now (con /api/music/lookup, que faltaba) en la especificación, y docs/RADIO.md.
This commit is contained in:
1 parent
e1d28f971d
commit
48cf976635
22 files changed
+1662
-15
No files matched your search
@@ -88,6 +88,11 @@ tags:
|
||||
description: >-
|
||||
Apple Health metrics ingested from an iPhone (Health Auto Export automations) —
|
||||
per profile, write-only for the phone's ingest key
|
||||
- name: music
|
||||
description: >-
|
||||
Música — reading a public Apple Music page for a saved playlist's card, and the live radio
|
||||
station directory. Audio is never proxied by this server: the list carries resolved stream
|
||||
URLs and the phone talks to the station directly.
|
||||
- name: admin
|
||||
description: Admin dashboard — requires an admin session (`ADMIN_UIDS` or `admin:true`)
|
||||
|
||||
@@ -909,6 +914,158 @@ paths:
|
||||
description: The gateway refused or failed; the message carries what it said.
|
||||
'401': { $ref: '#/components/responses/Unauthorized' }
|
||||
|
||||
/api/radio:
|
||||
get:
|
||||
tags: [music]
|
||||
operationId: radioGet
|
||||
summary: Live radio stations for a genre, with their stream URLs resolved
|
||||
description: |
|
||||
What the **Radio** section of the Música screen draws. Every station arrives with the URL to
|
||||
hand an `<audio>` element already resolved — the one non-obvious decision here, and it is
|
||||
about iOS: audio may only start *inside* the tap that asked for it, so anything asynchronous
|
||||
between the finger and the `play()` is a press that quietly does nothing.
|
||||
|
||||
The audio never passes through this server. The list is the whole feature on this side: the
|
||||
phone then talks to the station directly, so this instance spends no bandwidth and keeps no
|
||||
copy of anything. Sources are SomaFM (commercial-free) and Radio Paradise for the curated
|
||||
picks, and the public radio-browser directory for the rest, filtered to HTTPS and to codecs a
|
||||
browser plays without a library (HLS streams are skipped — that would mean shipping a player
|
||||
library).
|
||||
|
||||
A session is required. Not to protect the stations — they are public — but because this
|
||||
container sits on the owner's own network and fetches on behalf of whoever asks.
|
||||
|
||||
An unknown or missing `genre` is not an error: it falls back to the first genre.
|
||||
parameters:
|
||||
- name: genre
|
||||
in: query
|
||||
schema:
|
||||
type: string
|
||||
enum: [workout, techno, rnb, latin, hiphop, reggae, chill, jazz, rock, electronic]
|
||||
description: Genre key. Missing or unrecognised falls back to `workout`.
|
||||
responses:
|
||||
'200':
|
||||
description: The genres for the chips, and the stations for the one that was asked for.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
ok: { type: boolean }
|
||||
genres:
|
||||
type: array
|
||||
description: Every chip the screen offers, so the client never hard-codes them.
|
||||
items:
|
||||
type: object
|
||||
properties:
|
||||
key: { type: string }
|
||||
label: { type: string }
|
||||
genre: { type: string, description: The genre actually answered with. }
|
||||
label: { type: string, description: That genre's human label. }
|
||||
stations:
|
||||
type: array
|
||||
description: Curated, ad-free picks first, then the directory. At most 40.
|
||||
items: { $ref: '#/components/schemas/RadioStation' }
|
||||
'401': { $ref: '#/components/responses/Unauthorized' }
|
||||
|
||||
/api/radio/now:
|
||||
get:
|
||||
tags: [music]
|
||||
operationId: radioNow
|
||||
summary: What a station says it is playing
|
||||
description: |
|
||||
The line under the station's name in the player bar, and the metadata the lock screen shows.
|
||||
Only **SomaFM** and **Radio Paradise** publish this; for anything else the answer is
|
||||
`now: null` and the bar shows the station itself rather than inventing a track.
|
||||
|
||||
The station is rebuilt from `src` + `id` rather than accepted as an object, and the id is
|
||||
checked against a plain-id pattern, because the id is used to build a URL this process
|
||||
fetches: without that, a session would be enough to make the api a request proxy for anything
|
||||
on the owner's network. The two known sources are the only ones accepted.
|
||||
|
||||
The client polls this every 45 seconds while something plays — the screen's own timer, so
|
||||
when iOS suspends it on a locked screen the caption freezes and the music does not.
|
||||
parameters:
|
||||
- name: src
|
||||
in: query
|
||||
required: true
|
||||
schema: { type: string, enum: [soma, paradise] }
|
||||
description: Which service the station belongs to.
|
||||
- name: id
|
||||
in: query
|
||||
required: true
|
||||
schema: { type: string, pattern: '^[A-Za-z0-9_-]{1,40}$' }
|
||||
description: The station's id at that service (a SomaFM channel like `beatblender`, or a Radio Paradise mix like `main`).
|
||||
responses:
|
||||
'200':
|
||||
description: The current track, or `null` when the station does not publish one.
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
ok: { type: boolean }
|
||||
now:
|
||||
type: object
|
||||
nullable: true
|
||||
properties:
|
||||
artist: { type: string, nullable: true }
|
||||
title: { type: string }
|
||||
cover: { type: string, nullable: true, description: HTTPS album art, when the station sends one. }
|
||||
'400':
|
||||
description: No such station — an unknown `src`, or an `id` that is not a plain id.
|
||||
'401': { $ref: '#/components/responses/Unauthorized' }
|
||||
|
||||
/api/music/lookup:
|
||||
post:
|
||||
tags: [music]
|
||||
operationId: musicLookup
|
||||
summary: Read what a public Apple Music page says about itself
|
||||
description: |
|
||||
Apple has no API for somebody else's public playlists, so a playlist saved in KuentaGYM is a
|
||||
*link* — and this is how the card gets its title, artwork, track count and curator without
|
||||
the client fetching Apple itself (which CORS would refuse anyway).
|
||||
|
||||
The URL must be an Apple Music link on an allowlisted host (`hostAllowed`), and so must the
|
||||
URL the request ends up at: a redirect is otherwise a way around the allowlist. This
|
||||
container sits on the owner's own network, which is the whole reason for the check.
|
||||
|
||||
An unreachable page or a page that left the allowlist is **not** an error status — the answer
|
||||
is `200` with `meta: null` and an `error` naming which of the two happened, because the app's
|
||||
job then is to save the link anyway with the name the person typed.
|
||||
requestBody:
|
||||
required: true
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
required: [url]
|
||||
properties:
|
||||
url: { type: string, description: A public `https://music.apple.com/...` link. }
|
||||
responses:
|
||||
'200':
|
||||
description: 'What the page said, or `meta: null` with a reason.'
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: object
|
||||
properties:
|
||||
ok: { type: boolean }
|
||||
meta:
|
||||
type: object
|
||||
nullable: true
|
||||
properties:
|
||||
title: { type: string, nullable: true }
|
||||
artwork: { type: string, nullable: true }
|
||||
tracks: { type: integer, nullable: true }
|
||||
curator: { type: string, nullable: true }
|
||||
error:
|
||||
type: string
|
||||
description: Present only when `meta` is null — `unreachable`, `off-host` or `http-<status>`.
|
||||
'400':
|
||||
description: Not an Apple Music link, or a plain-`http`/off-host URL. Refused before any request is made.
|
||||
'401': { $ref: '#/components/responses/Unauthorized' }
|
||||
|
||||
/api/vitals/ingest:
|
||||
post:
|
||||
tags: [health]
|
||||
@@ -1627,6 +1784,42 @@ components:
|
||||
properties:
|
||||
ok: { type: boolean, const: true }
|
||||
|
||||
RadioStation:
|
||||
type: object
|
||||
description: >-
|
||||
One row in the Radio section: everything the screen needs to draw the station *and* to start
|
||||
playing it, because the `play()` has to happen inside the tap that chose it.
|
||||
required: [src, id, name, url]
|
||||
properties:
|
||||
src:
|
||||
type: string
|
||||
enum: [soma, paradise, rb]
|
||||
description: >-
|
||||
Where it came from — `soma` (SomaFM, commercial-free), `paradise` (Radio Paradise, four
|
||||
hand-mixed channels) or `rb` (the public radio-browser directory). `src` + `id` is what
|
||||
`GET /api/radio/now` is asked about, and only the first two answer.
|
||||
id: { type: string, description: The station's id at that source. }
|
||||
name: { type: string }
|
||||
genre: { type: string, nullable: true, description: Free-form tags or the channel's own genre. }
|
||||
detail:
|
||||
type: string
|
||||
nullable: true
|
||||
description: The second line — country, codec, bitrate for the directory, or "no advertising" for the curated ones.
|
||||
image: { type: string, nullable: true, description: HTTPS logo, when the source publishes one. }
|
||||
url:
|
||||
type: string
|
||||
description: >-
|
||||
The stream, already resolved to an HTTPS URL a browser plays natively. For SomaFM this
|
||||
comes from the channel's own `.pls` rather than a guessed bitrate URL.
|
||||
example:
|
||||
src: soma
|
||||
id: beatblender
|
||||
name: Beat Blender
|
||||
genre: Electronic
|
||||
detail: A late night blend
|
||||
image: null
|
||||
url: https://ice2.somafm.com/beatblender-128-mp3
|
||||
|
||||
SessionUser:
|
||||
type: object
|
||||
description: The caller's identity, as returned by /api/me and the sign-in routes.
|
||||
|
||||
Reference in new issue
Block a user