Skip to content

Commit

Permalink
Fix: allow seek support in providers which support it
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelveldt committed Feb 5, 2025
1 parent 69cc185 commit 3640aeb
Show file tree
Hide file tree
Showing 19 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
stream_type=StreamType.HTTP,
# explore the StreamDetails model and StreamType enum for more options
# but the above should be the mandatory fields to set.
allow_seek=True,
# set allow_seek to True if the stream may be seeked
can_seek=True,
# set can_seek to True if the stream supports seeking
)

async def get_audio_stream(
Expand Down
1 change: 1 addition & 0 deletions music_assistant/providers/apple_music/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
path=stream_url,
decryption_key=await self._get_decryption_key(license_url, key_id, uri, item_id),
can_seek=True,
allow_seek=True,
)

def _parse_artist(self, artist_obj):
Expand Down
8 changes: 2 additions & 6 deletions music_assistant/providers/audible/audible_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
import audible
import audible.register
from audible import AsyncClient
from music_assistant_models.enums import (
ContentType,
ImageType,
MediaType,
StreamType,
)
from music_assistant_models.enums import ContentType, ImageType, MediaType, StreamType
from music_assistant_models.errors import LoginFailed
from music_assistant_models.media_items import (
Audiobook,
Expand Down Expand Up @@ -169,6 +164,7 @@ async def get_stream(self, asin: str) -> StreamDetails:
stream_type=StreamType.HTTP,
path=m3u8_url,
can_seek=True,
allow_seek=True,
duration=duration,
data={"acr": acr},
)
Expand Down
6 changes: 6 additions & 0 deletions music_assistant/providers/audiobookshelf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,8 @@ async def get_streamdetails_from_playback_session(
media_type=media_type,
stream_type=StreamType.HLS,
path=stream_url,
can_seek=True,
allow_seek=True,
)

async def get_stream_details(self, item_id: str, media_type: MediaType) -> StreamDetails:
Expand Down Expand Up @@ -490,6 +492,8 @@ async def _get_stream_details_audiobook(
media_type=MediaType.AUDIOBOOK,
stream_type=StreamType.HTTP,
path=stream_url,
can_seek=True,
allow_seek=True,
)

async def _get_stream_details_podcast_episode(self, podcast_id: str) -> StreamDetails:
Expand Down Expand Up @@ -517,6 +521,8 @@ async def _get_stream_details_podcast_episode(self, podcast_id: str) -> StreamDe
media_type=MediaType.PODCAST_EPISODE,
stream_type=StreamType.HTTP,
path=full_url,
can_seek=True,
allow_seek=True,
)

async def on_played(
Expand Down
1 change: 1 addition & 0 deletions music_assistant/providers/builtin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
stream_type=StreamType.HTTP,
path=item_id,
can_seek=not is_radio,
allow_seek=not is_radio,
)

async def _get_builtin_playlist_random_favorite_tracks(self) -> list[Track]:
Expand Down
2 changes: 2 additions & 0 deletions music_assistant/providers/deezer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,8 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
# separately so we can use it later on.
data={"url": url, "format": url_details["format"], "track_id": song_data["SNG_ID"]},
size=int(song_data[f"FILESIZE_{url_details['format']}"]),
can_seek=True,
allow_seek=True,
)

async def get_audio_stream(
Expand Down
1 change: 1 addition & 0 deletions music_assistant/providers/filesystem_local/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1550,6 +1550,7 @@ async def _get_stream_details_for_track(self, item_id: str) -> StreamDetails:
data=file_item,
path=file_item.absolute_path,
can_seek=True,
allow_seek=True,
)

async def _get_stream_details_for_podcast_episode(self, item_id: str) -> StreamDetails:
Expand Down
2 changes: 2 additions & 0 deletions music_assistant/providers/ibroadcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
),
stream_type=StreamType.HTTP,
path=url,
can_seek=True,
allow_seek=True,
)

