feat: p2v 연동
This commit is contained in:
1 parent
b3385e7df2
commit
5de5c7507d
26 files changed
+2944
-9
No files matched your search
@@ -158,9 +158,10 @@ class VideoListItem(BaseModel):
|
||||
# **`(type, video_id)` 쌍**으로 다뤄야 한다.
|
||||
# 특히 `DELETE /archive/videos/{id}` 는 `Video.id` 로 지우므로,
|
||||
# 썰박스 항목의 id 를 그대로 넘기면 **엉뚱한 ADO2 영상이 삭제된다.**
|
||||
type: Literal["video", "ssul"] = Field(
|
||||
type: Literal["video", "ssul", "p2v_video", "p2v_poster"] = Field(
|
||||
default="video",
|
||||
description="콘텐츠 종류 (video: ADO2 영상, ssul: 썰박스)",
|
||||
description="콘텐츠 종류 (video: ADO2 영상, ssul: 썰박스, "
|
||||
"p2v_video: 무빙 포스터, p2v_poster: 포스터 스타일링 — 이미지라 <img> 로 그릴 것)",
|
||||
)
|
||||
video_id: int = Field(..., description="콘텐츠 고유 ID (type 안에서만 유일)")
|
||||
store_name: Optional[str] = Field(None, description="업체명")
|
||||
@@ -193,13 +194,14 @@ class VideoThumbnailItem(BaseModel):
|
||||
# ⚠️ `video_id` 는 종류 안에서만 유일하다. `video.id` 와 `ssul_content.id` 가
|
||||
# **둘 다 1부터 시작**하므로 식별자는 반드시 `(type, video_id)` 쌍으로 다뤄야 한다.
|
||||
# 한 곳이라도 id 만 쓰면 다른 종류의 콘텐츠가 열린다.
|
||||
type: Literal["video", "ssul"] = Field(
|
||||
type: Literal["video", "ssul", "p2v_video", "p2v_poster"] = Field(
|
||||
default="video",
|
||||
description="콘텐츠 종류 (video: ADO2 영상, ssul: 썰박스). video_id 와 쌍으로 식별한다",
|
||||
description="콘텐츠 종류 (video: ADO2 영상, ssul: 썰박스, p2v_video: 무빙 포스터, "
|
||||
"p2v_poster: 포스터 스타일링 — 이미지라 <img> 로 그릴 것). video_id 와 쌍으로 식별한다",
|
||||
)
|
||||
video_id: int = Field(..., description="콘텐츠 고유 ID (type 안에서만 유일)")
|
||||
store_name: str = Field(..., description="업체명")
|
||||
result_movie_url: str = Field(..., description="영상 URL")
|
||||
store_name: str = Field(..., description="업체명 (P2V 는 행사명/포스터명)")
|
||||
result_movie_url: str = Field(..., description="영상 URL (p2v_poster 는 이미지 URL)")
|
||||
poster_url: Optional[str] = Field(None, description="영상 첫 프레임 포스터 이미지 URL (썸네일 표시용)")
|
||||
title: Optional[str] = Field(None, description="SNS 업로드 제목")
|
||||
description: Optional[str] = Field(None, description="SNS 업로드 설명")
|
||||
|
||||
@@ -27,7 +27,7 @@ from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from typing import Literal, Optional
|
||||
|
||||
from sqlalchemy import Select, func, literal, or_, select, union_all
|
||||
from sqlalchemy import Select, func, literal, null, or_, select, union_all
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.comment.models import Comment
|
||||
@@ -40,11 +40,18 @@ from app.database.like_cache import (
|
||||
mset_like_counts,
|
||||
)
|
||||
from app.home.models import Project
|
||||
from app.p2v.models import P2vF1Job, P2vF2Job
|
||||
from app.ssulbox.models import SsulContent
|
||||
from app.utils.address_parser import SIDO_CITIES, SIDO_SEARCH_ALIASES
|
||||
from app.video.models import Video, VideoReaction
|
||||
|
||||
ContentType = Literal["video", "ssul"]
|
||||
#: p2v_video(무빙 포스터 영상)·p2v_poster(스타일링 이미지). 내 콘텐츠와 갤러리
|
||||
#: 양쪽에 나오지만(2026-08-26 갤러리 합류) **좋아요·댓글 축은 없다** — enrich 는
|
||||
#: CT_VIDEO/CT_SSUL 만 돌아 0 으로 남고, 프론트도 P2V 카드에는 소셜 액션을 숨긴다.
|
||||
#: 갤러리의 F2 는 퍼블릭 도메인 템플릿 결과물만 나간다(fetch_gallery 참조).
|
||||
ContentType = Literal["video", "ssul", "p2v_video", "p2v_poster"]
|
||||
CT_P2V_VIDEO = "p2v_video"
|
||||
CT_P2V_POSTER = "p2v_poster"
|
||||
|
||||
#: 정렬 가능한 키. 그 외 값은 created_at 으로 떨어진다.
|
||||
SORT_CREATED = "created_at"
|
||||
@@ -228,6 +235,58 @@ def _ssul_branch(where: list, sort_by: str) -> Select:
|
||||
return select(*cols).where(*where)
|
||||
|
||||
|
||||
def _p2v_f1_branch(where: list, sort_by: str = SORT_CREATED) -> Select:
|
||||
"""무빙 포스터(F1) 브랜치.
|
||||
|
||||
통합 목록의 축과 P2V 필드 대응: store_name←행사명, region←장소,
|
||||
hashtags←키워드. P2V 에는 좋아요·댓글 축이 없으므로 해당 정렬에서는
|
||||
sort_value 0 으로 뒤에 깔린다 (UNION 컬럼 수 맞춤용).
|
||||
"""
|
||||
cols = [
|
||||
literal(CT_P2V_VIDEO).label("ctype"),
|
||||
P2vF1Job.id.label("cid"),
|
||||
func.coalesce(P2vF1Job.event_name, P2vF1Job.name).label("store_name"),
|
||||
P2vF1Job.place.label("region"),
|
||||
P2vF1Job.p2v_video_url.label("movie_url"),
|
||||
P2vF1Job.created_at.label("created_at"),
|
||||
literal("").label("task_id"),
|
||||
P2vF1Job.poster_url.label("poster_url"),
|
||||
P2vF1Job.name.label("title"),
|
||||
null().label("description"),
|
||||
P2vF1Job.keywords.label("hashtags"),
|
||||
]
|
||||
if sort_by in (SORT_LIKE, SORT_COMMENT):
|
||||
cols.append(literal(0).label("sort_value"))
|
||||
return select(*cols).where(*where)
|
||||
|
||||
|
||||
def _p2v_f2_branch(where: list, sort_by: str = SORT_CREATED) -> Select:
|
||||
"""포스터 스타일링(F2) 브랜치 — 결과물이 영상이 아니라 이미지다.
|
||||
|
||||
movie_url 자리에 결과 이미지 URL 을 싣는다. **프론트는 ctype 으로 분기해
|
||||
<img> 로 그려야 한다** (ssul/video 처럼 <video> 에 넣으면 안 나온다).
|
||||
"""
|
||||
cols = [
|
||||
literal(CT_P2V_POSTER).label("ctype"),
|
||||
P2vF2Job.id.label("cid"),
|
||||
# 카드 제목 = 포스터 이름(업로드 파일명). 이름이 없던 구버전 행만 템플릿명으로.
|
||||
func.coalesce(P2vF2Job.name, P2vF2Job.template_name, literal("포스터 스타일링")).label("store_name"),
|
||||
null().label("region"),
|
||||
P2vF2Job.p2v_poster_url.label("movie_url"),
|
||||
P2vF2Job.created_at.label("created_at"),
|
||||
literal("").label("task_id"),
|
||||
# 썸네일 = 결과물 자신 (별도 썸네일이 없다)
|
||||
P2vF2Job.p2v_poster_url.label("poster_url"),
|
||||
# 스타일 정보는 제목이 아니라 부가 정보 자리(title)에 남긴다
|
||||
P2vF2Job.template_name.label("title"),
|
||||
null().label("description"),
|
||||
null().label("hashtags"),
|
||||
]
|
||||
if sort_by in (SORT_LIKE, SORT_COMMENT):
|
||||
cols.append(literal(0).label("sort_value"))
|
||||
return select(*cols).where(*where)
|
||||
|
||||
|
||||
# ──────────────────────────────────────────────
|
||||
# 페이지 확정 후 집계
|
||||
# ──────────────────────────────────────────────
|
||||
@@ -359,6 +418,39 @@ async def fetch_gallery(
|
||||
v_where = _video_where(store_name, region)
|
||||
s_where = _ssul_where(store_name, region)
|
||||
|
||||
# ── P2V (2026-08-26 갤러리 합류) ──────────────────────────────
|
||||
# Blob 아카이브까지 끝난 완성본만. 검색어는 행사명/포스터명에 대응시킨다.
|
||||
f1_where = [
|
||||
P2vF1Job.status == "done",
|
||||
P2vF1Job.archived_at.is_not(None),
|
||||
P2vF1Job.p2v_video_url.is_not(None),
|
||||
]
|
||||
if store_name:
|
||||
f1_where.append(
|
||||
func.coalesce(P2vF1Job.event_name, P2vF1Job.name).ilike(f"%{store_name}%")
|
||||
)
|
||||
if region:
|
||||
# place 는 자유 텍스트 장소라 시/도 별칭 매칭(_region_clause)이 안 맞는다 —
|
||||
# 부분 일치로만 거른다.
|
||||
f1_where.append(P2vF1Job.place.ilike(f"%{region}%"))
|
||||
|
||||
# F2 공개 조건 셋: ① 설정 플래그(P2V_POSTER_IN_GALLERY — 임시 비노출 중),
|
||||
# ② 퍼블릭 도메인 템플릿으로 만든 것만(사용자 업로드 레퍼런스는 권리 미확인이라
|
||||
# 공개 금지 — 내 콘텐츠에는 나온다), ③ 지역 개념이 없어 지역 필터가 걸리면 빠진다.
|
||||
from config import p2v_settings
|
||||
|
||||
include_f2 = p2v_settings.P2V_POSTER_IN_GALLERY and region is None
|
||||
f2_where = [
|
||||
P2vF2Job.status == "done",
|
||||
P2vF2Job.archived_at.is_not(None),
|
||||
P2vF2Job.p2v_poster_url.is_not(None),
|
||||
P2vF2Job.license == "public-domain",
|
||||
]
|
||||
if store_name:
|
||||
f2_where.append(
|
||||
func.coalesce(P2vF2Job.name, P2vF2Job.template_name).ilike(f"%{store_name}%")
|
||||
)
|
||||
|
||||
# 전체 개수는 브랜치별로 센다 — UNION 을 만들어 세는 것보다 싸다.
|
||||
total = (
|
||||
await session.execute(
|
||||
@@ -373,10 +465,20 @@ async def fetch_gallery(
|
||||
select(func.count(SsulContent.id)).where(*s_where)
|
||||
)
|
||||
).scalar() or 0
|
||||
total += (
|
||||
await session.execute(select(func.count(P2vF1Job.id)).where(*f1_where))
|
||||
).scalar() or 0
|
||||
if include_f2:
|
||||
total += (
|
||||
await session.execute(select(func.count(P2vF2Job.id)).where(*f2_where))
|
||||
).scalar() or 0
|
||||
|
||||
branches = [_video_branch(v_where, sort_by)]
|
||||
if include_ssul:
|
||||
branches.append(_ssul_branch(s_where, sort_by))
|
||||
branches.append(_p2v_f1_branch(f1_where, sort_by))
|
||||
if include_f2:
|
||||
branches.append(_p2v_f2_branch(f2_where, sort_by))
|
||||
|
||||
u = union_all(*branches).subquery() if len(branches) > 1 else branches[0].subquery()
|
||||
|
||||
@@ -458,16 +560,36 @@ async def fetch_my_contents(
|
||||
SsulContent.is_deleted.is_(False),
|
||||
SsulContent.video_url.is_not(None),
|
||||
]
|
||||
# P2V — Blob 아카이브까지 끝난(URL 이 실재하는) 완성본만.
|
||||
# archiving 중이거나 실패한 잡은 P2V 진행 화면이 담당하므로 여기 안 나온다.
|
||||
f1_where = [
|
||||
P2vF1Job.user_uuid == user_uuid,
|
||||
P2vF1Job.status == "done",
|
||||
P2vF1Job.archived_at.is_not(None),
|
||||
P2vF1Job.p2v_video_url.is_not(None),
|
||||
]
|
||||
f2_where = [
|
||||
P2vF2Job.user_uuid == user_uuid,
|
||||
P2vF2Job.status == "done",
|
||||
P2vF2Job.archived_at.is_not(None),
|
||||
P2vF2Job.p2v_poster_url.is_not(None),
|
||||
]
|
||||
|
||||
total = ((await session.execute(
|
||||
select(func.count(Video.id)).where(*v_where)
|
||||
)).scalar() or 0) + ((await session.execute(
|
||||
select(func.count(SsulContent.id)).where(*s_where)
|
||||
)).scalar() or 0) + ((await session.execute(
|
||||
select(func.count(P2vF1Job.id)).where(*f1_where)
|
||||
)).scalar() or 0) + ((await session.execute(
|
||||
select(func.count(P2vF2Job.id)).where(*f2_where)
|
||||
)).scalar() or 0)
|
||||
|
||||
u = union_all(
|
||||
_video_branch(v_where, SORT_CREATED),
|
||||
_ssul_branch(s_where, SORT_CREATED),
|
||||
_p2v_f1_branch(f1_where),
|
||||
_p2v_f2_branch(f2_where),
|
||||
).subquery()
|
||||
|
||||
rows = (
|
||||
|
||||
Reference in new issue
Block a user