projects include proper noun stuff

This commit is contained in:
2026-04-08 01:52:54 -06:00
parent 894144c84a
commit e9ddbb586a
2 changed files with 44 additions and 9 deletions

View File

@ -68,6 +68,8 @@ from PySide6.QtGui import *
class Project(NamedTuple):
name: str
source_paths: list[Path]
proper_nouns_output_dir: Path
proper_nouns_audio_dir: Path
def _project_slug(name: str) -> str:
return re.sub(r"[^a-zA-Z0-9_-]", "_", name).strip("_")[:60].lower()
@ -79,12 +81,29 @@ def load_projects() -> list[Project]:
projects = []
for item in data:
paths = [Path(p) for p in item["source_paths"]]
projects.append(Project(name=item["name"], source_paths=paths))
output_dir = Path(item["proper_nouns_output_dir"])
audio_dir = Path(item["proper_nouns_audio_dir"])
projects.append(
Project(
name=item["name"],
source_paths=paths,
proper_nouns_output_dir=output_dir,
proper_nouns_audio_dir=audio_dir,
)
)
return projects
return []
def save_projects(projects: list[Project]) -> None:
data = [{"name": p.name, "source_paths": [str(path) for path in p.source_paths]} for p in projects]
data = [
{
"name": p.name,
"source_paths": [str(path) for path in p.source_paths],
"proper_nouns_output_dir": str(p.proper_nouns_output_dir),
"proper_nouns_audio_dir": str(p.proper_nouns_audio_dir),
}
for p in projects
]
Path("projects.json").write_text(json.dumps(data, indent=2), encoding="utf-8")
VOICE = "am_michael"
@ -97,6 +116,8 @@ class BookSource(NamedTuple):
slug: str # Filesystem-safe identifier used for subdirectory names
source_paths: list # list[Path] — one or more source .txt files
fixed_out: Path # Where "Apply Fixes to Text" writes the TTS-ready copy
proper_nouns_output_dir: Path
proper_nouns_audio_dir: Path
def _book_slug(text: str) -> str:
@ -111,7 +132,9 @@ def load_books_from_projects() -> list[BookSource]:
slug = _project_slug(project.name)
fixed_out = Path(f"{project.name} (TTS Fixed).txt")
books.append(BookSource(label=project.name, slug=slug,
source_paths=project.source_paths, fixed_out=fixed_out))
source_paths=project.source_paths, fixed_out=fixed_out,
proper_nouns_output_dir=project.proper_nouns_output_dir,
proper_nouns_audio_dir=project.proper_nouns_audio_dir))
return books
# ── Colours ────────────────────────────────────────────────────────────────────
@ -368,11 +391,11 @@ class ProperNounAuditor(QMainWindow):
@property
def _data_dir(self) -> Path:
return Path("output_proper_nouns") / self.book.slug
return self.book.proper_nouns_output_dir
@property
def _audio_dir(self) -> Path:
return Path("proper_nouns_audio") / self.book.slug
return self.book.proper_nouns_audio_dir
@property
def _manifest_file(self) -> Path:
@ -434,7 +457,9 @@ class ProperNounAuditor(QMainWindow):
slug = _project_slug(project.name)
fixed_out = Path(f"{project.name} (TTS Fixed).txt")
book = BookSource(label=project.name, slug=slug,
source_paths=project.source_paths, fixed_out=fixed_out)
source_paths=project.source_paths, fixed_out=fixed_out,
proper_nouns_output_dir=project.proper_nouns_output_dir,
proper_nouns_audio_dir=project.proper_nouns_audio_dir)
self.books = [book]
self._load_book(book)
@ -449,7 +474,13 @@ class ProperNounAuditor(QMainWindow):
files, _ = QFileDialog.getOpenFileNames(self, "Select TXT files", "", "Text files (*.txt)")
if files:
paths = [Path(f) for f in files]
project = Project(name=name, source_paths=paths)
slug = _project_slug(name)
project = Project(
name=name,
source_paths=paths,
proper_nouns_output_dir=Path("output_proper_nouns") / slug,
proper_nouns_audio_dir=Path("proper_nouns_audio") / slug,
)
self.projects.append(project)
save_projects(self.projects)
# Update combobox values