Simplify input format options

Simplified the competing options json and youtube into --from which can
then select format.
This commit is contained in:
Marty Oehme 2025-01-28 08:59:59 +01:00
parent 260c10b5cd
commit 423b83abb9
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -56,20 +56,20 @@ def grab_subtitles(url: str | Path) -> Path:
raise ValueError("No correct json3 transcript object found.") raise ValueError("No correct json3 transcript object found.")
INPUT_FORMATS = ["json3", "yt", "txt"]
@click.command() @click.command()
# TODO: Can I set it so it checks existence *only* when no youtube flag exists? # 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.argument("file_path", type=click.Path(exists=False))
@click.option( @click.option(
"--json-transcript/--no-json-transcript", "--from",
"-j", "-f",
default=False, "get_from",
help="Use downloaded json3 transcript.", type=click.Choice(INPUT_FORMATS),
) default="txt",
@click.option( help="Choose format to process between json transcript, yt link or txt file.",
"--youtube/--no-youtube",
"-t",
default=False,
help="Get (english) transcript from youtube link.",
) )
@click.option( @click.option(
"--prompt", "--prompt",
@ -77,6 +77,7 @@ def grab_subtitles(url: str | Path) -> Path:
default="Please summarize the following transcript:", default="Please summarize the following transcript:",
type=str, type=str,
help="Use custom prompt.", help="Use custom prompt.",
) )
@click.option( @click.option(
"--log-level", "--log-level",
@ -86,10 +87,9 @@ def grab_subtitles(url: str | Path) -> Path:
) )
def cli( def cli(
file_path: Path | str, file_path: Path | str,
json_transcript: bool,
youtube: bool,
prompt: str, prompt: str,
log_level: int, log_level: int,
get_from: str,
): ):
"""Provide summary for a file at the specified path or a youtube video at the specified url.""" """Provide summary for a file at the specified path or a youtube video at the specified url."""
@ -100,7 +100,7 @@ def cli(
content = "" content = ""
# youtube link, dl transcript # youtube link, dl transcript
if youtube: if get_from == "yt":
file_path = grab_subtitles(file_path) file_path = grab_subtitles(file_path)
file_path = cast(Path, file_path) file_path = cast(Path, file_path)
@ -109,7 +109,7 @@ def cli(
with Path(file_path).open() as f: with Path(file_path).open() as f:
content = f.read() content = f.read()
if json_transcript or youtube: if get_from == "json3" or get_from == "yt":
content = extract_transcript_contents(content) content = extract_transcript_contents(content)
dprint(f"content = {content}") dprint(f"content = {content}")