From 7a667d8a5f69f1146ec9f60c83406f25bb3fcdac Mon Sep 17 00:00:00 2001 From: jaehwang Date: Wed, 9 Sep 2026 09:19:22 +0900 Subject: [PATCH] add archive --- backend/main.py | 3 +- backend/pipelines/gate.py | 12 +++-- backend/pipelines/playreel.py | 2 +- backend/routers/archive.py | 80 ++++++++++++++++++++++++++++++++ backend/services/compose_long.py | 34 ++++++++++++-- 5 files changed, 119 insertions(+), 12 deletions(-) create mode 100644 backend/routers/archive.py diff --git a/backend/main.py b/backend/main.py index b309031..b4a4b63 100644 --- a/backend/main.py +++ b/backend/main.py @@ -3,7 +3,7 @@ from contextlib import asynccontextmanager from fastapi import FastAPI from pipelines import worker -from routers import f1, playreel +from routers import archive, f1, playreel from utils import blob from utils.database import close_engine, create_missing_tables @@ -23,6 +23,7 @@ app = FastAPI(title="poster-alive", lifespan=lifespan) app.include_router(f1.router) app.include_router(playreel.router) +app.include_router(archive.router) @app.get("/api/health") diff --git a/backend/pipelines/gate.py b/backend/pipelines/gate.py index d823066..d1e9079 100644 --- a/backend/pipelines/gate.py +++ b/backend/pipelines/gate.py @@ -135,15 +135,16 @@ def clip_review(task: PlayreelTask) -> dict: def final_checks(task: PlayreelTask) -> list[dict]: - """컬럼으로 확인되는 것만 낸다 — 완성본을 다시 열어 본 결과가 아니다.""" - verdict = TitleGateVerdict.model_validate(task.title_gate or {"passed": True}) + """컬럼으로 확인되는 것만 낸다 — 완성본을 다시 열어 본 결과가 아니다. + + 제목 훼손 검사는 넣지 않는다. 비교 기준이 되는 좌표를 detect가 만드는데 + playreel에는 그 단계가 없어 검사 자체가 돌지 않는다. + """ plan = LongcutPlan.model_validate(task.scene_plan or {"scenes": []}) scroll_tags = {scene.tag for scene in plan.scenes if scene.kind == "scroll"} return [ {"key": "hybrid", "label": "원본 글자 합성", "ok": bool(task.hybrid_clip_url)}, - {"key": "title", "label": "제목 훼손 검사", - "ok": verdict.passed and not verdict.skip}, {"key": "scroll", "label": "상세페이지 스크롤", "ok": any(scene.kind == "scroll" for scene in plan.scenes)}, {"key": "schedule", "label": "캐스팅 스케줄 포함", @@ -156,7 +157,8 @@ def final_checks(task: PlayreelTask) -> list[dict]: def final_review(task: PlayreelTask) -> dict: return { "video_url": task.video_url or "", - "proof_url": task.compose_proof_url or task.hybrid_proof_url or "", + # hybrid 시트는 앞 8초짜리라 완성본 검수 자리에 대신 세우지 않는다 + "proof_url": task.compose_proof_url or "", "duration": task.video_duration or 0.0, "checks": final_checks(task), "version": task.version + 1, diff --git a/backend/pipelines/playreel.py b/backend/pipelines/playreel.py index b2b1256..f48759f 100644 --- a/backend/pipelines/playreel.py +++ b/backend/pipelines/playreel.py @@ -240,7 +240,7 @@ async def run_compose(session: AsyncSession, task: PlayreelTask) -> None: result = await asyncio.to_thread( compose_longcut, poster, clip, timeline, narration, sections, band_info(meta), - bgm_mp3=bgm, qr=Image.open(qr_path) if qr_path.exists() else None) + bgm_mp3=bgm, qr=Image.open(qr_path) if qr_path.exists() else None, preview=True) filename = f"{task.slug}_30_v{task.version + 1}.mp4" task.video_url = await store_bytes(PIPELINE, task.id, filename, result.video, diff --git a/backend/routers/archive.py b/backend/routers/archive.py new file mode 100644 index 0000000..594218a --- /dev/null +++ b/backend/routers/archive.py @@ -0,0 +1,80 @@ +"""/api/archive — 완료된 잡을 한 목록으로 보여준다 + +별도 저장소를 두지 않는다. 두 잡 테이블에서 끝난 것만 골라 그때그때 만든다. +필드는 web/lib/api.ts 의 ArchiveEntry 와 맞춘다. +""" +from fastapi import APIRouter, Depends, HTTPException +from sqlalchemy import select +from sqlalchemy.ext.asyncio import AsyncSession + +from models.nol import NolMeta +from pipelines.gate import period_text +from pipelines.runner import DONE +from routers.view import UNNAMED +from tables.task import PlayreelTask, PosterAliveTask +from utils.database import get_session + +router = APIRouter(prefix="/api/archive", tags=["archive"]) + + +def poster_alive_entry(task: PosterAliveTask) -> dict: + return { + "slug": task.id, + "kind": "f1", + "name": task.name or UNNAMED, + "source": None, + "metadata": task.poster_metadata, + "narration": task.narration_lines, + "poster_url": task.poster_url, + "video_url": task.video_url, + "thumbnail_url": task.thumbnail_url, + "version": None, + "credits_used": task.credits_used, + "f2_variants": [], + "created_at": task.created_at.timestamp(), + } + + +def playreel_entry(task: PlayreelTask) -> dict: + meta = NolMeta.model_validate(task.nol_meta) if task.nol_meta else None + return { + "slug": task.id, + "kind": "playreel", + "name": task.name or UNNAMED, + "source": {"url": task.source_url, "goods_id": task.goods_id, "slug": task.slug}, + "metadata": None if meta is None else { + "event_name": meta.goods_name or "", + "date_text": period_text(meta), + "place": meta.place_name or "", + "category": meta.genre_name or "", + "keywords": [], + }, + "narration": [line["text"] for line in task.narration_lines or []] or None, + "poster_url": task.upscaled_poster_url or task.poster_url, + "video_url": task.video_url, + "thumbnail_url": None, + "version": task.version, + "credits_used": task.credits_used, + "f2_variants": [], + "created_at": task.created_at.timestamp(), + } + + +@router.get("") +async def list_entries(session: AsyncSession = Depends(get_session)): + entries = [playreel_entry(task) for task in await session.scalars( + select(PlayreelTask).where(PlayreelTask.status == DONE))] + entries += [poster_alive_entry(task) for task in await session.scalars( + select(PosterAliveTask).where(PosterAliveTask.status == DONE))] + return sorted(entries, key=lambda entry: entry["created_at"], reverse=True) + + +@router.get("/{slug}") +async def get_entry(slug: str, session: AsyncSession = Depends(get_session)): + playreel = await session.get(PlayreelTask, slug) + if playreel is not None: + return playreel_entry(playreel) + poster_alive = await session.get(PosterAliveTask, slug) + if poster_alive is not None: + return poster_alive_entry(poster_alive) + raise HTTPException(404, "아카이브에 없는 항목입니다") diff --git a/backend/services/compose_long.py b/backend/services/compose_long.py index 3fef056..09b05b0 100644 --- a/backend/services/compose_long.py +++ b/backend/services/compose_long.py @@ -33,6 +33,10 @@ BGM_FADE_OUT = 1.2 # 큐 1초당 화면 높이의 몇 배를 훑을지. 원본은 사람이 구간을 골랐다(known_issue 참조). SCROLL_SCREENS_PER_SECOND = 0.35 +PROOF_COUNT = 8 # 완성본 전체에서 고르게 뽑는 시점 수 +PROOF_SIZE = (180, 320) +PROOF_GAP = 10 + BAND_HEIGHT = 300 BAND_RISE_SECONDS = 0.6 NOL_BLUE = (0x41, 0x54, 0xFF) @@ -246,11 +250,20 @@ def compose_frames(timeline: NarrationTimeline, plan: LongcutPlan, poster: Image yield image +def proof_sheet(tiles: list[Image.Image]) -> Image.Image: + width = (PROOF_SIZE[0] + PROOF_GAP) * len(tiles) - PROOF_GAP + sheet = Image.new("RGB", (width, PROOF_SIZE[1]), "black") + for order, tile in enumerate(tiles): + sheet.paste(tile, (order * (PROOF_SIZE[0] + PROOF_GAP), 0)) + return sheet + + def compose_longcut(poster: bytes | Path | Image.Image, clip: bytes, timeline: NarrationTimeline, narration_mp3: bytes, sections: Sequence[DetailSection], info: EndBandInfo, *, bgm_mp3: bytes | None = None, qr: Image.Image | None = None, - plan: LongcutPlan | None = None) -> LongcutResult: + plan: LongcutPlan | None = None, + preview: bool = False) -> LongcutResult: if isinstance(poster, Image.Image): source = poster.convert("RGB") else: @@ -261,8 +274,19 @@ def compose_longcut(poster: bytes | Path | Image.Image, clip: bytes, used = {scene.section for scene in plan.scenes if scene.section} images = {section.name: section.image for section in sections if section.name in used} - frames = compose_frames(timeline, plan, source, clip, images, info, qr) - video = encode_mp4(frames, (W, H), mix_audio(narration_mp3, bgm_mp3, timeline.total), + total_frames = round(timeline.total * FPS) + # 훅 구간만 보면 뒤쪽 스크롤과 엔드밴드를 검수할 수 없어 전체에서 고르게 뽑는다 + proof_at = {round(step * total_frames / PROOF_COUNT) for step in range(PROOF_COUNT)} + tiles: list[Image.Image] = [] + + def frames() -> Iterator[Image.Image]: + for index, frame in enumerate( + compose_frames(timeline, plan, source, clip, images, info, qr)): + if preview and index in proof_at: + tiles.append(frame.resize(PROOF_SIZE)) + yield frame + + video = encode_mp4(frames(), (W, H), mix_audio(narration_mp3, bgm_mp3, timeline.total), fps=FPS) - return LongcutResult(video=video, duration=timeline.total, - frames=round(timeline.total * FPS), plan=plan) + return LongcutResult(video=video, duration=timeline.total, frames=total_frames, + plan=plan, proof=proof_sheet(tiles) if tiles else None)