From 423b83abb9d32073d7862efd8bb480309c562b1d Mon Sep 17 00:00:00 2001 From: Marty Oehme <marty.oehme@gmail.com> Date: Tue, 28 Jan 2025 08:59:59 +0100 Subject: [PATCH] Simplify input format options Simplified the competing options json and youtube into --from which can then select format. --- summarize.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/summarize.py b/summarize.py index 9ae3a45..88f8621 100755 --- a/summarize.py +++ b/summarize.py @@ -56,20 +56,20 @@ def grab_subtitles(url: str | Path) -> Path: raise ValueError("No correct json3 transcript object found.") +INPUT_FORMATS = ["json3", "yt", "txt"] + + @click.command() # TODO: Can I set it so it checks existence *only* when no youtube flag exists? +# TODO: Implement some way to allow content passed in on stdin instead of file (- as arg?) @click.argument("file_path", type=click.Path(exists=False)) @click.option( - "--json-transcript/--no-json-transcript", - "-j", - default=False, - help="Use downloaded json3 transcript.", -) -@click.option( - "--youtube/--no-youtube", - "-t", - default=False, - help="Get (english) transcript from youtube link.", + "--from", + "-f", + "get_from", + type=click.Choice(INPUT_FORMATS), + default="txt", + help="Choose format to process between json transcript, yt link or txt file.", ) @click.option( "--prompt", @@ -77,6 +77,7 @@ def grab_subtitles(url: str | Path) -> Path: default="Please summarize the following transcript:", type=str, help="Use custom prompt.", + ) @click.option( "--log-level", @@ -86,10 +87,9 @@ def grab_subtitles(url: str | Path) -> Path: ) def cli( file_path: Path | str, - json_transcript: bool, - youtube: bool, prompt: str, log_level: int, + get_from: str, ): """Provide summary for a file at the specified path or a youtube video at the specified url.""" @@ -100,7 +100,7 @@ def cli( content = "" # youtube link, dl transcript - if youtube: + if get_from == "yt": file_path = grab_subtitles(file_path) file_path = cast(Path, file_path) @@ -109,7 +109,7 @@ def cli( with Path(file_path).open() as f: content = f.read() - if json_transcript or youtube: + if get_from == "json3" or get_from == "yt": content = extract_transcript_contents(content) dprint(f"content = {content}")