feat: add ffmpeg transcode proxy for Radio 357 to serve pure MP3 to Mopidy
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@ FROM python:3.11-slim
|
|||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y tzdata && \
|
RUN apt-get update && apt-get install -y tzdata ffmpeg && \
|
||||||
ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && echo Europe/Warsaw > /etc/timezone && \
|
ln -snf /usr/share/zoneinfo/Europe/Warsaw /etc/localtime && echo Europe/Warsaw > /etc/timezone && \
|
||||||
apt-get clean
|
apt-get clean
|
||||||
|
|
||||||
|
|||||||
@@ -612,6 +612,30 @@ def podcast_rss(station: str, slug_with_ext: str, request: Request, db: Session
|
|||||||
return Response(status_code=404)
|
return Response(status_code=404)
|
||||||
return Response(content=xml, media_type="application/xml")
|
return Response(content=xml, media_type="application/xml")
|
||||||
|
|
||||||
|
def iter_stream_transcode(target_url):
|
||||||
|
import subprocess
|
||||||
|
cmd = [
|
||||||
|
"ffmpeg",
|
||||||
|
"-reconnect", "1",
|
||||||
|
"-reconnect_streamed", "1",
|
||||||
|
"-reconnect_delay_max", "5",
|
||||||
|
"-loglevel", "error",
|
||||||
|
"-i", target_url,
|
||||||
|
"-c:a", "libmp3lame",
|
||||||
|
"-b:a", "320k",
|
||||||
|
"-f", "mp3",
|
||||||
|
"-"
|
||||||
|
]
|
||||||
|
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.DEVNULL)
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
chunk = process.stdout.read(8192)
|
||||||
|
if not chunk:
|
||||||
|
break
|
||||||
|
yield chunk
|
||||||
|
finally:
|
||||||
|
process.kill()
|
||||||
|
|
||||||
def iter_stream(target_url):
|
def iter_stream(target_url):
|
||||||
import requests
|
import requests
|
||||||
with requests.get(target_url, stream=True, timeout=10) as r:
|
with requests.get(target_url, stream=True, timeout=10) as r:
|
||||||
@@ -634,8 +658,8 @@ def live_stream_redirect(station: str, db: Session = Depends(db_session)):
|
|||||||
if station == "radio357":
|
if station == "radio357":
|
||||||
config_url = db.query(Config).filter_by(key="r357_live_url").first()
|
config_url = db.query(Config).filter_by(key="r357_live_url").first()
|
||||||
target_url = config_url.value if config_url else "https://stream.rcs.revma.com/ye5kghkgcm0uv"
|
target_url = config_url.value if config_url else "https://stream.rcs.revma.com/ye5kghkgcm0uv"
|
||||||
# Proxy strumienia! Zwracamy jako audio/mpeg żeby ominąć unwrapper
|
# Proxy + Transkodowanie AAC -> MP3 w locie!
|
||||||
return StreamingResponse(iter_stream(target_url), media_type="audio/mpeg")
|
return StreamingResponse(iter_stream_transcode(target_url), media_type="audio/mpeg")
|
||||||
|
|
||||||
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()
|
||||||
|
|||||||
Reference in New Issue
Block a user