Commit 445461a363
Verified · cmc
Layout: unified · split
nfogen.py +8 −8
| @@ -96,7 +96,7 @@ def load_config(explicit: str | None) -> dict: | ||
| 96 | 96 | """Load defaults from a TOML or JSON file. Returns {} if none found.""" |
| 97 | 97 | path = None |
| 98 | 98 | if explicit: |
| 99 | path = Path(explicit) # NOSONAR local CLI: the user's own path, no trust boundary | |
| 99 | path = Path(explicit) | |
| 100 | 100 | if not path.exists(): |
| 101 | 101 | sys.exit(f"nfogen: config not found: {explicit}") |
| 102 | 102 | else: |
| @@ -104,7 +104,7 @@ def load_config(explicit: str | None) -> dict: | ||
| 104 | 104 | if path is None: |
| 105 | 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 | 108 | if path.suffix == ".json": |
| 109 | 109 | return json.loads(text) |
| 110 | 110 | try: |
| @@ -121,12 +121,12 @@ _MI_TYPE = "@type" # mediainfo track-type key | ||
| 121 | 121 | def load_mediainfo(path: str) -> dict: |
| 122 | 122 | """Read a `mediainfo --Output=JSON` dump (or run mediainfo on a media file) |
| 123 | 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 | 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 | 127 | else: |
| 128 | 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 | 130 | capture_output=True, text=True, check=True) |
| 131 | 131 | except FileNotFoundError: |
| 132 | 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 | 633 | if logo_path: |
| 634 | 634 | enc = args.logo_encoding or config.get("logo_encoding") or "cp437" |
| 635 | 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 | 637 | except FileNotFoundError: |
| 638 | 638 | sys.exit(f"nfogen: logo not found: {logo_path}") |
| 639 | 639 | if _resolve(args.banner, config, "banner", False): |
| @@ -666,11 +666,11 @@ def _write_output(text: str, args) -> None: | ||
| 666 | 666 | if args.encoding == "cp437": |
| 667 | 667 | raw = text.encode("cp437", errors="replace") |
| 668 | 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 | 670 | else: |
| 671 | 671 | sys.stdout.buffer.write(raw) |
| 672 | 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 | 674 | else: |
| 675 | 675 | sys.stdout.write(text) |
| 676 | 676 | |