feat: passthrough Icecast metadata headers for RNS proxy
This commit is contained in:
@@ -636,15 +636,18 @@ def iter_stream_transcode(target_url):
|
||||
finally:
|
||||
process.kill()
|
||||
|
||||
def iter_stream(target_url):
|
||||
import requests
|
||||
with requests.get(target_url, stream=True, timeout=10) as r:
|
||||
def iter_stream(r):
|
||||
try:
|
||||
for chunk in r.iter_content(chunk_size=8192):
|
||||
if chunk:
|
||||
yield chunk
|
||||
finally:
|
||||
r.close()
|
||||
|
||||
from fastapi import Request
|
||||
|
||||
@app.get("/live/{station}")
|
||||
def live_stream_redirect(station: str, db: Session = Depends(db_session)):
|
||||
def live_stream_redirect(station: str, request: Request, db: Session = Depends(db_session)):
|
||||
# Usuwamy sztuczne rozszerzenia dodane dla Mopidy
|
||||
if station.endswith(".aac"):
|
||||
station = station[:-4]
|
||||
@@ -664,7 +667,22 @@ def live_stream_redirect(station: str, db: Session = Depends(db_session)):
|
||||
elif station == "rns":
|
||||
config_url = db.query(Config).filter_by(key="rns_live_url").first()
|
||||
target_url = config_url.value if config_url else "https://stream.rcs.revma.com/4md4m0a0fs8uv"
|
||||
return StreamingResponse(iter_stream(target_url), media_type="audio/mpeg")
|
||||
|
||||
# Przekazujemy żądanie o metadane z odtwarzacza (Mopidy) do serwera (Revma)
|
||||
req_headers = {}
|
||||
if "icy-metadata" in request.headers:
|
||||
req_headers["Icy-MetaData"] = request.headers["icy-metadata"]
|
||||
|
||||
import requests
|
||||
r = requests.get(target_url, stream=True, timeout=10, headers=req_headers)
|
||||
|
||||
# Odbieramy nagłówki metadanych od Revmy i przekazujemy z powrotem do odtwarzacza
|
||||
resp_headers = {}
|
||||
for k, v in r.headers.items():
|
||||
if k.lower().startswith("icy-"):
|
||||
resp_headers[k] = v
|
||||
|
||||
return StreamingResponse(iter_stream(r), media_type="audio/mpeg", headers=resp_headers)
|
||||
|
||||
else:
|
||||
raise HTTPException(status_code=404, detail="Brak streamu dla podanej stacji")
|
||||
|
||||
Reference in New Issue
Block a user