Add IMDb ID validation with regex pattern matching for tt followed by 7-8 digits
This commit is contained in:
+12
-1
@@ -2,6 +2,8 @@ import json
|
||||
import subprocess
|
||||
import typer
|
||||
from pathlib import Path
|
||||
import re
|
||||
import click
|
||||
|
||||
from models.streams import VideoFile, VideoStream, AudioStream, SubtitleStream, OriginalMediaType
|
||||
from movie_details import get_movie_details
|
||||
@@ -23,10 +25,19 @@ def parse_streams(stream_data: dict, VideoFile: VideoFile) -> VideoFile:
|
||||
return VideoFile
|
||||
|
||||
|
||||
def validate_imdb(ctx: click.Context, param: click.Parameter, value: str) -> str:
|
||||
"""Validate that an IMDb ID matches 'tt' followed by 7-8 digits."""
|
||||
if value is None:
|
||||
return value
|
||||
if not re.match(r"^tt\d{7,8}$", value):
|
||||
raise click.BadParameter("IMDb ID must be 'tt' followed by 7-8 digits (e.g. tt1234567)")
|
||||
return value
|
||||
|
||||
|
||||
@app.command()
|
||||
def main(
|
||||
filename: Path = typer.Argument(..., exists=True, help="Input video file"),
|
||||
imdb: str = typer.Option(None, "-i", "--imdb", help="IMDB ID"),
|
||||
imdb: str = typer.Option(None, "-i", "--imdb", callback=validate_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"),
|
||||
|
||||
Reference in New Issue
Block a user