Commit 445461a363
Verified · cmc
Layout: unified · split
nfogen.py +8 −8
| @@ -96,7 +96,7 @@ def load_config(explicit: str | None) -> dict: | |||
| 96 | """Load defaults from a TOML or JSON file. Returns {} if none found.""" | 96 | """Load defaults from a TOML or JSON file. Returns {} if none found.""" |
| 97 | path = None | 97 | path = None |
| 98 | if explicit: | 98 | if explicit: |
| 99 | path = Path(explicit) # NOSONAR local CLI: the user's own path, no trust boundary | 99 | path = Path(explicit) |
| 100 | if not path.exists(): | 100 | if not path.exists(): |
| 101 | sys.exit(f"nfogen: config not found: {explicit}") | 101 | sys.exit(f"nfogen: config not found: {explicit}") |
| 102 | else: | 102 | else: |
| @@ -104,7 +104,7 @@ def load_config(explicit: str | None) -> dict: | |||
| 104 | if path is None: | 104 | if path is None: |
| 105 | return {} | 105 | return {} |
| 106 | 106 | ||
| 107 | text = path.read_text(encoding="utf-8") # NOSONAR local CLI: the user's own path | 107 | text = path.read_text(encoding="utf-8") |
| 108 | if path.suffix == ".json": | 108 | if path.suffix == ".json": |
| 109 | return json.loads(text) | 109 | return json.loads(text) |
| 110 | try: | 110 | try: |
| @@ -121,12 +121,12 @@ _MI_TYPE = "@type" # mediainfo track-type key | |||
| 121 | def load_mediainfo(path: str) -> dict: | 121 | def load_mediainfo(path: str) -> dict: |
| 122 | """Read a `mediainfo --Output=JSON` dump (or run mediainfo on a media file) | 122 | """Read a `mediainfo --Output=JSON` dump (or run mediainfo on a media file) |
| 123 | and return values for the video/audio/resolution/size/runtime/format keys.""" | 123 | and return values for the video/audio/resolution/size/runtime/format keys.""" |
| 124 | p = Path(path) # NOSONAR local CLI: the user's own path, no trust boundary | 124 | p = Path(path) |
| 125 | if p.suffix.lower() == ".json": | 125 | if p.suffix.lower() == ".json": |
| 126 | raw = p.read_text(encoding="utf-8") # NOSONAR local CLI: the user's own path | 126 | raw = p.read_text(encoding="utf-8") |
| 127 | else: | 127 | else: |
| 128 | try: | 128 | try: |
| 129 | proc = subprocess.run(["mediainfo", "--Output=JSON", str(p)], # NOSONAR local CLI: the user's own file | 129 | proc = subprocess.run(["mediainfo", "--Output=JSON", str(p)], |
| 130 | capture_output=True, text=True, check=True) | 130 | capture_output=True, text=True, check=True) |
| 131 | except FileNotFoundError: | 131 | except FileNotFoundError: |
| 132 | sys.exit("nfogen: mediainfo not installed; pass a JSON dump to --mediainfo") | 132 | sys.exit("nfogen: mediainfo not installed; pass a JSON dump to --mediainfo") |
| @@ -633,7 +633,7 @@ def _resolve_logo(args, config: dict, group: str) -> str | None: | |||
| 633 | if logo_path: | 633 | if logo_path: |
| 634 | enc = args.logo_encoding or config.get("logo_encoding") or "cp437" | 634 | enc = args.logo_encoding or config.get("logo_encoding") or "cp437" |
| 635 | try: | 635 | try: |
| 636 | return Path(logo_path).read_text(encoding=enc, errors="replace") # NOSONAR local CLI: the user's own path | 636 | return Path(logo_path).read_text(encoding=enc, errors="replace") |
| 637 | except FileNotFoundError: | 637 | except FileNotFoundError: |
| 638 | sys.exit(f"nfogen: logo not found: {logo_path}") | 638 | sys.exit(f"nfogen: logo not found: {logo_path}") |
| 639 | if _resolve(args.banner, config, "banner", False): | 639 | if _resolve(args.banner, config, "banner", False): |
| @@ -666,11 +666,11 @@ def _write_output(text: str, args) -> None: | |||
| 666 | if args.encoding == "cp437": | 666 | if args.encoding == "cp437": |
| 667 | raw = text.encode("cp437", errors="replace") | 667 | raw = text.encode("cp437", errors="replace") |
| 668 | if args.output: | 668 | if args.output: |
| 669 | Path(args.output).write_bytes(raw) # NOSONAR local CLI: the user's own path | 669 | Path(args.output).write_bytes(raw) |
| 670 | else: | 670 | else: |
| 671 | sys.stdout.buffer.write(raw) | 671 | sys.stdout.buffer.write(raw) |
| 672 | elif args.output: | 672 | elif args.output: |
| 673 | Path(args.output).write_text(text, encoding="utf-8") # NOSONAR local CLI: the user's own path | 673 | Path(args.output).write_text(text, encoding="utf-8") |
| 674 | else: | 674 | else: |
| 675 | sys.stdout.write(text) | 675 | sys.stdout.write(text) |
| 676 | 676 | ||