Replace Click with Typer for improved CLI argument handling

This commit is contained in:
Esa Kataja
2025-04-17 12:36:31 +03:00
parent 55cd3e7ec0
commit a30791a036
3 changed files with 41 additions and 13 deletions
+12 -12
View File
@@ -1,13 +1,13 @@
import json
import subprocess
import click
import typer
from pathlib import Path
# from rich import print
from models.streams import VideoFile, VideoStream, AudioStream, SubtitleStream
from movie_details import get_movie_details
from lib.fs import write_shell_script
app = typer.Typer()
def parse_streams(stream_data: dict, VideoFile: VideoFile) -> VideoFile:
for stream in stream_data["streams"]:
@@ -23,15 +23,15 @@ def parse_streams(stream_data: dict, VideoFile: VideoFile) -> VideoFile:
return VideoFile
@click.command()
@click.argument("filename", type=click.Path(exists=True))
@click.option("-i", "--imdb", type=str, help="IMDB ID")
@click.option("-ns", "--nosubtitles", is_flag=True, help="No subtitles")
@click.option("-p", "--preset", type=int, default=2, help="Encoding preset (default: 2)")
@click.option("-c", "--crf", type=int, default=30, help="CRF value (default: 30)")
@click.option('-o', '--original-media-type', default='DVD', help='Set the ORIGINAL_MEDIA_TYPE metadata')
def main(filename: Path, imdb: str, nosubtitles: bool, preset: int, crf: int, original_media_type: str):
"""Run ffprobe on a file and print the output in JSON format."""
@app.command()
def main(
filename: Path = typer.Argument(..., exists=True, help="Input video file"),
imdb: str = typer.Option(None, "-i", "--imdb", help="IMDB ID"),
nosubtitles: bool = typer.Option(False, "-ns", "--nosubtitles", help="Remove subtitles"),
preset: int = typer.Option(2, "-p", "--preset", help="Encoding preset"),
crf: int = typer.Option(30, "-c", "--crf", help="CRF value"),
original_media_type: str = typer.Option("DVD", "-o", "--original-media-type", help="Set the ORIGINAL_MEDIA_TYPE metadata")
):
video_details = VideoFile(
imdb=imdb, video_path=filename, allow_subtitle=not nosubtitles
)
@@ -62,4 +62,4 @@ def main(filename: Path, imdb: str, nosubtitles: bool, preset: int, crf: int, or
if __name__ == "__main__":
main()
app()