mirror of
https://github.com/dmunozv04/iSponsorBlockTV.git
synced 2025-12-06 20:06:44 +03:00
Send a no-op command after the watchdog is triggered
This commit is contained in:
@@ -31,6 +31,7 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
|
|||||||
self.logger = logger
|
self.logger = logger
|
||||||
self.shorts_disconnected = False
|
self.shorts_disconnected = False
|
||||||
self.auto_play = True
|
self.auto_play = True
|
||||||
|
self.noop_attempted = False # Track if we've already tried noop
|
||||||
if config:
|
if config:
|
||||||
self.mute_ads = config.mute_ads
|
self.mute_ads = config.mute_ads
|
||||||
self.skip_ads = config.skip_ads
|
self.skip_ads = config.skip_ads
|
||||||
@@ -42,8 +43,27 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
|
|||||||
await asyncio.sleep(
|
await asyncio.sleep(
|
||||||
35
|
35
|
||||||
) # YouTube sends at least a message every 30 seconds (no-op or any other)
|
) # YouTube sends at least a message every 30 seconds (no-op or any other)
|
||||||
|
|
||||||
|
if not self.noop_attempted:
|
||||||
|
# First time the watchdog is triggered, try sending a noop to keep connection alive
|
||||||
|
# YouTube responds with a LoungeStatus event after a noop if it is still connected
|
||||||
|
self.noop_attempted = True
|
||||||
|
self.logger.info("Watchdog triggered - sending noop command")
|
||||||
|
try:
|
||||||
|
await self.noop()
|
||||||
|
self.subscribe_task_watchdog = asyncio.create_task(self._watchdog())
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"Error sending noop command: {e}")
|
||||||
|
self._cancel_subscription()
|
||||||
|
else:
|
||||||
|
# If we already tried noop and the watchdog is triggered again, cancel subscription
|
||||||
|
self.logger.warning("Watchdog triggered again after noop attempt, cancelling subscription")
|
||||||
|
self._cancel_subscription()
|
||||||
|
|
||||||
|
def _cancel_subscription(self):
|
||||||
try:
|
try:
|
||||||
self.subscribe_task.cancel()
|
self.subscribe_task.cancel()
|
||||||
|
self.noop_attempted = False
|
||||||
except BaseException:
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -54,6 +74,8 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
|
|||||||
self.subscribe_task_watchdog.cancel()
|
self.subscribe_task_watchdog.cancel()
|
||||||
except BaseException:
|
except BaseException:
|
||||||
pass # No watchdog task
|
pass # No watchdog task
|
||||||
|
|
||||||
|
self.noop_attempted = False
|
||||||
self.subscribe_task = asyncio.create_task(super().subscribe(callback))
|
self.subscribe_task = asyncio.create_task(super().subscribe(callback))
|
||||||
self.subscribe_task_watchdog = asyncio.create_task(self._watchdog())
|
self.subscribe_task_watchdog = asyncio.create_task(self._watchdog())
|
||||||
return self.subscribe_task
|
return self.subscribe_task
|
||||||
@@ -61,13 +83,15 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
|
|||||||
# Process a lounge subscription event
|
# Process a lounge subscription event
|
||||||
def _process_event(self, event_type: str, args: List[Any]):
|
def _process_event(self, event_type: str, args: List[Any]):
|
||||||
self.logger.debug(f"process_event({event_type}, {args})")
|
self.logger.debug(f"process_event({event_type}, {args})")
|
||||||
# (Re)start the watchdog
|
# (Re)start the watchdog and reset noop attempt flag
|
||||||
try:
|
try:
|
||||||
self.subscribe_task_watchdog.cancel()
|
self.subscribe_task_watchdog.cancel()
|
||||||
except BaseException:
|
except BaseException:
|
||||||
pass
|
pass
|
||||||
finally:
|
finally:
|
||||||
|
self.noop_attempted = False
|
||||||
self.subscribe_task_watchdog = asyncio.create_task(self._watchdog())
|
self.subscribe_task_watchdog = asyncio.create_task(self._watchdog())
|
||||||
|
|
||||||
# A bunch of events useful to detect ads playing, and the next video before it starts playing (that way we
|
# A bunch of events useful to detect ads playing, and the next video before it starts playing (that way we
|
||||||
# can get the segments)
|
# can get the segments)
|
||||||
if event_type == "onStateChange":
|
if event_type == "onStateChange":
|
||||||
@@ -198,3 +222,7 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
|
|||||||
if self.conn is not None:
|
if self.conn is not None:
|
||||||
await self.conn.close()
|
await self.conn.close()
|
||||||
self.session = web_session
|
self.session = web_session
|
||||||
|
|
||||||
|
async def noop(self):
|
||||||
|
# No-op command to keep the connection alive
|
||||||
|
await super()._command("noop")
|
||||||
Reference in New Issue
Block a user