Show public podcasts in the federated search and subscribe from a card

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
sanapachandClaude Opus 5.5 committed 2026-11-20 15:12:51 +02:00
1 parent 20bf30eae8
commit 59d94203db
6 files changed
+625 -5

No files matched your search

+79
View File
@@ -71,6 +71,85 @@
</div>
</template>
<!-- Podcast found in the federation: card, preview from its feed, subscribe -->
<template x-if="$store.podcasts.found">
<div class="modal-overlay" @click.self="$store.podcasts.closeFound()" @keydown.escape.window="$store.podcasts.closeFound()">
<div class="modal-box podcast-found-dialog" role="dialog" aria-modal="true" aria-labelledby="podcast-found-title">
<div class="podcast-found-head">
<div class="podcast-found-cover">
<template x-if="$store.podcasts.found.hit.image_url || $store.podcasts.found.preview?.image_url">
<img :src="$store.podcasts.found.hit.image_url || $store.podcasts.found.preview?.image_url" alt="" aria-hidden="true" referrerpolicy="no-referrer">
</template>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<rect x="9" y="2" width="6" height="12" rx="3"/><path d="M5 10a7 7 0 0014 0M12 17v5M8 22h8"/>
</svg>
</div>
<div class="podcast-found-heading">
<div class="podcast-found-badges">
<span class="podcast-type-badge">{{ t.player_podcast_type }}</span>
<span class="podcast-subscribed-badge" x-show="$store.podcasts.found.subscribed">{{ t.player_podcast_found_subscribed }}</span>
</div>
<h3 id="podcast-found-title" x-text="$store.podcasts.found.hit.title"></h3>
<div class="podcast-found-author" x-show="$store.podcasts.found.hit.author" x-text="$store.podcasts.found.hit.author"></div>
<div class="podcast-found-meta" x-text="$store.podcasts.foundMeta($store.podcasts.found.hit)"></div>
<a class="podcast-found-link" x-show="$store.podcasts.found.hit.link"
:href="$store.podcasts.found.hit.link" target="_blank" rel="noopener noreferrer nofollow"
x-text="$store.podcasts.found.hit.link"></a>
</div>
</div>
<p class="podcast-found-description" x-show="$store.podcasts.found.hit.description" x-text="$store.podcasts.found.hit.description"></p>
<div class="podcast-found-label">{{ t.player_podcast_found_feed }}</div>
<div class="podcast-share-url" x-text="$store.podcasts.found.hit.feed_url"></div>
<p class="podcast-share-hint">{{ t.player_podcast_found_note }}</p>
<div class="podcast-found-preview">
<template x-if="$store.podcasts.found.previewLoading">
<div class="podcast-found-status">{{ t.player_podcast_found_loading }}</div>
</template>
<template x-if="$store.podcasts.found.previewError">
<div class="podcast-found-status error">
<span x-text="$store.podcasts.found.previewError"></span>
<button class="modal-btn modal-btn-ghost" @click="$store.podcasts.loadFoundPreview()">{{ t.player_podcast_found_retry }}</button>
</div>
</template>
<template x-if="$store.podcasts.found.preview">
<div>
<div class="podcast-found-status" x-show="$store.podcasts.found.preview.moved">{{ t.player_podcast_found_moved }}</div>
<div class="podcast-chips podcast-found-seasons">
<template x-for="season in $store.podcasts.found.preview.seasons" :key="$store.podcasts.seasonValue(season)">
<span class="podcast-chip" x-text="`${$store.podcasts.seasonLabel(season)} · ${season.episode_count}`"></span>
</template>
</div>
<ul class="podcast-found-episodes">
<template x-for="(episode, index) in $store.podcasts.found.preview.episodes" :key="index">
<li>
<div class="podcast-found-episode-title" x-text="episode.title"></div>
<div class="podcast-found-episode-meta" x-text="$store.podcasts.episodeMeta(episode)"></div>
</li>
</template>
</ul>
<div class="podcast-found-status" x-show="$store.podcasts.foundMore($store.podcasts.found.preview)" x-text="$store.podcasts.foundMore($store.podcasts.found.preview)"></div>
</div>
</template>
</div>
<div class="podcast-found-status error" x-show="$store.podcasts.found.error" x-text="$store.podcasts.found.error"></div>
<div class="podcast-found-status" x-show="$store.podcasts.found.message" x-text="$store.podcasts.found.message"></div>
<div class="modal-footer">
<button class="modal-btn modal-btn-ghost" @click="$store.podcasts.closeFound()">{{ t.player_close }}</button>
<template x-if="$store.podcasts.found.subscribed">
<button class="modal-btn modal-btn-primary" @click="$store.podcasts.openFoundPodcast()">{{ t.player_podcast_found_open }}</button>
</template>
<template x-if="!$store.podcasts.found.subscribed">
<button class="modal-btn modal-btn-primary" :disabled="$store.podcasts.found.subscribing"
@click="$store.podcasts.subscribeFound()"
x-text="$store.podcasts.foundButtonLabel()"></button>
</template>
</div>
</div>
</div>
</template>
<!-- Create / Rename Playlist Modal -->
<template x-if="$store.playlists.modal">
<div class="modal-overlay" @click.self="$store.playlists.modal = null">
+200 -4
View File
@@ -94,6 +94,12 @@ const T = {
podcastSourceFailed: "{{ t.player_podcast_source_failed }}",
podcastCannotSeek: "{{ t.player_podcast_cannot_seek }}",
podcastRequestFailed: "{{ t.player_podcast_request_failed }}",
podcastType: "{{ t.player_podcast_type }}",
podcastFoundLatest: "{{ t.player_podcast_found_latest }}",
podcastFoundMore: "{{ t.player_podcast_found_more }}",
podcastFoundDone: "{{ t.player_podcast_found_done }}",
podcastFoundSubscribing: "{{ t.player_podcast_found_subscribing }}",
podcastSubscribe: "{{ t.player_podcast_subscribe }}",
podcastEpisodes: "{{ t.player_podcast_episodes }}",
podcastUnplayed: "{{ t.player_podcast_unplayed }}",
podcastSeasons: "{{ t.player_podcast_seasons }}",
@@ -3692,6 +3698,8 @@ document.addEventListener('alpine:init', () => {
sharing: false,
shareError: '',
shareDialog: null,
found: null,
_foundToken: 0,
busy: {},
expanded: {},
_searchTimer: null,
@@ -3979,6 +3987,171 @@ document.addEventListener('alpine:init', () => {
}
},
// Public podcasts found by the federated search. A card is another
// member's claim: only expected fields of expected types are kept,
// URLs must be absolute http(s) (artwork: https only), and every
// text is rendered with x-text.
safeHttpUrl(value) {
if (typeof value !== 'string' || !value || value.length > 2048) return '';
let url;
try { url = new URL(value); } catch { return ''; }
if (url.protocol !== 'http:' && url.protocol !== 'https:') return '';
if (url.username || url.password || !url.hostname) return '';
return value;
},
safeImageUrl(value) {
const url = this.safeHttpUrl(value);
return url && url.startsWith('https:') ? url : '';
},
foundHit(entity) {
if (!entity || typeof entity !== 'object' || entity.type !== 'podcast') return null;
const text = (value, max) => (typeof value === 'string' ? value.slice(0, max) : '');
const count = value => (Number.isInteger(value) && value >= 0 ? value : null);
const podcastId = text(entity.podcast_id, 200);
const feedUrl = this.safeHttpUrl(entity.feed_url);
const title = text(entity.title, 300).trim();
if (!/^pod1:[a-z2-7]{52}$/.test(podcastId) || !feedUrl || !title) return null;
const localId = text(entity.local_podcast_id, 200);
return {
type: 'podcast',
podcast_id: podcastId,
feed_url: feedUrl,
title,
author: text(entity.author, 300),
description: text(entity.description, 1000),
image_url: this.safeImageUrl(entity.image_url),
link: this.safeHttpUrl(entity.link),
language: text(entity.language, 35),
categories: Array.isArray(entity.categories)
? entity.categories.filter(item => typeof item === 'string').slice(0, 8).map(item => item.slice(0, 64))
: [],
episode_count: count(entity.episode_count),
latest_episode_at_ms: count(entity.latest_episode_at_ms),
publisher_count: count(entity.publisher_count) || 0,
rank: count(entity.rank) ?? Number.MAX_SAFE_INTEGER,
exact_match: entity.exact_match === true,
subscribed: entity.subscribed === true,
local_podcast_id: /^pod1:[a-z2-7]{52}$/.test(localId) ? localId : null,
};
},
foundMeta(hit) {
if (!hit) return '';
const parts = [];
if (hit.episode_count != null) parts.push(`${hit.episode_count} ${T.podcastEpisodes}`);
if (hit.latest_episode_at_ms) parts.push(`${T.podcastFoundLatest}: ${this.formatDate(hit.latest_episode_at_ms)}`);
if (hit.language) parts.push(hit.language);
if (hit.categories?.length) parts.push(hit.categories.join(', '));
return parts.join(' · ');
},
foundSubtitle(hit) {
if (!hit) return '';
return [hit.author, hit.episode_count != null ? `${hit.episode_count} ${T.podcastEpisodes}` : '']
.filter(Boolean)
.join(' · ');
},
foundMore(preview) {
const more = Number(preview?.episode_count || 0) - (preview?.episodes?.length || 0);
return more > 0 ? T.podcastFoundMore.replace('{count}', String(more)) : '';
},
openFound(hit) {
if (GUEST || !hit?.podcast_id || !hit.feed_url) return;
this._foundToken += 1;
this.found = {
hit,
preview: null,
previewLoading: false,
previewError: '',
subscribing: false,
error: '',
message: '',
subscribed: hit.subscribed === true,
localPodcastId: hit.local_podcast_id || null,
};
this.loadFoundPreview();
},
closeFound() {
this._foundToken += 1;
this.found = null;
},
_foundBody(hit) {
// The card's id and origin URL, exactly as found: the server
// checks that the id comes from this URL.
return {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ podcast_id: hit.podcast_id, feed_url: hit.feed_url }),
};
},
async loadFoundPreview() {
const found = this.found;
if (!found || found.previewLoading) return;
const token = this._foundToken;
this.found = { ...found, previewLoading: true, previewError: '' };
try {
const preview = await this._json('/api/podcasts/discovery/preview', this._foundBody(found.hit));
if (token !== this._foundToken) return;
this.found = {
...this.found,
preview: {
...preview,
image_url: this.safeImageUrl(preview?.image_url),
link: this.safeHttpUrl(preview?.link),
seasons: Array.isArray(preview?.seasons) ? preview.seasons : [],
episodes: Array.isArray(preview?.episodes) ? preview.episodes : [],
},
previewLoading: false,
subscribed: this.found.subscribed || preview?.subscribed === true,
localPodcastId: this.found.localPodcastId || preview?.local_podcast_id || null,
};
} catch (error) {
if (token !== this._foundToken) return;
this.found = { ...this.found, previewLoading: false, previewError: error.message };
}
},
async subscribeFound() {
const found = this.found;
if (!found || found.subscribing || found.subscribed) return;
const token = this._foundToken;
this.found = { ...found, subscribing: true, error: '', message: '' };
try {
const data = await this._json('/api/podcasts/discovery/subscribe', this._foundBody(found.hit));
const podcastId = data?.podcast?.podcast_id || found.hit.podcast_id;
Alpine.store('library')?.markFoundPodcastSubscribed?.(found.hit.podcast_id, podcastId);
this.loadList();
if (token !== this._foundToken) return;
this.found = {
...this.found,
subscribing: false,
subscribed: true,
localPodcastId: podcastId,
message: data?.already_subscribed ? T.podcastAlready : T.podcastFoundDone,
};
} catch (error) {
if (token !== this._foundToken) return;
this.found = { ...this.found, subscribing: false, error: error.message };
}
},
foundButtonLabel() {
return this.found?.subscribing ? T.podcastFoundSubscribing : T.podcastSubscribe;
},
openFoundPodcast() {
const podcastId = this.found?.localPodcastId || this.found?.hit?.podcast_id;
this.closeFound();
if (podcastId) this.open(podcastId);
},
jamBlocked() {
// A Jam guest controls the host's queue: episodes are private.
return !!Alpine.store('devices')?.isControllingRemoteJam?.();
@@ -4172,7 +4345,7 @@ document.addEventListener('alpine:init', () => {
similaritySearchLabel: '',
similaritySearchError: '',
similaritySearchStats: { loading: false, tracks: 0, artists: 0, peers: 0, elapsed_ms: 0 },
federationSearch: { loading: false, error: '', artists: [], releases: [], tracks: [] },
federationSearch: { loading: false, error: '', artists: [], releases: [], tracks: [], podcasts: [] },
artistFederation: { loading: false, error: '', releases: [], tracks: [] },
federationPreparing: {},
federationFailures: {},
@@ -5112,7 +5285,7 @@ document.addEventListener('alpine:init', () => {
this.similaritySearchError = '';
this.searchLoading = true;
this.searchResults = null;
this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [] };
this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [], podcasts: [] };
this.similaritySearchStats = { loading: true, tracks: 0, artists: 0, peers: 0, elapsed_ms: 0 };
Alpine.store('info').close();
try {
@@ -5254,12 +5427,12 @@ document.addEventListener('alpine:init', () => {
this._federationSearchSource.close();
this._federationSearchSource = null;
}
this.federationSearch = { loading: false, error: '', artists: [], releases: [], tracks: [] };
this.federationSearch = { loading: false, error: '', artists: [], releases: [], tracks: [], podcasts: [] };
},
startFederationSearch(query) {
this.stopFederationSearch();
this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [] };
this.federationSearch = { loading: true, error: '', artists: [], releases: [], tracks: [], podcasts: [] };
const source = new EventSource(`/api/player/federation/search/events?q=${encodeURIComponent(query)}`);
this._federationSearchSource = source;
const updateResults = (kind, keyFor, labelFor, entity) => {
@@ -5312,6 +5485,20 @@ document.addEventListener('alpine:init', () => {
if (!release?.key) return;
updateResults('releases', item => JSON.stringify(item.key || {}), item => item.title, release);
});
source.addEventListener('federation.podcast', event => {
if (this._federationSearchSource !== source) return;
let payload = null;
try { payload = JSON.parse(event.data); } catch { return; }
// Public podcast cards: typed, sanitized, ordered by their
// place among the music results.
const hit = Alpine.store('podcasts')?.foundHit?.(payload?.entity);
if (!hit) return;
const podcasts = (this.federationSearch.podcasts || [])
.filter(item => item.podcast_id !== hit.podcast_id);
podcasts.push(hit);
podcasts.sort((left, right) => left.rank - right.rank);
this.federationSearch = { ...this.federationSearch, podcasts };
});
source.addEventListener('search.completed', () => {
window.clearTimeout(watchdog);
if (this._federationSearchSource === source) {
@@ -5345,6 +5532,15 @@ document.addEventListener('alpine:init', () => {
};
},
markFoundPodcastSubscribed(podcastId, localPodcastId) {
const podcasts = (this.federationSearch?.podcasts || []).map(item => (
item.podcast_id === podcastId
? { ...item, subscribed: true, local_podcast_id: localPodcastId || item.local_podcast_id }
: item
));
this.federationSearch = { ...this.federationSearch, podcasts };
},
normalizeFederationSearchText(value) {
return String(value || '')
.normalize('NFKD')
+32
View File
@@ -625,6 +625,38 @@
</div>
</template>
</div>
<div class="search-podcasts-section"
x-show="!$store.library.similaritySearchLabel && ($store.library.federationSearch.podcasts || []).length > 0"
x-cloak>
<h3 class="search-subsection-title">{{ t.player_podcast_found_title }}</h3>
<div class="search-releases-row">
<template x-for="hit in ($store.library.federationSearch.podcasts || [])"
:key="hit.podcast_id">
<div class="search-release-card federation-entity-card podcast-found-card"
role="button" tabindex="0"
@click="$store.podcasts.openFound(hit)"
@keydown.enter="$store.podcasts.openFound(hit)">
<div class="search-release-cover">
<template x-if="hit.image_url">
<img class="artwork-image" :src="hit.image_url" alt="" aria-hidden="true"
loading="lazy" referrerpolicy="no-referrer"
@load="$event.currentTarget.classList.add('artwork-loaded')"
@error="$event.currentTarget.classList.remove('artwork-loaded')">
</template>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5">
<rect x="9" y="2" width="6" height="12" rx="3"/><path d="M5 10a7 7 0 0014 0M12 17v5M8 22h8"/>
</svg>
</div>
<div class="podcast-found-badges">
<span class="podcast-type-badge">{{ t.player_podcast_type }}</span>
<span class="podcast-subscribed-badge" x-show="hit.subscribed">{{ t.player_podcast_found_subscribed }}</span>
</div>
<div class="card-title" x-text="hit.title"></div>
<div class="card-subtitle" x-text="$store.podcasts.foundSubtitle(hit)"></div>
</div>
</template>
</div>
</div>
<template x-for="(track, idx) in $store.library.federationSearch.tracks"
:key="track.key.content_id">
<div class="track-row federation-track-row"
+118
View File
@@ -7121,6 +7121,124 @@ button.user-stat:hover {
padding: 1px 8px;
}
.podcast-share-dialog { max-width: 520px; }
.search-podcasts-section { margin: 4px 0 18px; }
.search-subsection-title {
color: var(--text-secondary);
font-size: 13px;
font-weight: 600;
letter-spacing: 0.02em;
margin: 0 0 8px;
text-transform: uppercase;
}
.podcast-found-badges {
display: flex;
flex-wrap: wrap;
gap: 4px;
margin-bottom: 4px;
}
.podcast-type-badge,
.podcast-subscribed-badge {
border-radius: 8px;
font-size: 10px;
font-weight: 600;
line-height: 1.6;
padding: 0 6px;
}
.podcast-type-badge { background: var(--bg-active); color: var(--text-secondary); }
.podcast-subscribed-badge { background: var(--accent); color: #000; }
.podcast-found-dialog {
max-width: 600px;
max-height: calc(100vh - 48px);
overflow-y: auto;
}
.podcast-found-head {
display: flex;
gap: 16px;
align-items: flex-start;
}
.podcast-found-cover {
position: relative;
flex: 0 0 96px;
width: 96px;
height: 96px;
border-radius: 8px;
background: var(--bg-elevated);
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.podcast-found-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.podcast-found-cover svg { width: 36px; height: 36px; color: var(--text-subdued); }
.podcast-found-heading { min-width: 0; }
.podcast-found-heading h3 { margin: 2px 0 4px; overflow-wrap: anywhere; }
.podcast-found-author,
.podcast-found-meta {
color: var(--text-secondary);
font-size: 13px;
overflow-wrap: anywhere;
}
.podcast-found-link {
color: var(--accent);
display: block;
font-size: 12px;
margin-top: 4px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.podcast-found-description {
color: var(--text-secondary);
font-size: 13px;
line-height: 1.5;
margin: 12px 0;
white-space: pre-line;
overflow-wrap: anywhere;
}
.podcast-found-label {
color: var(--text-subdued);
font-size: 12px;
margin-top: 8px;
}
.podcast-found-dialog .podcast-share-hint {
color: var(--text-subdued);
font-size: 12px;
line-height: 1.5;
}
.podcast-found-preview { margin: 8px 0; }
.podcast-found-seasons { margin: 8px 0; }
.podcast-found-seasons .podcast-chip { cursor: default; }
.podcast-found-status {
color: var(--text-secondary);
font-size: 13px;
margin: 6px 0;
display: flex;
gap: 8px;
align-items: center;
}
.podcast-found-status.error { color: #ff6b6b; }
.podcast-found-episodes {
list-style: none;
margin: 0;
padding: 0;
max-height: 240px;
overflow-y: auto;
}
.podcast-found-episodes li {
border-bottom: 1px solid var(--border-color);
padding: 6px 2px;
}
.podcast-found-episode-title {
font-size: 13px;
overflow-wrap: anywhere;
}
.podcast-found-episode-meta {
color: var(--text-subdued);
font-size: 12px;
}
@media (max-width: 600px) {
.podcast-found-head { flex-direction: column; }
}
.podcast-share-dialog p {
color: var(--text-secondary);
font-size: 13px;