From 715386a4d0f0a43ce633a7d77823e513c5d39215 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 3 May 2024 16:46:30 +0200 Subject: [PATCH] Mark item played on Plex after playback finishes (#1266) Mark item played on plex after playback finishes --- music_assistant/server/providers/plex/__init__.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/music_assistant/server/providers/plex/__init__.py b/music_assistant/server/providers/plex/__init__.py index 01dced2b..c1558723 100644 --- a/music_assistant/server/providers/plex/__init__.py +++ b/music_assistant/server/providers/plex/__init__.py @@ -787,6 +787,16 @@ class PlexProvider(MusicProvider): return stream_details + async def on_streamed(self, streamdetails: StreamDetails, seconds_streamed: int) -> None: + """Handle callback when an item completed streaming.""" + + def mark_played(): + item = streamdetails.data + params = {"key": str(item.ratingKey), "identifier": "com.plexapp.plugins.library"} + self._plex_server.query("/:/scrobble", params=params) + + await asyncio.to_thread(mark_played) + async def get_myplex_account_and_refresh_token(self, auth_token: str) -> MyPlexAccount: """Get a MyPlexAccount object and refresh the token if needed.""" -- 2.34.1