aboutsummaryrefslogtreecommitdiff
path: root/app/backends/audiocpp/catalog.py
diff options
context:
space:
mode:
authorhistoria <historiavg@proton.me>2026-09-01 14:32:05 -0400
committerhistoria <historiavg@proton.me>2026-09-01 14:32:05 -0400
commit6cfcd564c0684c52618235e6366f4a81c02b9a5b (patch)
tree55321760a8103bc6b5d79489fac4135a60e6e3ba /app/backends/audiocpp/catalog.py
parentdc6e7cd43029da62dabe2513fb5aa8a34df1bd6d (diff)
downloadtts-audiobook-generator-6cfcd564c0684c52618235e6366f4a81c02b9a5b.tar.gz
slop refactor/dedup
Diffstat (limited to 'app/backends/audiocpp/catalog.py')
-rw-r--r--app/backends/audiocpp/catalog.py16
1 files changed, 12 insertions, 4 deletions
diff --git a/app/backends/audiocpp/catalog.py b/app/backends/audiocpp/catalog.py
index 1048185..048e325 100644
--- a/app/backends/audiocpp/catalog.py
+++ b/app/backends/audiocpp/catalog.py
@@ -44,6 +44,8 @@ def request_options_families(audiocpp_dir: Path) -> Dict[str, dict]:
spec = json.loads(spec_path.read_text(encoding="utf-8"))
except (OSError, ValueError):
continue
+ if not isinstance(spec, dict):
+ continue
options = spec.get("options")
request = options.get("request") if isinstance(options, dict) else None
if not isinstance(request, list) or not request:
@@ -161,12 +163,12 @@ def _default_package(packages: List[dict]) -> Optional[dict]:
if not packages:
return None
for package in packages:
- if package.get("default"):
+ if isinstance(package, dict) and package.get("default"):
return package
for package in packages:
- if package.get("format") == "gguf":
+ if isinstance(package, dict) and package.get("format") == "gguf":
return package
- return packages[0]
+ return packages[0] if isinstance(packages[0], dict) else None
def spec_gguf_rooted(spec: dict) -> bool:
@@ -292,6 +294,11 @@ def load_model_catalog(audiocpp_dir: Path) -> List[dict]:
spec = json.loads(spec_path.read_text(encoding="utf-8"))
except (OSError, ValueError):
continue
+ if not isinstance(spec, dict):
+ # Valid JSON that is not an object (a list, a string, a
+ # number): skip it like an unparsable one instead of crashing
+ # the wizard on a half-written spec file.
+ continue
sanitize_model_spec(spec)
tasks = spec.get("tasks") or []
if tasks:
@@ -305,7 +312,8 @@ def load_model_catalog(audiocpp_dir: Path) -> List[dict]:
# No task list: fall back to the category as before.
continue
family = spec.get("family") or spec_path.stem
- packages = spec.get("packages") or []
+ packages = [package for package in (spec.get("packages") or [])
+ if isinstance(package, dict)]
package = _default_package(packages)
if package is None:
# No installable package: skip (cannot be hosted from a path).