MCPcopy Create free account
hub / github.com/HelpFreedom/youthub / _controller_loop

Method _controller_loop

bridge_player.py:312–347  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

310 return False
311
312 def _controller_loop(self) -> None:
313 log = open(self.log_path, "a")
314 def cprint(m: str) -> None:
315 try: log.write(m + "\n"); log.flush()
316 except Exception: pass
317
318 self._ctrl_sock = self._connect_ipc()
319 if self._ctrl_sock is None:
320 cprint("[controller] could not connect to ffplay-yt IPC")
321 log.close()
322 return
323 cprint("[controller] connected")
324 if SIDEBAR_RECS:
325 self._start_sidebar_recs(cprint)
326 self._watchstats = WatchStats(
327 video_id=self.video_id,
328 get_pos_fn=lambda: self._last_pos_sec,
329 shutdown_event=self._shutdown,
330 log_fn=cprint,
331 )
332 self._watchstats.start()
333
334 buf = b""
335 try:
336 while not self._shutdown.is_set():
337 try: chunk = self._ctrl_sock.recv(4096)
338 except socket.timeout: continue
339 except Exception: break
340 if not chunk: break
341 buf += chunk
342 while b"\n" in buf:
343 line, buf = buf.split(b"\n", 1)
344 self._handle_event(line.decode("utf-8", "ignore").strip(), cprint)
345 finally:
346 cprint("[controller] exiting")
347 log.close()
348
349 def _handle_event(self, line: str, cprint) -> None:
350 if not line: return

Callers

nothing calls this directly

Calls 6

_connect_ipcMethod · 0.95
_start_sidebar_recsMethod · 0.95
_handle_eventMethod · 0.95
WatchStatsClass · 0.90
closeMethod · 0.45
startMethod · 0.45

Tested by

no test coverage detected