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.")
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}")