From 85776390f6381b067ff92a543d0b8a6f7eb52c7a Mon Sep 17 00:00:00 2001 From: marwin Date: Sat, 21 Mar 2026 17:50:12 +0100 Subject: [PATCH] Open HTTP streams in minimal standalone player tab MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of trying a HTTPS upgrade (which fails for IP-based streams): - playStation() detects http:// URL on https:// page, opens /radio/stream-player/ with url, name, vol as query params, then returns — main stream is already stopped by the stopPlayback(false) call at the top of playStation() - New view stream_player renders a standalone minimal player page - Template: auto-plays on load, correct volume from URL param, volume changes synced back to localStorage so main window picks it up next time, live track metadata via SSE, tab title updates on track change, close-tab button Co-Authored-By: Claude Sonnet 4.6 --- radio/urls.py | 1 + radio/views.py | 17 ++++ static/js/app.js | 28 ++--- templates/radio/stream_player.html | 157 +++++++++++++++++++++++++++++ 4 files changed, 184 insertions(+), 19 deletions(-) create mode 100644 templates/radio/stream_player.html diff --git a/radio/urls.py b/radio/urls.py index 65ecb01..acd6c77 100644 --- a/radio/urls.py +++ b/radio/urls.py @@ -18,4 +18,5 @@ urlpatterns = [ path('radio/notes//', views.save_station_notes, name='save_station_notes'), path('radio/focus/record/', views.record_focus_session, name='record_focus_session'), path('radio/focus/stats/', views.focus_stats, name='focus_stats'), + path('radio/stream-player/', views.stream_player, name='stream_player'), ] diff --git a/radio/views.py b/radio/views.py index 29a29df..af6a122 100644 --- a/radio/views.py +++ b/radio/views.py @@ -1,4 +1,6 @@ import json +import socket +import ssl as ssl_module import time import urllib.parse from datetime import datetime @@ -573,3 +575,18 @@ def import_m3u(request): skipped += 1 return JsonResponse({'ok': True, 'added': added, 'skipped': skipped}) + + +# --------------------------------------------------------------------------- +# Minimal HTTP stream player (standalone tab for mixed-content streams) +# --------------------------------------------------------------------------- + +def stream_player(request): + url = request.GET.get('url', '').strip() + name = request.GET.get('name', '').strip() + vol = request.GET.get('vol', '204').strip() + try: + vol = max(0, min(255, int(vol))) + except ValueError: + vol = 204 + return render(request, 'radio/stream_player.html', {'stream_url': url, 'stream_name': name, 'stream_vol': vol}) diff --git a/static/js/app.js b/static/js/app.js index c91f6e4..f008577 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -67,28 +67,18 @@ function escapeHtml(str) { function playStation(url, name, stationId) { stopPlayback(false); + // HTTP stream on HTTPS page → open minimal player in new tab, keep main window as home base + if (location.protocol === 'https:' && url.startsWith('http://')) { + const vol = localStorage.getItem('diora_volume') || '204'; + const params = new URLSearchParams({ url, name, vol }); + window.open('/radio/stream-player/?' + params, '_blank'); + return; + } + currentStation = { url, name, id: stationId || null }; isPlaying = true; - // If page is HTTPS and stream is HTTP, try upgrading to HTTPS first. - // Browsers block mixed content (HTTP media on HTTPS pages). - const playUrl = (location.protocol === 'https:' && url.startsWith('http://')) - ? url.replace('http://', 'https://') - : url; - - audio.onerror = () => { - const wasUpgraded = playUrl !== url; - if (wasUpgraded) { - $('now-playing-track').textContent = 'Stream nicht erreichbar (HTTP-only, kein HTTPS-Fallback)'; - } else { - $('now-playing-track').textContent = 'Stream konnte nicht geladen werden'; - } - isPlaying = false; - $('play-stop-btn').textContent = '▶ Play'; - $('play-stop-btn').classList.remove('playing'); - }; - - audio.src = playUrl; + audio.src = url; const volSlider = document.getElementById('volume'); if (volSlider) audio.volume = volSlider.value / 255; audio.play().catch(() => { diff --git a/templates/radio/stream_player.html b/templates/radio/stream_player.html new file mode 100644 index 0000000..6b270d1 --- /dev/null +++ b/templates/radio/stream_player.html @@ -0,0 +1,157 @@ + + + + + + {{ stream_name|default:"Radio" }} + + + +
{{ stream_name|default:"Radio" }}
+
+ +
+ +
+ vol + + +
+
+ + + + + +