From af6e64ee0c01cf8bb263b5b7e705d63646243c36 Mon Sep 17 00:00:00 2001 From: Benexl Date: Tue, 29 Jul 2025 11:30:56 +0300 Subject: [PATCH] feat(anilist-download-command): add previews --- .../cli/commands/anilist/commands/download.py | 26 +++++++++++++++---- fastanime/libs/selectors/base.py | 3 --- fastanime/libs/selectors/fzf/selector.py | 2 +- 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/fastanime/cli/commands/anilist/commands/download.py b/fastanime/cli/commands/anilist/commands/download.py index d09e2ec..74b8a87 100644 --- a/fastanime/cli/commands/anilist/commands/download.py +++ b/fastanime/cli/commands/anilist/commands/download.py @@ -106,7 +106,7 @@ if TYPE_CHECKING: ) @click.option( "--yes", - "-y", + "-Y", is_flag=True, help="Automatically download from all found anime without prompting for selection.", ) @@ -191,10 +191,26 @@ def download(config: AppConfig, **options: "Unpack[DownloadOptions]"): (item.title.english or item.title.romaji or f"ID: {item.id}"): item for item in search_result.media } - selected_titles = selector.choose_multiple( - "Select anime to download (use TAB to select, ENTER to confirm)", - list(choice_map.keys()), - ) + preview_command = None + if config.general.preview != "none": + from ....utils.preview import create_preview_context + + with create_preview_context() as preview_ctx: + preview_command = preview_ctx.get_anime_preview( + list(choice_map.values()), + list(choice_map.keys()), + config, + ) + selected_titles = selector.choose_multiple( + "Select anime to download", + list(choice_map.keys()), + preview=preview_command, + ) + else: + selected_titles = selector.choose_multiple( + "Select anime to download", + list(choice_map.keys()), + ) if not selected_titles: feedback.warning("No anime selected. Aborting download.") return diff --git a/fastanime/libs/selectors/base.py b/fastanime/libs/selectors/base.py index 465fff5..ac5e0ec 100644 --- a/fastanime/libs/selectors/base.py +++ b/fastanime/libs/selectors/base.py @@ -35,9 +35,7 @@ class BaseSelector(ABC): self, prompt: str, choices: List[str], - *, preview: Optional[str] = None, - header: Optional[str] = None, ) -> List[str]: """ Prompts the user to choose multiple items from a list. @@ -61,7 +59,6 @@ class BaseSelector(ABC): f"{prompt} (Select multiple, empty to finish)", remaining_choices + ["[DONE] Finish selection"], preview=preview, - header=header, ) if not choice or choice == "[DONE] Finish selection": diff --git a/fastanime/libs/selectors/fzf/selector.py b/fastanime/libs/selectors/fzf/selector.py index 081dd55..2fd585f 100644 --- a/fastanime/libs/selectors/fzf/selector.py +++ b/fastanime/libs/selectors/fzf/selector.py @@ -53,7 +53,7 @@ class FzfSelector(BaseSelector): return None return result.stdout.strip() - def choose_multiple(self, prompt, choices, *, preview=None, header=None): + def choose_multiple(self, prompt, choices, preview=None): """Enhanced multi-selection using fzf's --multi flag.""" fzf_input = "\n".join(choices)