Skip to content

Commit a60f53b

Browse files
Paulluxclaude
andcommitted
Faster track change detection: poll every 2s, grace period before clearing presence
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent bc82a44 commit a60f53b

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

main.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,23 +183,27 @@ def emit_track(artist, title):
183183
last_track = None
184184
last_update_time = 0
185185
last_position_s = 0
186+
none_count = 0
186187
SYNC_INTERVAL = 15
187188
SEEK_TOLERANCE = 3
189+
NONE_GRACE = 3 # nombre de polls None consécutifs avant d'effacer
188190

189191
while True:
190192
info = await get_track_info()
191193

192194
if info is None:
193-
if last_log is not None:
195+
none_count += 1
196+
if last_log is not None and none_count >= NONE_GRACE:
194197
await clear_discord()
195198
last_log = None
196199
last_track = None
197200
last_update_time = 0
198201
emit_status('idle')
199202
emit_track('', '')
200-
else:
203+
elif last_log is None:
201204
print("Aucune session multimédia active.")
202205
else:
206+
none_count = 0
203207
title, artist, image_bytes, source_app, position_s, duration_s = info
204208
current_track = (title, artist, source_app)
205209
now = time.time()
@@ -225,7 +229,7 @@ def emit_track(artist, title):
225229
print(log)
226230
last_log = log
227231

228-
await asyncio.sleep(5)
232+
await asyncio.sleep(2)
229233

230234

231235
# ---------- Entrée ----------

0 commit comments

Comments
 (0)