async def _get_tracks(self, track_ids: list[int], is_playlist: bool = False) -> list[Track]:
Expand Down
2 changes: 2 additions & 0 deletions music_assistant/providers/jellyfin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,8 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
jellyfin_track[ITEM_KEY_RUNTIME_TICKS] / 10000000
), # 10000000 ticks per millisecond)
path=url,
can_seek=True,
allow_seek=True,
)

async def get_similar_tracks(self, prov_track_id: str, limit: int = 25) -> list[Track]:
Expand Down
2 changes: 2 additions & 0 deletions music_assistant/providers/plex/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,8 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
stream_type=StreamType.HTTP,
duration=plex_track.duration,
data=plex_track,
can_seek=True,
allow_seek=True,
)

if content_type != ContentType.M4A:
Expand Down
2 changes: 2 additions & 0 deletions music_assistant/providers/podcastfeed/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
media_type=MediaType.PODCAST_EPISODE,
stream_type=StreamType.HTTP,
path=episode["enclosures"][0]["url"],
can_seek=True,
allow_seek=True,
)
raise MediaNotFoundError("Stream not found")

Expand Down
2 changes: 2 additions & 0 deletions music_assistant/providers/qobuz/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,8 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
duration=streamdata["duration"],
data=streamdata, # we need these details for reporting playback
path=streamdata["url"],
can_seek=True,
allow_seek=True,
)

async def _report_playback_started(self, streamdata: dict) -> None:
Expand Down
6 changes: 5 additions & 1 deletion music_assistant/providers/radiobrowser/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ async def get_library_radios(self) -> AsyncGenerator[Radio, None]:
if TYPE_CHECKING:
stored_radios = cast(list[str], stored_radios)
for item in stored_radios:
yield await self.get_radio(item)
try:
yield await self.get_radio(item)
except MediaNotFoundError as err:
self.logger.warning("Radio station %s not found: %s", item, err)

async def library_add(self, item: MediaItemType) -> bool:
"""Add item to provider's library. Return true on success."""
Expand Down Expand Up @@ -364,4 +367,5 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
stream_type=StreamType.HTTP,
path=stream.url_resolved,
can_seek=False,
allow_seek=False,
)
1 change: 1 addition & 0 deletions music_assistant/providers/siriusxm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
media_type=MediaType.RADIO,
path=hls_path,
can_seek=False,
allow_seek=False,
)

return self._current_stream_details
Expand Down
2 changes: 2 additions & 0 deletions music_assistant/providers/soundcloud/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
if url.startswith("https://cf-hls-media.sndcdn.com")
else StreamType.HTTP,
path=url,
can_seek=True,
allow_seek=True,
)

async def _parse_artist(self, artist_obj: dict[str, Any]) -> Artist:
Expand Down
1 change: 1 addition & 0 deletions music_assistant/providers/test/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,4 +353,5 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
stream_type=StreamType.HTTP,
path=SILENCE_FILE_LONG,
can_seek=True,
allow_seek=True,
)
2 changes: 2 additions & 0 deletions music_assistant/providers/tidal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
stream_type=StreamType.HTTP,
duration=track.duration,
path=url,
can_seek=True,
allow_seek=True,
)

@throttle_with_retries
Expand Down
2 changes: 2 additions & 0 deletions music_assistant/providers/tunein/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
media_type=MediaType.RADIO,
stream_type=StreamType.HTTP,
path=item_id,
allow_seek=False,
can_seek=False,
)
if "--" in item_id:
Expand All @@ -269,6 +270,7 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
media_type=MediaType.RADIO,
stream_type=StreamType.HTTP,
path=stream["url"],
allow_seek=False,
can_seek=False,
)
msg = f"Unable to retrieve stream details for {item_id}"
Expand Down
2 changes: 2 additions & 0 deletions music_assistant/providers/ytmusic/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ async def get_stream_details(self, item_id: str, media_type: MediaType) -> Strea
),
stream_type=StreamType.HTTP,
path=stream_format["url"],
can_seek=True,
allow_seek=True,
)
if (
stream_format.get("audio_channels")
Expand Down

0 comments on commit 3640aeb

Please sign in to comment.