From 453f0999376230a7deb9d32a96e3aa3360db8a57 Mon Sep 17 00:00:00 2001 From: Lars Solberg Date: Fri, 5 Aug 2022 11:39:03 +0200 Subject: [PATCH] A way to override base_url (#802) (#447) * A way to override base_url (#802) --- music_assistant/constants.py | 3 +++ music_assistant/controllers/streams.py | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/music_assistant/constants.py b/music_assistant/constants.py index 13eed2d0..1a2a5e44 100755 --- a/music_assistant/constants.py +++ b/music_assistant/constants.py @@ -16,3 +16,6 @@ SILENCE_FILE = str(RESOURCES_DIR.joinpath("silence.mp3")) # if duration is None (e.g. radio stream) = 48 hours FALLBACK_DURATION = 172800 + +# Name of the environment-variable to override base_url +BASE_URL_OVERRIDE_ENVNAME = "MASS_BASE_URL" diff --git a/music_assistant/controllers/streams.py b/music_assistant/controllers/streams.py index 4d5e931e..655fadb1 100644 --- a/music_assistant/controllers/streams.py +++ b/music_assistant/controllers/streams.py @@ -3,6 +3,7 @@ from __future__ import annotations import asyncio import gc +import os import urllib.parse from time import time from types import CoroutineType @@ -11,7 +12,11 @@ from uuid import uuid4 from aiohttp import web -from music_assistant.constants import FALLBACK_DURATION, SILENCE_FILE +from music_assistant.constants import ( + BASE_URL_OVERRIDE_ENVNAME, + FALLBACK_DURATION, + SILENCE_FILE, +) from music_assistant.helpers.audio import ( check_audio_support, crossfade_pcm_parts, @@ -56,6 +61,15 @@ class StreamsController: @property def base_url(self) -> str: """Return the base url for the stream engine.""" + + if BASE_URL_OVERRIDE_ENVNAME in os.environ: + # This is a purpously undocumented feature to override the automatic + # generated base_url used by the streaming-devices. + # If you need this, you know it, but you should probably try to not set it! + # Also see https://github.com/music-assistant/hass-music-assistant/issues/802 + # and https://github.com/music-assistant/hass-music-assistant/discussions/794#discussioncomment-3331209 + return os.environ[BASE_URL_OVERRIDE_ENVNAME] + return f"http://{self._ip}:{self._port}" def get_stream_url( -- 2.34.1