From c0363db98b64ef5e66ba433714bcde57c15b7f79 Mon Sep 17 00:00:00 2001 From: ewgsta <159681870+ewgsta@users.noreply.github.com> Date: Wed, 15 Apr 2026 18:16:26 +0300 Subject: [PATCH 1/5] perf(player): run stream validation concurrently for faster loading --- weeb_cli/commands/search/watch_flow.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/weeb_cli/commands/search/watch_flow.py b/weeb_cli/commands/search/watch_flow.py index 68bf3a4..76ea43f 100644 --- a/weeb_cli/commands/search/watch_flow.py +++ b/weeb_cli/commands/search/watch_flow.py @@ -177,11 +177,16 @@ def _play_episode(slug, selected_ep, details, season, episodes, completed_ids): if config.get("scraping_source") == "docchi": valid_streams = streams_list else: + from concurrent.futures import ThreadPoolExecutor console.print(f"[dim]{i18n.t('details.validating_streams')}...[/dim]") - for stream in streams_list: - is_valid, error = stream_validator.validate_url(stream.get("url"), timeout=3) - if is_valid: - valid_streams.append(stream) + + def check_stream(stream): + is_valid, _ = stream_validator.validate_url(stream.get("url"), timeout=3) + return stream if is_valid else None + + with ThreadPoolExecutor(max_workers=len(streams_list) if streams_list else 1) as executor: + results = executor.map(check_stream, streams_list) + valid_streams = [s for s in results if s is not None] if not valid_streams: console.print(f"[red]{i18n.t('details.no_valid_streams')}[/red]") From c82cf31e5d4d19c8ba1f448d368e5fe37df286c0 Mon Sep 17 00:00:00 2001 From: ewgsta <159681870+ewgsta@users.noreply.github.com> Date: Wed, 15 Apr 2026 18:17:06 +0300 Subject: [PATCH 2/5] refactor(player): extract stream fetching and validation to helper method --- weeb_cli/commands/search/watch_flow.py | 27 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/weeb_cli/commands/search/watch_flow.py b/weeb_cli/commands/search/watch_flow.py index 76ea43f..9d04e11 100644 --- a/weeb_cli/commands/search/watch_flow.py +++ b/weeb_cli/commands/search/watch_flow.py @@ -148,15 +148,7 @@ def _build_episode_choices(episodes, season, completed_ids, next_ep_num): return ep_choices -def _play_episode(slug, selected_ep, details, season, episodes, completed_ids): - ep_id = selected_ep.get("id") - ep_num = selected_ep.get("number") or selected_ep.get("ep_num") - - if not ep_id: - console.print(f"[red]{i18n.t('details.invalid_ep_id')}[/red]") - time.sleep(1) - return False - +def _fetch_and_validate_streams(slug, ep_id): with console.status(i18n.t("common.processing"), spinner="dots"): stream_resp = get_streams(slug, ep_id) @@ -168,7 +160,7 @@ def _play_episode(slug, selected_ep, details, season, episodes, completed_ids): error_msg += f" [{scraper.last_error}]" console.print(f"[red]{error_msg}[/red]") time.sleep(1.5) - return False + return None from weeb_cli.services.stream_validator import stream_validator from weeb_cli.config import config @@ -191,6 +183,21 @@ def check_stream(stream): if not valid_streams: console.print(f"[red]{i18n.t('details.no_valid_streams')}[/red]") time.sleep(1.5) + return None + + return valid_streams + +def _play_episode(slug, selected_ep, details, season, episodes, completed_ids): + ep_id = selected_ep.get("id") + ep_num = selected_ep.get("number") or selected_ep.get("ep_num") + + if not ep_id: + console.print(f"[red]{i18n.t('details.invalid_ep_id')}[/red]") + time.sleep(1) + return False + + valid_streams = _fetch_and_validate_streams(slug, ep_id) + if not valid_streams: return False streams_list = sort_streams(valid_streams) From c5774e87750db2648d13203ba5b42f4035082e7f Mon Sep 17 00:00:00 2001 From: ewgsta <159681870+ewgsta@users.noreply.github.com> Date: Wed, 15 Apr 2026 18:17:42 +0300 Subject: [PATCH 3/5] refactor(player): move dynamic imports to module level to reduce overhead --- weeb_cli/commands/search/watch_flow.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/weeb_cli/commands/search/watch_flow.py b/weeb_cli/commands/search/watch_flow.py index 9d04e11..4eefcb4 100644 --- a/weeb_cli/commands/search/watch_flow.py +++ b/weeb_cli/commands/search/watch_flow.py @@ -8,6 +8,9 @@ from weeb_cli.services.progress import progress_tracker from weeb_cli.services.scraper import scraper from weeb_cli.services.logger import error as log_error +from weeb_cli.services.stream_validator import stream_validator +from weeb_cli.config import config +from concurrent.futures import ThreadPoolExecutor from .episode_utils import get_episodes_safe, group_episodes_by_season, make_season_episode_id from .stream_utils import sort_streams, extract_streams_from_response @@ -162,14 +165,10 @@ def _fetch_and_validate_streams(slug, ep_id): time.sleep(1.5) return None - from weeb_cli.services.stream_validator import stream_validator - from weeb_cli.config import config - valid_streams = [] if config.get("scraping_source") == "docchi": valid_streams = streams_list else: - from concurrent.futures import ThreadPoolExecutor console.print(f"[dim]{i18n.t('details.validating_streams')}...[/dim]") def check_stream(stream): From 5e3fbc2615cd711fda45dee57d4ea1a042a64ab7 Mon Sep 17 00:00:00 2001 From: ewgsta <159681870+ewgsta@users.noreply.github.com> Date: Wed, 15 Apr 2026 18:18:37 +0300 Subject: [PATCH 4/5] perf(trackers): hoist tracker imports to top-level to speed up sync callbacks --- weeb_cli/commands/search/watch_flow.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/weeb_cli/commands/search/watch_flow.py b/weeb_cli/commands/search/watch_flow.py index 4eefcb4..025e95b 100644 --- a/weeb_cli/commands/search/watch_flow.py +++ b/weeb_cli/commands/search/watch_flow.py @@ -11,6 +11,7 @@ from weeb_cli.services.stream_validator import stream_validator from weeb_cli.config import config from concurrent.futures import ThreadPoolExecutor +from weeb_cli.services.tracker import anilist_tracker, mal_tracker, kitsu_tracker from .episode_utils import get_episodes_safe, group_episodes_by_season, make_season_episode_id from .stream_utils import sort_streams, extract_streams_from_response @@ -298,9 +299,6 @@ def _mark_episode_watched(slug, details, ep_num, season, episodes, completed_ids return False def _update_trackers(details, slug, ep_num=None): - from weeb_cli.services.tracker import anilist_tracker, mal_tracker, kitsu_tracker - from concurrent.futures import ThreadPoolExecutor - updated_prog = progress_tracker.get_anime_progress(slug) if ep_num is not None: From 9b1d03c8706d835da75117bf8f45a78c03d8225f Mon Sep 17 00:00:00 2001 From: ewgsta <159681870+ewgsta@users.noreply.github.com> Date: Wed, 15 Apr 2026 18:19:08 +0300 Subject: [PATCH 5/5] chore: completed planned performance refactors for watch_flow