Podcasts: en español solamente, y se acuerdan de dónde ibas
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 **Podcasts**: programas por categoría —Salud y fitness, Deporte, Comedia, Noticias, Historia, Crímenes reales, Ciencia, Tecnología, Sociedad y cultura, Negocios, Ficción, Educación, Música, Ocio— que suenan mientras entrenás y siguen donde los dejaste. Sin dependencias nuevas y sin clave de API: el directorio de Apple es público. **En español se comprueba, no se supone.** La tienda dice dónde se *vende* un podcast, no en qué idioma está —en el ranking español de comedia hay uno en catalán y en el argentino uno en inglés—, así que se lee el `<language>` del feed de cada programa (los primeros 64 KB, con una petición `Range`: el idioma está en las primeras líneas) y se descarta lo que no sea español. Un feed sin etiqueta se queda: feeds genuinamente españoles la omiten, y tirarlos por una omisión sería sacar podcasts buenos de la lista. La respuesta cuenta cuántos quedaron afuera y por qué (`skipped`), así que una lista corta nunca es un misterio, y abrir un programa en otro idioma se contesta con `spanish:false` en vez de con una lista vacía. Es la otra mitad de la radio y es lo contrario en todo lo que le importa al reproductor: un podcast es un **archivo** —tiene principio, final y un minuto en el que ibas—. Por eso hay un módulo de reglas puras (`lib/podcast-view.js`: dónde retomar, qué cuenta como escuchado, cuál sigue, cuántas posiciones se guardan) y por eso `lib/radio-player.js` pasa a ser `lib/player.js`: **un solo elemento de audio** para las dos cosas, que es lo que impide que una emisora y un episodio suenen a la vez. La barra crece línea de progreso, −15 s, +30 s, siguiente episodio y reloj; la posición se guarda por perfil (con tope de 200, lo más nuevo primero) en pausa, al parar, al terminar y cuando la app se va al fondo, porque con la pantalla bloqueada iOS suspende los temporizadores y un guardado sólo desde el tick perdería lo escuchado con el teléfono guardado. Media Session muestra episodio, programa y progreso en la pantalla bloqueada. Nada se descarga y nada pasa por el servidor: el episodio llega como la URL del `enclosure` y el audio va de quien lo publica al teléfono. Acá no hay lista blanca posible —un feed vive en cualquier host—, así que la puerta es **https, host real y nunca una dirección privada**, comprobada en la URL y en dónde terminó el pedido, con el cuerpo leído a tope y la conexión cortada al llegar: este contenedor vive adentro de una casa. Verificado con datos reales: 20 programas en español por categoría (idiomas es, es-ES, es-mx), un feed de 40 episodios parseado, un feed en inglés contestado como `spanish:false` y la dirección de metadatos rechazada con 400 sin hacer el pedido. Fuera de los podcasts: la página de la API ocultaba `health` y `music` enteras —el generador sólo dibuja las secciones de su tabla de etiquetas—, así que ahora están, con radio y podcasts incluidas.
This commit is contained in:
1 parent
a3e13df279
commit
22654c61fc
31 files changed
+3687
-360
No files matched your search
@@ -22,6 +22,7 @@ import { verifyError } from './verify-error.js';
|
||||
import { parsePayload, mergeVitals, vitalsSeries, vitalsHours, dropMetric, emptyVitals, RETENTION_DAYS } from './vitals.js';
|
||||
import { hostAllowed, readCapped, parseMusicPage } from './music.js';
|
||||
import { genreList, stationsFor, nowPlaying } from './radio.js';
|
||||
import { categoryList, showsFor, episodesFor, safeFeedUrl, isSpanish } from './podcasts.js';
|
||||
import { jevConfig, jevEndpoint, stateHash, insightFreshness, budgetFor } from './jev.js';
|
||||
import {
|
||||
readInsight, clearInsight, runInsight, stateFor, summarizeState, endpointHost
|
||||
@@ -36,6 +37,7 @@ export const API_FEATURES = Object.freeze([
|
||||
'vitals.receipt', // per-metric `shape`, and per-day `own` / `hours_sum`
|
||||
'music.lookup', // POST /api/music/lookup
|
||||
'radio', // GET /api/radio, GET /api/radio/now
|
||||
'podcasts', // GET /api/podcasts, GET /api/podcasts/show
|
||||
'insights' // GET/POST /api/insights (the second opinion)
|
||||
]);
|
||||
|
||||
@@ -1302,6 +1304,49 @@ const routes = {
|
||||
json(res, 200, { ok: true, now: await nowPlaying(station) });
|
||||
},
|
||||
|
||||
/* ---------- podcasts ----------
|
||||
*
|
||||
* Two routes, both session-gated, and neither proxies audio: the list of Spanish shows for a
|
||||
* category, and one show's episodes read out of the publisher's own feed. The episode URLs go to
|
||||
* the phone from here; the audio then goes from the publisher to the phone.
|
||||
*
|
||||
* Unlike the radio — three known hosts, one allowlist — a feed can live anywhere, so the gate is
|
||||
* `safeFeedUrl`: https, a real hostname, and never a private address (see api/podcasts.js). That
|
||||
* matters more here than anywhere else in this file, because this process is running inside
|
||||
* somebody's house and the URL arrives from a browser. */
|
||||
'GET /api/podcasts': async (req, res) => {
|
||||
const user = readSession(req);
|
||||
if (!user) return json(res, 401, { error: 'not signed in' });
|
||||
const key = new URL(req.url, 'http://x').searchParams.get('category') || '';
|
||||
const { category, shows, skipped } = await showsFor(key);
|
||||
json(res, 200, { ok: true, categories: categoryList(), category: category.key, label: category.label, shows, skipped });
|
||||
},
|
||||
|
||||
'GET /api/podcasts/show': async (req, res) => {
|
||||
const user = readSession(req);
|
||||
if (!user) return json(res, 401, { error: 'not signed in' });
|
||||
const q = new URL(req.url, 'http://x').searchParams;
|
||||
const feed = safeFeedUrl(q.get('feed') || '');
|
||||
if (!feed) return json(res, 400, { error: 'not a feed this server will fetch' });
|
||||
const got = await episodesFor(feed, {
|
||||
title: text(q.get('title')).slice(0, 120),
|
||||
image: text(q.get('image')).slice(0, 300)
|
||||
});
|
||||
// A feed that does not answer is not an error status: the screen says so, the same way a music
|
||||
// lookup that cannot reach Apple says so, and nothing about it is a 500.
|
||||
if (!got) return json(res, 200, { ok: true, show: null, episodes: [], error: 'unreadable' });
|
||||
/* A feed that declares another language is answered with the fact rather than hidden: the show
|
||||
exists, it is simply not in Spanish, and saying that is better than an empty list that looks
|
||||
like a feed with no episodes. */
|
||||
const spanish = isSpanish(got.show.language);
|
||||
json(res, 200, {
|
||||
ok: true,
|
||||
...got,
|
||||
spanish,
|
||||
episodes: spanish ? got.episodes : []
|
||||
});
|
||||
},
|
||||
|
||||
'GET /api/push/public-key': async (req, res) => json(res, 200, { key: vapid.publicKey }),
|
||||
|
||||
'POST /api/push/subscribe': async (req, res) => {
|
||||
|
||||
Reference in new issue
Block a user