Fix snapcast metadata
authorMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 27 Mar 2025 00:24:24 +0000 (01:24 +0100)
committerMarcel van der Veldt <m.vanderveldt@outlook.com>
Thu, 27 Mar 2025 00:24:24 +0000 (01:24 +0100)
music_assistant/providers/snapcast/__init__.py
music_assistant/providers/snapcast/control.py

index 401e1e65e22e24c378d1e987633bcacacbff8e33..3c8a6784f743ce49f92f5bef097b04ba9a14efe6 100644 (file)
@@ -682,7 +682,10 @@ class SnapCastProvider(PlayerProvider):
         if self._use_builtin_server:
             extra_args = (
                 f"&controlscript={urllib.parse.quote_plus(str(CONTROL_SCRIPT))}"
-                f"&controlscriptparams=--queueid={urllib.parse.quote_plus(queue_id)}%20--api-port={self.mass.webserver.publish_port}"
+                f"&controlscriptparams=--queueid={urllib.parse.quote_plus(queue_id)}%20"
+                f"--api-port={self.mass.webserver.publish_port}%20"
+                f"--streamserver-ip={self.mass.streams.publish_ip}%20"
+                f"--streamserver-port={self.mass.streams.publish_port}"
             )
         else:
             extra_args = ""
index cff41a99dfae8113379eb31b761aa7dee8961b2b..ca620b6033424ecc359805ed1d9d21ca4b599b02 100755 (executable)
@@ -39,10 +39,14 @@ def send(json_msg: dict[str, Any]):
 class MusicAssistantControl:
     """Music Assistant websocket remote control Snapcast plugin."""
 
-    def __init__(self, queue_id: str, api_port: int) -> None:
+    def __init__(
+        self, queue_id: str, streamserver_ip: str, streamserver_port: int, api_port: int
+    ) -> None:
         """Initialize."""
         self.queue_id = queue_id
         self.api_port = api_port
+        self.streamserver_ip = streamserver_ip
+        self.streamserver_port = streamserver_port
         self._metadata = {}
         self._properties = {}
         self._request_callbacks: dict[str, MessageCallback] = {}
@@ -202,7 +206,9 @@ class MusicAssistantControl:
             if image_path := current_queue_item.get("image", {}).get("path"):
                 image_path_encoded = urllib.parse.quote_plus(image_path)
                 image_url = (
-                    f"http://localhost:{self.api_port}/imageproxy?path={image_path_encoded}"
+                    # we prefer the streamserver for the imageproxy because it is enabled by default
+                    # where the api server is by default protected
+                    f"http://{self.streamserver_ip}:{self.streamserver_port}/imageproxy?path={image_path_encoded}"
                     f"&provider={current_queue_item['image']['provider']}"
                     "&size=512"
                 )
@@ -282,11 +288,17 @@ if __name__ == "__main__":
     # Parse command line
     queue_id = None
     api_port = None
+    streamserver_ip = None
+    streamserver_port = None
     for arg in sys.argv:
         if arg.startswith("--stream="):
             stream_id = arg.split("=")[1]
         if arg.startswith("--queueid="):
             queue_id = arg.split("=")[1]
+        if arg.startswith("--streamserver-ip="):
+            streamserver_ip = arg.split("=")[1]
+        if arg.startswith("--streamserver-port="):
+            streamserver_port = arg.split("=")[1]
         if arg.startswith("--api-port="):
             api_port = arg.split("=")[1]
 
@@ -309,7 +321,7 @@ if __name__ == "__main__":
         "Initializing for stream_id %s, queue_id %s and api_port %s", stream_id, queue_id, api_port
     )
 
-    ctrl = MusicAssistantControl(queue_id, int(api_port))
+    ctrl = MusicAssistantControl(queue_id, streamserver_ip, int(streamserver_port), int(api_port))
 
     # keep listening for messages on stdin and forward them
     try: