Changeset b56afa7 in Klonkt
- Timestamp:
- 06/20/2026 04:08:28 AM (3 months ago)
- Branches:
- main
- Children:
- d43ea3f
- Parents:
- 976d36d
- Location:
- src
- Files:
-
- 3 edited
-
assets/js/embed-player.js (modified) (2 diffs)
-
routes/audio.js (modified) (1 diff)
-
views/shell.ejs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
src/assets/js/embed-player.js
r976d36d rb56afa7 233 233 let preMuteVol = 100; 234 234 // Audio-only YouTube: zet de thumbnail als albumhoes op de audio-kaart. 235 let ytTitle = ''; // echte videotitel (via same-origin oEmbed-proxy) 235 236 if (audioOnly && ytThumb) { 236 237 const art0 = el.querySelector('.pcms-embed-art'); 237 238 if (art0) { art0.style.backgroundImage = `url('${ytThumb}')`; art0.classList.add('has-art'); } 239 // Haal de echte titel op (server-proxy, want YT-oEmbed heeft geen CORS) en 240 // toon 'm i.p.v. "YouTube". 241 fetch('/audio/yt-title?url=' + encodeURIComponent(url)) 242 .then((r) => (r.ok ? r.json() : null)) 243 .then((d) => { 244 if (d && d.title) { 245 ytTitle = d.title; 246 const tt = el.querySelector('.pcms-embed-title'); 247 if (tt) tt.textContent = d.title; 248 } 249 }) 250 .catch(() => {}); 238 251 } 239 252 … … 314 327 // én doorspelen bij navigeren. De inline-kaart is enkel de launcher. 315 328 if (audioOnly && window.pcmsAudioPlayer && typeof window.pcmsAudioPlayer.playYouTube === 'function') { 316 window.pcmsAudioPlayer.playYouTube({ id: ytId(ref, url), cover: ytThumb, postUrl: location.pathname + location.search });329 window.pcmsAudioPlayer.playYouTube({ id: ytId(ref, url), title: ytTitle || undefined, cover: ytThumb, postUrl: location.pathname + location.search }); 317 330 el.classList.add('pcms-embed-elsewhere'); 318 331 return; -
src/routes/audio.js
r976d36d rb56afa7 158 158 }); 159 159 160 // Same-origin proxy voor de YouTube-titel (oEmbed). YouTube's oEmbed stuurt geen 161 // CORS-header, dus de browser kan 'm niet direct fetchen — wij halen 'm server- 162 // side op (geen CORS) en cachen 't. Gebruikt door de audio-only YT-embed om de 163 // echte videotitel te tonen i.p.v. "YouTube". 164 const ytTitleCache = new Map(); 165 router.get('/yt-title', async (req, res) => { 166 const url = String(req.query.url || ''); 167 if (!/^https:\/\/(www\.)?(youtube\.com|youtu\.be|youtube-nocookie\.com)\//i.test(url)) { 168 return res.status(400).json({ error: 'bad url' }); 169 } 170 if (ytTitleCache.has(url)) return res.json({ title: ytTitleCache.get(url) }); 171 try { 172 const ac = new AbortController(); 173 const timer = setTimeout(() => ac.abort(), 6000); 174 const r = await fetch('https://www.youtube.com/oembed?format=json&url=' + encodeURIComponent(url), { signal: ac.signal }); 175 clearTimeout(timer); 176 if (!r.ok) { ytTitleCache.set(url, ''); return res.json({ title: '' }); } 177 const d = await r.json(); 178 const title = (d && d.title) ? String(d.title).slice(0, 200) : ''; 179 ytTitleCache.set(url, title); 180 res.json({ title }); 181 } catch (e) { 182 res.status(502).json({ error: 'fetch failed' }); 183 } 184 }); 185 160 186 export default router; -
src/views/shell.ejs
r976d36d rb56afa7 303 303 <!-- Eigen custom media-embeds (YouTube/SoundCloud/Spotify) via de echte 304 304 player-API's + gedeelde mutual-exclusion registry met de site-speler. --> 305 <script src="/assets/js/embed-player.js?v=1 0" defer></script>305 <script src="/assets/js/embed-player.js?v=11" defer></script> 306 306 <% if (site && site.enable_audio_player && audioTracks && audioTracks.length > 0) { %> 307 307 <script>window.PCMS_SITE_TRACKS = <%- JSON.stringify(audioTracks) %>;</script>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)