Fix watchdog triggering too much

This commit is contained in:
dmunozv04
2025-07-04 19:14:08 +02:00
parent f2155abad3
commit 30cac71820

View File

@@ -1,6 +1,7 @@
import asyncio
import json
import sys
import time
from typing import Any, List
import pyytlounge
@@ -50,12 +51,12 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
it cancels the current subscription.
"""
self.watchdog_running = True
self.last_event_time = asyncio.get_event_loop().time()
self.last_event_time = time.time()
try:
while self.watchdog_running:
await asyncio.sleep(10)
current_time = asyncio.get_event_loop().time()
current_time = time.time()
time_since_last_event = current_time - self.last_event_time
# YouTube sends a message at least every 30 seconds
@@ -105,7 +106,7 @@ class YtLoungeApi(pyytlounge.YtLoungeApi):
def _process_event(self, event_type: str, args: List[Any]):
self.logger.debug(f"process_event({event_type}, {args})")
# Update last event time for the watchdog
self.last_event_time = asyncio.get_event_loop().time()
self.last_event_time = time.time()
# A bunch of events useful to detect ads playing,
# and the next video before it starts playing