mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 05:40:26 +02:00
feat: Implement existing item lookup and overwrite handling for Audiobookshelf uploads
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from abogen.web.conversion_runner import _build_output_path, _prepare_project_layout
|
||||
from abogen.web.service import Job
|
||||
|
||||
|
||||
def _sample_job(tmp_path: Path) -> Job:
|
||||
source = tmp_path / "sample.txt"
|
||||
source.write_text("example", encoding="utf-8")
|
||||
return Job(
|
||||
id="job-1",
|
||||
original_filename="Sample Title.txt",
|
||||
stored_path=source,
|
||||
language="en",
|
||||
voice="af_alloy",
|
||||
speed=1.0,
|
||||
use_gpu=False,
|
||||
subtitle_mode="Sentence",
|
||||
output_format="mp3",
|
||||
save_mode="Use default save location",
|
||||
output_folder=tmp_path,
|
||||
replace_single_newlines=False,
|
||||
subtitle_format="srt",
|
||||
created_at=time.time(),
|
||||
)
|
||||
|
||||
|
||||
def test_prepare_project_layout_uses_timestamped_folder(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
||||
job = _sample_job(tmp_path)
|
||||
monkeypatch.setattr(
|
||||
"abogen.web.conversion_runner._output_timestamp_token",
|
||||
lambda: "20250101-120000",
|
||||
)
|
||||
|
||||
project_root, audio_dir, subtitle_dir, metadata_dir = _prepare_project_layout(job, tmp_path)
|
||||
|
||||
assert project_root.name.startswith("20250101-120000_sample_title"), project_root.name
|
||||
assert audio_dir == project_root
|
||||
assert subtitle_dir == project_root
|
||||
assert metadata_dir is None
|
||||
|
||||
output_path = _build_output_path(audio_dir, job.original_filename, "mp3")
|
||||
assert output_path == project_root / "Sample Title.mp3"
|
||||
|
||||
|
||||
def test_prepare_project_layout_creates_project_subdirs(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> None:
|
||||
job = _sample_job(tmp_path)
|
||||
job.save_as_project = True
|
||||
monkeypatch.setattr(
|
||||
"abogen.web.conversion_runner._output_timestamp_token",
|
||||
lambda: "20250101-120500",
|
||||
)
|
||||
|
||||
project_root, audio_dir, subtitle_dir, metadata_dir = _prepare_project_layout(job, tmp_path)
|
||||
|
||||
assert audio_dir == project_root / "audio"
|
||||
assert subtitle_dir == project_root / "subtitles"
|
||||
assert metadata_dir == project_root / "metadata"
|
||||
assert audio_dir.is_dir()
|
||||
assert subtitle_dir.is_dir()
|
||||
assert metadata_dir is not None and metadata_dir.is_dir()
|
||||
|
||||
output_path = _build_output_path(audio_dir, job.original_filename, "wav")
|
||||
assert output_path == audio_dir / "Sample Title.wav"
|
||||
@@ -86,6 +86,16 @@ def test_simple_fractions_are_spoken() -> None:
|
||||
assert "one half" in normalized.lower()
|
||||
|
||||
|
||||
def test_plain_numbers_are_spelled_out() -> None:
|
||||
normalized = _normalize_for_pipeline("He rolled a 42.")
|
||||
assert "forty-two" in normalized.lower()
|
||||
|
||||
|
||||
def test_space_separated_numbers_become_ranges() -> None:
|
||||
normalized = _normalize_for_pipeline("Read pages 12 14 tonight.")
|
||||
assert "pages twelve to fourteen" in normalized.lower()
|
||||
|
||||
|
||||
def test_contractions_can_be_kept_when_override_disabled() -> None:
|
||||
normalized = _normalize_for_pipeline(
|
||||
"It's a good day.",
|
||||
|
||||
Reference in New Issue
Block a user