mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-10 05:56:46 +03:00
Merge pull request #191 from dmunozv04/add-mutex-command
Implements mutex when sending commands to YouTube
This commit is contained in:
@@ -35,6 +35,7 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
|
|||||||
self.mute_ads = config.mute_ads
|
self.mute_ads = config.mute_ads
|
||||||
self.skip_ads = config.skip_ads
|
self.skip_ads = config.skip_ads
|
||||||
self.auto_play = config.auto_play
|
self.auto_play = config.auto_play
|
||||||
|
self._command_mutex = asyncio.Lock()
|
||||||
|
|
||||||
# Ensures that we still are subscribed to the lounge
|
# Ensures that we still are subscribed to the lounge
|
||||||
async def _watchdog(self):
|
async def _watchdog(self):
|
||||||
@@ -145,8 +146,11 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
|
|||||||
self.shorts_disconnected = False
|
self.shorts_disconnected = False
|
||||||
create_task(self.play_video(video_id_saved))
|
create_task(self.play_video(video_id_saved))
|
||||||
elif event_type == "loungeScreenDisconnected":
|
elif event_type == "loungeScreenDisconnected":
|
||||||
|
if args: # Sometimes it's empty
|
||||||
data = args[0]
|
data = args[0]
|
||||||
if data["reason"] == "disconnectedByUserScreenInitiated": # Short playing?
|
if (
|
||||||
|
data["reason"] == "disconnectedByUserScreenInitiated"
|
||||||
|
): # Short playing?
|
||||||
self.shorts_disconnected = True
|
self.shorts_disconnected = True
|
||||||
elif event_type == "onAutoplayModeChanged":
|
elif event_type == "onAutoplayModeChanged":
|
||||||
create_task(self.set_auto_play_mode(self.auto_play))
|
create_task(self.set_auto_play_mode(self.auto_play))
|
||||||
@@ -181,3 +185,9 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
|
|||||||
|
|
||||||
async def play_video(self, video_id: str) -> bool:
|
async def play_video(self, video_id: str) -> bool:
|
||||||
return await self._command("setPlaylist", {"videoId": video_id})
|
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)
|
||||||
|
|||||||
Reference in New Issue
Block a user