feat: passthrough Icecast metadata headers for RNS proxy
This commit is contained in:
@@ -636,15 +636,18 @@ def iter_stream_transcode(target_url):
|
|||||||
finally:
|
finally:
|
||||||
process.kill()
|
process.kill()
|
||||||
|
|
||||||
def iter_stream(target_url):
|
def iter_stream(r):
|
||||||
import requests
|
try:
|
||||||
with requests.get(target_url, stream=True, timeout=10) as r:
|
|
||||||
for chunk in r.iter_content(chunk_size=8192):
|
for chunk in r.iter_content(chunk_size=8192):
|
||||||
if chunk:
|
if chunk:
|
||||||
yield chunk
|
yield chunk
|
||||||
|
finally:
|
||||||
|
r.close()
|
||||||
|
|
||||||
|
from fastapi import Request
|
||||||
|
|
||||||
@app.get("/live/{station}")
|
@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
|
# Usuwamy sztuczne rozszerzenia dodane dla Mopidy
|
||||||
if station.endswith(".aac"):
|
if station.endswith(".aac"):
|
||||||
station = station[:-4]
|
station = station[:-4]
|
||||||
@@ -664,7 +667,22 @@ def live_stream_redirect(station: str, db: Session = Depends(db_session)):
|
|||||||
elif station == "rns":
|
elif station == "rns":
|
||||||
config_url = db.query(Config).filter_by(key="rns_live_url").first()
|
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"
|
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:
|
else:
|
||||||
raise HTTPException(status_code=404, detail="Brak streamu dla podanej stacji")
|
raise HTTPException(status_code=404, detail="Brak streamu dla podanej stacji")
|
||||||
|
|||||||
Reference in New Issue
Block a user