Música se ordena: pestañas, buscador, y listas de diez con "Mostrar má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

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.
This commit is contained in:
dsantillan committed 2026-09-23 21:24:50 -04:00
1 parent 22654c61fc
commit d5cf0d8d64
16 files changed
+845 -81

No files matched your search

+62 -8
View File
@@ -332,13 +332,22 @@ export async function showsFor(genreKey, { fetchImpl = fetch } = {}) {
for (let i = 0; lists.some(l => l[i]); i++) {
for (const list of lists) if (list[i]) rows.push(list[i]);
}
const { shows, skipped } = await spanishOnly(rows, { fetchImpl });
return { category, shows, skipped };
}
/**
* The Spanish filter, shared by a category list and a search: check each candidate's feed, keep the
* Spanish ones, and count why the others went.
*
* *Why* a show was left out is reported and not just dropped. It used to be `return null` for every
* reason, which made three different things — "not in Spanish", "the feed did not answer", "the pool
* swallowed an unexpected error" — the same observable outcome, so a refactor that accidentally let
* the third one happen looked exactly like the rule working. A count per reason makes each of them a
* fact a test can assert on.
*/
export async function spanishOnly(rows, { fetchImpl = fetch, limit = MAX_SHOWS } = {}) {
const seen = new Set();
/* *Why* a show was left out is reported, not just dropped.
*
* It used to be `return null` for every reason, which made three different things — "not in
* Spanish", "the feed did not answer", "the pool swallowed an unexpected error" — the same
* observable outcome. A refactor that accidentally let the third one happen then looked exactly
* like the rule working. A count per reason makes each of them a fact a test can assert on. */
const skipped = { duplicate: 0, language: 0, unreadable: 0, failed: 0 };
const results = await mapLimit(rows.slice(0, CHECK_LIMIT), POOL, async show => {
if (seen.has(show.feed)) return { skip: 'duplicate' };
@@ -355,9 +364,54 @@ export async function showsFor(genreKey, { fetchImpl = fetch } = {}) {
if (!r) { skipped.failed++; continue }
if (r.skip) { skipped[r.skip]++; continue }
shows.push(r.show);
if (shows.length >= MAX_SHOWS) break;
if (shows.length >= limit) break;
}
return { category, shows, skipped };
return { shows, skipped };
}
/* ---------- search ---------- */
/**
* Shows by name, from the same directory as the categories.
*
* Apple's search endpoint takes the same shape as its charts did in `lookup` — `collectionName`,
* `feedUrl`, `artworkUrl600` — so the rows go straight through `showFrom`, and then through the very
* same Spanish filter as a category list. That sharing is the point: a search is not a second,
* weaker way into the catalogue, and "Spanish only" cannot quietly stop applying to it.
*
* The two storefronts are searched because they publish different podcasts, and the results are
* interleaved so neither country fills the screen.
*/
export async function searchShows(query, { fetchImpl = fetch } = {}) {
const term = normQuery(query);
if (!term) return { query: '', shows: [], skipped: { duplicate: 0, language: 0, unreadable: 0, failed: 0 } };
const perStore = await Promise.all(STORES.map(country => appleSearch(term, country, { fetchImpl })));
const lists = perStore.filter(Array.isArray);
const rows = [];
for (let i = 0; lists.some(l => l[i]); i++) {
for (const list of lists) if (list[i]) rows.push(list[i]);
}
const { shows, skipped } = await spanishOnly(rows, { fetchImpl });
return { query: term, shows, skipped };
}
/** One query, normalised: one letter matches everything and costs a request per storefront to say so. */
export function normQuery(query) {
const q = String(query == null ? '' : query).replace(/\s+/g, ' ').trim().slice(0, 80);
return q.length < 2 ? '' : q;
}
/** The directory's search for one storefront, cached: the same query is the same answer. */
export async function appleSearch(term, country, { fetchImpl = fetch } = {}) {
return cached(`search:${country}:${term.toLowerCase()}`, CACHE_MS, async () => {
const params = new URLSearchParams({ media: 'podcast', term, country, limit: String(CHART_LIMIT), lang: 'es' });
const text = await get(apple('/search?' + params), { fetchImpl });
if (!text) return [];
try {
const json = JSON.parse(text);
return (json.results || []).map(r => showFrom(r, country)).filter(Boolean);
} catch { return [] }
});
}
/* ---------- the feed ---------- */