output_format=AIRPLAY_PCM_FORMAT,
use_pre_announce=media.custom_data["use_pre_announce"],
)
- elif media.queue_id.startswith("ugp_"):
+ elif media.queue_id and media.queue_id.startswith("ugp_"):
# special case: UGP stream
ugp_provider: PlayerGroupProvider = self.mass.get_provider("player_group")
ugp_stream = ugp_provider.ugp_streams[media.queue_id]
input_format = AIRPLAY_PCM_FORMAT
audio_source = get_ffmpeg_stream(
audio_input=media.uri,
- input_format=AudioFormat(ContentType.try_parse(media.uri)),
+ input_format=AudioFormat(content_type=ContentType.try_parse(media.uri)),
output_format=AIRPLAY_PCM_FORMAT,
)
# setup RaopStreamSession for player (and its sync childs if any)
import asyncio
import contextlib
import os
-import platform
import time
from typing import TYPE_CHECKING, Any, cast
from urllib.parse import urlencode
from music_assistant.helpers.util import lock, parse_title_and_version
from music_assistant.models.music_provider import MusicProvider
+from .helpers import get_librespot_binary
+
if TYPE_CHECKING:
from collections.abc import AsyncGenerator
self.throttler.rate_limit = 45
self.throttler.period = 30
# check if we have a librespot binary for this arch
- await self.get_librespot_binary()
+ self._librespot_bin = await get_librespot_binary()
# try login which will raise if it fails
await self.login()
self, streamdetails: StreamDetails, seek_position: int = 0
) -> AsyncGenerator[bytes, None]:
"""Return the audio stream for the provider item."""
- librespot = await self.get_librespot_binary()
spotify_uri = f"spotify://track:{streamdetails.item_id}"
self.logger.log(VERBOSE_LOG_LEVEL, f"Start streaming {spotify_uri} using librespot")
args = [
- librespot,
+ self._librespot_bin,
"--cache",
self.cache_dir,
"--cache-size-limit",
self.instance_id, CONF_REFRESH_TOKEN, auth_info["refresh_token"], encrypted=True
)
# check if librespot still has valid auth
- librespot = await self.get_librespot_binary()
args = [
- librespot,
+ self._librespot_bin,
"--cache",
self.cache_dir,
"--check-auth",
response.raise_for_status()
return await response.json(loads=json_loads)
- async def get_librespot_binary(self):
- """Find the correct librespot binary belonging to the platform."""
- # ruff: noqa: SIM102
- if self._librespot_bin is not None:
- return self._librespot_bin
-
- async def check_librespot(librespot_path: str) -> str | None:
- try:
- returncode, output = await check_output(librespot_path, "--version")
- if returncode == 0 and b"librespot" in output:
- self._librespot_bin = librespot_path
- return librespot_path
- except OSError:
- return None
-
- base_path = os.path.join(os.path.dirname(__file__), "bin")
- system = platform.system().lower().replace("darwin", "macos")
- architecture = platform.machine().lower()
-
- if bridge_binary := await check_librespot(
- os.path.join(base_path, f"librespot-{system}-{architecture}")
- ):
- return bridge_binary
-
- msg = f"Unable to locate Librespot for {system}/{architecture}"
- raise RuntimeError(msg)
-
def _fix_create_playlist_api_bug(self, playlist_obj: dict[str, Any]) -> None:
"""Fix spotify API bug where incorrect owner id is returned from Create Playlist."""
if playlist_obj["owner"]["id"] != self._sp_user["id"]:
--- /dev/null
+"""Helpers/utils for the Spotify musicprovider."""
+
+from __future__ import annotations
+
+import os
+import platform
+
+from music_assistant.helpers.process import check_output
+
+
+async def get_librespot_binary():
+ """Find the correct librespot binary belonging to the platform."""
+
+ # ruff: noqa: SIM102
+ async def check_librespot(librespot_path: str) -> str | None:
+ try:
+ returncode, output = await check_output(librespot_path, "--version")
+ if returncode == 0 and b"librespot" in output:
+ return librespot_path
+ except OSError:
+ return None
+
+ base_path = os.path.join(os.path.dirname(__file__), "bin")
+ system = platform.system().lower().replace("darwin", "macos")
+ architecture = platform.machine().lower()
+
+ if bridge_binary := await check_librespot(
+ os.path.join(base_path, f"librespot-{system}-{architecture}")
+ ):
+ return bridge_binary
+
+ msg = f"Unable to locate Librespot for {system}/{architecture}"
+ raise RuntimeError(msg)