feat: p2v_video SNS SEO 생성·저장 서비스 추가
This commit is contained in:
1 parent
1b700bd1bb
commit
ccf80b2cbf
1 file changed
+83
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
ADO2 영상은 제목/설명/해시태그를 video 테이블에 저장합니다.
|
ADO2 영상은 제목/설명/해시태그를 video 테이블에 저장합니다.
|
||||||
썰박스는 별도 프롬프트로 생성합니다.
|
썰박스는 별도 프롬프트로 생성합니다.
|
||||||
|
P2V 무빙 포스터는 시트 p2v_upload 프롬프트로 생성합니다.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import json
|
import json
|
||||||
@@ -14,6 +15,8 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
|||||||
|
|
||||||
from app.home.models import MarketingIntel, Project
|
from app.home.models import MarketingIntel, Project
|
||||||
from app.social.schemas import YoutubeDescriptionResponse
|
from app.social.schemas import YoutubeDescriptionResponse
|
||||||
|
from app.p2v.models import PosterAliveTask
|
||||||
|
from app.p2v.services.seo_input import build_seo_input, clamp_title
|
||||||
from app.social.services.sns_metadata import apply_sns_metadata, has_stored_sns_metadata
|
from app.social.services.sns_metadata import apply_sns_metadata, has_stored_sns_metadata
|
||||||
from app.ssulbox.models import SsulContent
|
from app.ssulbox.models import SsulContent
|
||||||
from app.user.models import User
|
from app.user.models import User
|
||||||
@@ -150,6 +153,86 @@ class SeoService:
|
|||||||
keywords=out.keywords,
|
keywords=out.keywords,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def get_p2v_seo(
|
||||||
|
self,
|
||||||
|
content_id: int,
|
||||||
|
current_user: User,
|
||||||
|
session: AsyncSession,
|
||||||
|
) -> YoutubeDescriptionResponse:
|
||||||
|
"""P2V 무빙 포스터용 SEO 생성 — 시트 p2v_upload 프롬프트를 쓴다."""
|
||||||
|
row = (
|
||||||
|
await session.execute(
|
||||||
|
select(PosterAliveTask).where(
|
||||||
|
PosterAliveTask.id == content_id,
|
||||||
|
PosterAliveTask.user_id == current_user.user_uuid,
|
||||||
|
PosterAliveTask.is_deleted.is_(False),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).scalar_one_or_none()
|
||||||
|
if row is None:
|
||||||
|
raise HTTPException(status_code=404, detail="콘텐츠를 찾을 수 없습니다.")
|
||||||
|
|
||||||
|
if has_stored_sns_metadata(row):
|
||||||
|
return self._response_from_row(row)
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = await self.generate_and_save_for_p2v(content_id, session)
|
||||||
|
except ValueError as e:
|
||||||
|
# 포스터 분석(poster_metadata)이 아직 없다 — GPT 를 부르기 전에 막는다
|
||||||
|
raise HTTPException(status_code=409, detail=str(e))
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"[SEO_SERVICE] P2V EXCEPTION - error: {e}")
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=500,
|
||||||
|
detail=f"P2V SEO 생성에 실패했습니다. : {str(e)}",
|
||||||
|
)
|
||||||
|
if result is None:
|
||||||
|
raise HTTPException(status_code=404, detail="콘텐츠를 찾을 수 없습니다.")
|
||||||
|
await session.commit()
|
||||||
|
return result
|
||||||
|
|
||||||
|
async def generate_and_save_for_p2v(
|
||||||
|
self,
|
||||||
|
content_id: int,
|
||||||
|
session: AsyncSession,
|
||||||
|
) -> YoutubeDescriptionResponse | None:
|
||||||
|
"""GPT로 P2V SNS 메타데이터를 생성해 저장합니다 (제목은 100자로 자름)."""
|
||||||
|
row = await session.get(PosterAliveTask, content_id)
|
||||||
|
if row is None:
|
||||||
|
logger.warning(f"[SEO_SERVICE] p2v_video NOT FOUND - id: {content_id}")
|
||||||
|
return None
|
||||||
|
|
||||||
|
if has_stored_sns_metadata(row):
|
||||||
|
return self._response_from_row(row)
|
||||||
|
|
||||||
|
result = await self._generate_p2v_seo_description(row)
|
||||||
|
title = clamp_title(result.title)
|
||||||
|
apply_sns_metadata(row, title, result.description, result.keywords)
|
||||||
|
await session.flush()
|
||||||
|
logger.info(f"[SEO_SERVICE] Saved p2v metadata - id: {content_id}")
|
||||||
|
return YoutubeDescriptionResponse(
|
||||||
|
title=title, description=result.description, keywords=result.keywords
|
||||||
|
)
|
||||||
|
|
||||||
|
async def _generate_p2v_seo_description(
|
||||||
|
self,
|
||||||
|
row: PosterAliveTask,
|
||||||
|
) -> YoutubeDescriptionResponse:
|
||||||
|
"""p2v_upload 프롬프트로 제목/설명/해시태그를 생성합니다."""
|
||||||
|
from app.utils.prompts.chatgpt_prompt import ChatgptService
|
||||||
|
from app.utils.prompts.prompts import get_p2v_upload_prompt
|
||||||
|
|
||||||
|
input_data = build_seo_input(row) # event_name 없으면 ValueError (GPT 호출 전)
|
||||||
|
chatgpt = ChatgptService(timeout=180)
|
||||||
|
out = await chatgpt.generate_structured_output(get_p2v_upload_prompt(), input_data)
|
||||||
|
return YoutubeDescriptionResponse(
|
||||||
|
title=out.title,
|
||||||
|
description=out.description,
|
||||||
|
keywords=out.keywords,
|
||||||
|
)
|
||||||
|
|
||||||
async def generate_and_save_for_video(
|
async def generate_and_save_for_video(
|
||||||
self,
|
self,
|
||||||
video_id: int,
|
video_id: int,
|
||||||
|
|||||||
Reference in new issue
Block a user