A way to override base_url (#802) (#447)
authorLars Solberg <lars.solberg+github@gmail.com>
Fri, 5 Aug 2022 09:39:03 +0000 (11:39 +0200)
committerGitHub <noreply@github.com>
Fri, 5 Aug 2022 09:39:03 +0000 (11:39 +0200)
* A way to override base_url (#802)

music_assistant/constants.py
music_assistant/controllers/streams.py

index 13eed2d00a9c1d9af18bff4c40bc530c0ea9f004..1a2a5e44ed8af6f6a02cd3a5d36a2d91d6214c87 100755 (executable)
@@ -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"
index 4d5e931ef7a9fb23e87216105c26090ecdae9511..655fadb12a854d1f3a313c53c8e4c780e6f91fe8 100644 (file)
@@ -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(