From ef830f5d21ccaf717df684f0d05d7beb1e38fd59 Mon Sep 17 00:00:00 2001 From: ewgsta <159681870+ewgsta@users.noreply.github.com> Date: Tue, 17 Mar 2026 01:35:49 +0300 Subject: [PATCH] resolve single source loop and mpv hang issues (closes #16, closes #17) --- weeb_cli/commands/search/watch_flow.py | 6 +++--- weeb_cli/services/player.py | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/weeb_cli/commands/search/watch_flow.py b/weeb_cli/commands/search/watch_flow.py index 9cbb391..dd3cd07 100644 --- a/weeb_cli/commands/search/watch_flow.py +++ b/weeb_cli/commands/search/watch_flow.py @@ -243,9 +243,6 @@ def on_watched_callback(): return play_success def _select_stream(streams_list): - if len(streams_list) == 1: - return streams_list[0] - stream_choices = [] for s in streams_list: server = s.get("server", "Unknown") @@ -253,6 +250,9 @@ def _select_stream(streams_list): label = f"{server} ({quality})" stream_choices.append(questionary.Choice(label, value=s)) + if not stream_choices: + return None + return questionary.select( i18n.t("details.select_source"), choices=stream_choices, diff --git a/weeb_cli/services/player.py b/weeb_cli/services/player.py index ac6737f..ed8a336 100644 --- a/weeb_cli/services/player.py +++ b/weeb_cli/services/player.py @@ -201,16 +201,26 @@ def play(self, url: str, title: Optional[str] = None, start_time: Optional[int] ) self._monitor_thread.start() - result = subprocess.run(cmd, capture_output=True, text=True) + # Using Popen for more flexible process management, similar to doccli + process = subprocess.Popen( + cmd, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + stdin=subprocess.DEVNULL, + shell=False + ) + + # Wait for the process to exit + exit_code = process.wait() if self._monitor_thread: self._stop_monitor.set() self._monitor_thread.join(timeout=1) - if result.returncode != 0: - log_debug(f"[Player] MPV Error (Code {result.returncode}): {result.stderr.strip()}") - console.print(f"[red]{i18n.t('player.error')}[/red]") - return result.returncode == 0 + if exit_code != 0: + log_debug(f"[Player] MPV exited with code: {exit_code}") + # Don't show error if exit_code is 0 (normal exit) + return exit_code == 0 except FileNotFoundError as e: handle_error(e, "Player:MPV", f"{i18n.t('player.error')}: MPV not found at {self.mpv_path}") return False