From 460a817072718043dbaa45341285e59be4a8291d Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 10 Jan 2025 23:27:17 +0100 Subject: [PATCH] Feat: Allow core logic to handle seeking for providers without native seek support --- music_assistant/controllers/streams.py | 10 +++++----- .../providers/opensubsonic/sonic_provider.py | 5 +++++ music_assistant/providers/spotify/__init__.py | 2 ++ 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/music_assistant/controllers/streams.py b/music_assistant/controllers/streams.py index 29a601dc..1596ba5f 100644 --- a/music_assistant/controllers/streams.py +++ b/music_assistant/controllers/streams.py @@ -910,9 +910,6 @@ class StreamsController(CoreController): pcm_format: AudioFormat, ) -> AsyncGenerator[tuple[bool, bytes], None]: """Get the audio stream for the given streamdetails as raw pcm chunks.""" - is_radio = streamdetails.media_type == MediaType.RADIO or not streamdetails.duration - if is_radio: - streamdetails.seek_position = 0 # collect all arguments for ffmpeg filter_params = [] extra_input_args = [] @@ -978,8 +975,11 @@ class StreamsController(CoreController): # handle seek support if ( streamdetails.seek_position - and streamdetails.media_type != MediaType.RADIO - and streamdetails.stream_type != StreamType.CUSTOM + and streamdetails.duration + and streamdetails.allow_seek + # allow seeking for custom streams, + # but only for custom streams that can't seek theirselves + and (streamdetails.stream_type != StreamType.CUSTOM or not streamdetails.can_seek) ): extra_input_args += ["-ss", str(int(streamdetails.seek_position))] diff --git a/music_assistant/providers/opensubsonic/sonic_provider.py b/music_assistant/providers/opensubsonic/sonic_provider.py index f86e240c..db1bc600 100644 --- a/music_assistant/providers/opensubsonic/sonic_provider.py +++ b/music_assistant/providers/opensubsonic/sonic_provider.py @@ -874,6 +874,7 @@ class OpenSonicProvider(MusicProvider): return StreamDetails( item_id=item.id, provider=self.instance_id, + allow_seek=True, can_seek=self._seek_support, media_type=media_type, audio_format=AudioFormat(content_type=ContentType.try_parse(mime_type)), @@ -902,6 +903,10 @@ class OpenSonicProvider(MusicProvider): ) -> AsyncGenerator[bytes, None]: """Provide a generator for the stream data.""" audio_buffer = asyncio.Queue(1) + # ignore seek position if the server does not support it + # in that case we let the core handle seeking + if not self._seek_support: + seek_position = 0 self.logger.debug("Streaming %s", streamdetails.item_id) diff --git a/music_assistant/providers/spotify/__init__.py b/music_assistant/providers/spotify/__init__.py index f855811d..268f4d63 100644 --- a/music_assistant/providers/spotify/__init__.py +++ b/music_assistant/providers/spotify/__init__.py @@ -556,6 +556,8 @@ class SpotifyProvider(MusicProvider): content_type=ContentType.OGG, ), stream_type=StreamType.CUSTOM, + allow_seek=True, + can_seek=True, ) async def get_audio_stream( -- 2.34.1