From 6969e4d7cb7ed19a0fac07aa9deb09e7f177d01c Mon Sep 17 00:00:00 2001 From: Olivier 'reivilibre Date: Mon, 21 Nov 2022 12:57:12 +0000 Subject: [PATCH] Add no-op guard --- rei_toolbox/dubstrip.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rei_toolbox/dubstrip.py b/rei_toolbox/dubstrip.py index 3337deb..5fe4792 100644 --- a/rei_toolbox/dubstrip.py +++ b/rei_toolbox/dubstrip.py @@ -23,6 +23,15 @@ def has_audio_in_lang(meta: Dict[str, Any], lang: str) -> bool: return False +def has_audio_not_in_lang(meta: Dict[str, Any], lang: str) -> bool: + for stream in meta["streams"]: + if stream["codec_type"] == "audio": + if stream.get("tags", {}).get("language") != lang: + return True + + return False + + def make_dubstrip_command( file: Path, outfile: Path, meta: Dict[str, Any], keep_lang: str ) -> List[Union[str, Path]]: @@ -55,6 +64,10 @@ def main() -> None: print(f"no audio in {args.keep}: leaving untouched.") continue + if not has_audio_not_in_lang(meta, args.keep): + print(f"no audio not in {args.keep}: nothing to do.") + continue + outfile = file.parent.joinpath("dubstriptmp-" + file.name) cmd = make_dubstrip_command(file, outfile, meta, args.keep)