Skip to content

Commit

Permalink
Subsonic: Check for transcodeOffset support on startup
Browse files Browse the repository at this point in the history
If this support is present, then we can seek using the stream endpoint
timeOffset argument. If not we need to fall back to having the player
provider do it.

Signed-off-by: Eric B Munson <[email protected]>
  • Loading branch information
khers committed Mar 13, 2024
1 parent 9531797 commit 1578b66
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions music_assistant/server/providers/opensubsonic/sonic_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class OpenSonicProvider(MusicProvider):

_conn: SonicConnection = None
_enable_podcasts: bool = True
_seek_support: bool = False

async def handle_async_init(self) -> None:
"""Set up the music provider and test the connection."""
Expand Down Expand Up @@ -97,6 +98,17 @@ async def handle_async_init(self) -> None:
)
raise LoginFailed(msg) from e
self._enable_podcasts = self.config.get_value(CONF_ENABLE_PODCASTS)
try:
ret = await self._run_async(self._conn.getOpenSubsonicExtensions)
extensions = ret["openSubsonicExtensions"]
for entry in extensions:
if entry["name"] == "transcodeOffset":
self._seek_support = True
break
except OSError:
logging.getLogger("libopensonic").info(
"Server does not support transcodeOffset, seeking in player provider"
)

@property
def supported_features(self) -> tuple[ProviderFeature, ...]:
Expand Down Expand Up @@ -656,6 +668,7 @@ async def get_stream_details(self, item_id: str) -> StreamDetails | None:
return StreamDetails(
item_id=sonic_song.id,
provider=self.instance_id,
can_seek=self._seek_support,
audio_format=AudioFormat(content_type=ContentType.try_parse(mime_type)),
duration=sonic_song.duration if sonic_song.duration is not None else 0,
callback=self._report_playback_stopped,
Expand Down

0 comments on commit 1578b66

Please sign in to comment.