From 39aef5babf13a41465f45d456b255fb88920ad60 Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sat, 14 Sep 2024 23:44:32 +0200 Subject: [PATCH 1/3] Test wrap command function in a mutex to avoid race conditions with the _command_offset --- src/iSponsorBlockTV/ytlounge.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/iSponsorBlockTV/ytlounge.py b/src/iSponsorBlockTV/ytlounge.py index ce5f398..ec1a900 100644 --- a/src/iSponsorBlockTV/ytlounge.py +++ b/src/iSponsorBlockTV/ytlounge.py @@ -35,6 +35,7 @@ class YtLoungeApi(pyytlounge.YtLoungeApi): self.mute_ads = config.mute_ads self.skip_ads = config.skip_ads self.auto_play = config.auto_play + self._command_mutex = asyncio.Lock() # Ensures that we still are subscribed to the lounge async def _watchdog(self): @@ -181,3 +182,9 @@ class YtLoungeApi(pyytlounge.YtLoungeApi): async def play_video(self, video_id: str) -> bool: return await self._command("setPlaylist", {"videoId": video_id}) + + # Test to wrap the command function in a mutex to avoid race conditions with + # the _command_offset (TODO: move to upstream if it works) + async def _command(self, command: str, command_parameters: dict = None) -> bool: + async with self._command_mutex: + return await super()._command(command, command_parameters) \ No newline at end of file From 5fadc81a698cf5250c8993edf4d1b025fe54b1aa Mon Sep 17 00:00:00 2001 From: dmunozv04 <39565245+dmunozv04@users.noreply.github.com> Date: Sun, 15 Sep 2024 14:49:39 +0200 Subject: [PATCH 2/3] Fix occasional IndexError in loungeScreenDisconnected event --- src/iSponsorBlockTV/ytlounge.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/iSponsorBlockTV/ytlounge.py b/src/iSponsorBlockTV/ytlounge.py index ec1a900..90077bf 100644 --- a/src/iSponsorBlockTV/ytlounge.py +++ b/src/iSponsorBlockTV/ytlounge.py @@ -146,9 +146,10 @@ class YtLoungeApi(pyytlounge.YtLoungeApi): self.shorts_disconnected = False create_task(self.play_video(video_id_saved)) elif event_type == "loungeScreenDisconnected": - data = args[0] - if data["reason"] == "disconnectedByUserScreenInitiated": # Short playing? - self.shorts_disconnected = True + if args: # Sometimes it's empty + data = args[0] + if data["reason"] == "disconnectedByUserScreenInitiated": # Short playing? + self.shorts_disconnected = True elif event_type == "onAutoplayModeChanged": create_task(self.set_auto_play_mode(self.auto_play)) From 8cc3f8aa0590698b6bb702b93b00dbf766e0d99e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 15 Sep 2024 13:20:36 +0000 Subject: [PATCH 3/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/iSponsorBlockTV/ytlounge.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/iSponsorBlockTV/ytlounge.py b/src/iSponsorBlockTV/ytlounge.py index 90077bf..5f32eef 100644 --- a/src/iSponsorBlockTV/ytlounge.py +++ b/src/iSponsorBlockTV/ytlounge.py @@ -146,9 +146,11 @@ class YtLoungeApi(pyytlounge.YtLoungeApi): self.shorts_disconnected = False create_task(self.play_video(video_id_saved)) elif event_type == "loungeScreenDisconnected": - if args: # Sometimes it's empty + if args: # Sometimes it's empty data = args[0] - if data["reason"] == "disconnectedByUserScreenInitiated": # Short playing? + if ( + data["reason"] == "disconnectedByUserScreenInitiated" + ): # Short playing? self.shorts_disconnected = True elif event_type == "onAutoplayModeChanged": create_task(self.set_auto_play_mode(self.auto_play)) @@ -184,8 +186,8 @@ class YtLoungeApi(pyytlounge.YtLoungeApi): async def play_video(self, video_id: str) -> bool: return await self._command("setPlaylist", {"videoId": video_id}) - # Test to wrap the command function in a mutex to avoid race conditions with + # Test to wrap the command function in a mutex to avoid race conditions with # the _command_offset (TODO: move to upstream if it works) async def _command(self, command: str, command_parameters: dict = None) -> bool: async with self._command_mutex: - return await super()._command(command, command_parameters) \ No newline at end of file + return await super()._command(command, command_parameters)