feat(e-pub): Tilføj til CWA (.epub) og Send til Audiobookshelf (.m4b)
Claude-Session: https://claude.ai/code/session_01AUj1LSMmrowcomkn1ciAgj
This commit is contained in:
+15
-4
@@ -13,8 +13,8 @@ for f in ("run.sh", "run-audiobook.sh", "lib.sh"):
|
||||
(VAERKTOEJ / "fetch.sh").write_text(r'''#!/bin/bash
|
||||
echo "trin 1: $1" >&2
|
||||
case "$1" in
|
||||
ok-epub*) printf 'PK' > "$PWD/Min Bog.epub"; echo "Wrote $PWD/Min Bog.epub (2 B)" >&2 ;;
|
||||
ok-m4b) head -c 1000 /dev/zero > "$PWD/Lydbog æøå.m4b"; printf 'trin 2\rtrin 3\n' >&2; echo "Wrote $PWD/Lydbog æøå.m4b (1000 B)" >&2 ;;
|
||||
ok-epub*) sleep 1; printf 'PK' > "$PWD/Min Bog.epub"; echo "Wrote $PWD/Min Bog.epub (2 B)" >&2 ;;
|
||||
ok-m4b) head -c 1000 /dev/zero > "$PWD/Ane Forfatter - Lydbog æøå.m4b"; printf 'trin 2\rtrin 3\n' >&2; echo "Wrote $PWD/Ane Forfatter - Lydbog æøå.m4b (1000 B)" >&2 ;;
|
||||
env) env | sort >&2; [ -d "$TMP" ] && [ -z "$(ls -A)" ] && touch "$PWD/env.epub" ;;
|
||||
bad) exit 2 ;;
|
||||
gone) exit 3 ;;
|
||||
@@ -27,7 +27,10 @@ sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
|
||||
os.chdir(pathlib.Path(__file__).resolve().parents[1])
|
||||
import config # noqa: E402
|
||||
config.EPUB_SETTINGS_PATH.write_text(json.dumps({"tools_dir": str(VAERKTOEJ), "job_timeout_seconds": 3,
|
||||
"output_ttl_seconds": 4, "max_concurrent_jobs": 1}))
|
||||
"output_ttl_seconds": 4, "max_concurrent_jobs": 1,
|
||||
"cwa_ingest_dir": str(ROD / "cwa"), "abs_dir": str(ROD / "abs")}))
|
||||
(ROD / "cwa").mkdir()
|
||||
(ROD / "abs").mkdir()
|
||||
import main # noqa: E402
|
||||
import uvicorn # noqa: E402
|
||||
import httpx # noqa: E402
|
||||
@@ -71,6 +74,11 @@ b = c.post("/e-pub/start", data={"link": "ok-m4b"}).json()
|
||||
tjek("semafor: andet job venter i kø", c.get(f"/e-pub/status/{b['id']}").json()["tilstand"] == "koe")
|
||||
sa = vent(a["id"])
|
||||
tjek("epub færdig", sa["tilstand"] == "faerdig" and sa["filnavn"] == "Min Bog.epub")
|
||||
tjek("epub kan sendes til CWA", sa["kan_sende"] == "cwa")
|
||||
r = c.post(f"/e-pub/send/{a['id']}")
|
||||
tjek("sendt til CWA", r.status_code == 200 and r.json()["sendt"] == "CWA"
|
||||
and (ROD / "cwa" / "Min Bog.epub").read_bytes() == b"PK" and not list((ROD / "cwa").glob(".*")))
|
||||
tjek("ikke to gange", c.post(f"/e-pub/send/{a['id']}").status_code == 400)
|
||||
r = c.get(f"/e-pub/hent/{a['id']}")
|
||||
tjek("epub content-type", r.headers["content-type"] == "application/epub+zip" and r.content == b"PK")
|
||||
tjek("filnavn i Content-Disposition", "Min%20Bog.epub" in r.headers["content-disposition"] or "Min Bog.epub" in r.headers["content-disposition"])
|
||||
@@ -79,7 +87,10 @@ tjek("slettet efter hentning", c.get(f"/e-pub/status/{a['id']}").json()["tilstan
|
||||
and not (config.EPUB_SCRATCH / a["id"]).exists())
|
||||
tjek("anden hentning = 410", c.get(f"/e-pub/hent/{a['id']}").status_code == 410)
|
||||
sb = vent(b["id"])
|
||||
tjek("m4b færdig, \\r-linjer splittet", sb["filnavn"] == "Lydbog æøå.m4b" and "trin 3" in sb["log"])
|
||||
tjek("m4b færdig, \\r-linjer splittet", sb["filnavn"] == "Ane Forfatter - Lydbog æøå.m4b" and "trin 3" in sb["log"])
|
||||
r = c.post(f"/e-pub/send/{b['id']}")
|
||||
tjek("m4b til Audiobookshelf som Forfatter/Titel", r.json().get("sendt") == "Audiobookshelf"
|
||||
and (ROD / "abs" / "Ane Forfatter" / "Lydbog æøå" / "Ane Forfatter - Lydbog æøå.m4b").stat().st_size == 1000)
|
||||
tjek("m4b content-type", c.get(f"/e-pub/hent/{b['id']}").headers["content-type"] == "audio/mp4")
|
||||
|
||||
e = vent(c.post("/e-pub/start", data={"link": "env"}).json()["id"])
|
||||
|
||||
Reference in New Issue
Block a user