diff --git a/src/now-playing/emg-now-playing.service.ts b/src/now-playing/emg-now-playing.service.ts index 740cf24..1a44fdc 100644 --- a/src/now-playing/emg-now-playing.service.ts +++ b/src/now-playing/emg-now-playing.service.ts @@ -48,14 +48,27 @@ export class EmgNowPlayingService { const slug = this.extractSlug(station.streamUrl); if (!slug) return; - const url = - `https://meta.hostingradio.ru/emg/${slug}/history` + - `?format=native&types=3&order=desc&date=${date}&from=${from}&to=${to}`; - const res = await fetch(url, { headers: this.headers }); - if (!res.ok) return; + // Slug из хоста потока не всегда = slug в meta (напр. hls-01-fresh → + // в meta это europaplus-fresh). Если по основному пусто — пробуем префикс. + const candidates = [slug]; + if (!slug.startsWith('europaplus') && slug !== 'dfm') { + candidates.push(`europaplus-${slug}`); + } - const items = (await res.json()) as EmgHistoryItem[]; - const cur = Array.isArray(items) ? items[0] : null; + let cur: EmgHistoryItem | null = null; + for (const c of candidates) { + const url = + `https://meta.hostingradio.ru/emg/${c}/history` + + `?format=native&types=3&order=desc&date=${date}&from=${from}&to=${to}`; + const res = await fetch(url, { headers: this.headers }); + if (!res.ok) continue; + const items = (await res.json()) as EmgHistoryItem[] | unknown; + const first = Array.isArray(items) ? (items[0] as EmgHistoryItem) : null; + if (first?.artist && first?.title) { + cur = first; + break; + } + } if (!cur?.artist || !cur?.title) return; await this.nowPlayingService.ingest({