이미지 크롤링 로직 변경 및 자막 이미지 매칭 보완

This commit is contained in:
skkim committed 2026-07-03 11:46:32 +09:00
1 parent 04d8614919
commit 46449a7a3f
20 files changed
+1828 -1116

No files matched your search

+28 -33
View File
@@ -26,13 +26,12 @@ from app.dependencies.pagination import PaginationParams, get_pagination_params
from app.user.dependencies.auth import get_current_user, get_current_user_optional
from app.user.models import User
from app.utils.pagination import PaginatedResponse
from app.home.models import Image, Project, MarketingIntel, ImageTag
from app.home.models import Image, Project, MarketingIntel
from app.home.api.routers.v1.home import _extract_region_from_address
from app.utils.address_parser import SIDO_CITIES, SIDO_SEARCH_ALIASES
from app.lyric.models import Lyric
from app.song.models import Song, SongTimestamp
from app.utils.creatomate import CreatomateService
from app.utils.subtitles import SubtitleContentsGenerator
from app.comment.models import Comment
from app.database.like_cache import (
@@ -59,7 +58,7 @@ from app.video.schemas.video_schema import (
VideoThumbnailItem,
)
from app.video.worker.video_task import download_and_upload_video_to_blob
from app.video.services.video import get_image_tags_by_task_id
from config import creatomate_settings
@@ -199,16 +198,22 @@ async def generate_video(
)
marketing_intelligence: MarketingIntel = marketing_result.scalar_one_or_none()
# subtitle 미완료 시 즉시 반환 — Lyric/Song/Image 쿼리 전에 체크하여 불필요한 조회 방지
# 자막 + 이미지 배정 미완료 시 즉시 반환 — Lyric/Song/Image 쿼리 전에 체크하여 불필요한 조회 방지
# 클라이언트가 /lyric/subtitle/status/{task_id} 폴링 후 재시도
if not marketing_intelligence.subtitle:
logger.info(f"[generate_video] subtitle pending - task_id: {task_id}")
if not marketing_intelligence.subtitle or not marketing_intelligence.image_match:
pending_what = []
if not marketing_intelligence.subtitle:
pending_what.append("자막")
if not marketing_intelligence.image_match:
pending_what.append("이미지 배정")
pending_msg = ", ".join(pending_what)
logger.info(f"[generate_video] 사전 준비 미완료 ({pending_msg}) - task_id: {task_id}")
return GenerateVideoResponse(
success=False,
status="subtitle_pending",
task_id=task_id,
creatomate_render_id=None,
message="자막 생성이 아직 완료되지 않았습니다. /lyric/subtitle/status/{task_id}로 완료 확인 후 재요청하세요.",
message=f"{pending_msg} 생성이 아직 완료되지 않았습니다. /lyric/subtitle/status/{{task_id}}로 완료 확인 후 재요청하세요.",
error_message=None,
)
@@ -365,25 +370,15 @@ async def generate_video(
logger.debug(f"[generate_video] Template fetched - task_id: {task_id}")
# 6-2. elements에서 리소스 매핑 생성
# modifications = creatomate_service.elements_connect_resource_blackbox(
# elements=template["source"]["elements"],
# image_url_list=image_urls,
# music_url=music_url,
# address=store_address
taged_image_list = await get_image_tags_by_task_id(task_id)
min_image_num = creatomate_service.counting_component(
template = template,
target_template_type = "image"
)
duplicate = bool(len(taged_image_list) < min_image_num)
logger.info(f"[generate_video] Duplicate : {duplicate} | length of taged_image {len(taged_image_list)}, min_len {min_image_num},- task_id: {task_id}")
modifications = creatomate_service.template_matching_taged_image(
template = template,
taged_image_list = taged_image_list,
music_url = music_url,
address = store_address,
duplicate = duplicate,
)
# 이미지 배정은 /lyric/generate 사전 단계에서 이미 수행되어 marketing_intelligence.image_match에 저장됨.
# 여기서는 사전 산출물을 읽어 음악 URL과 주소만 보완한다.
modifications: dict = dict(marketing_intelligence.image_match) # 슬롯→image_url 사전 배정 결과
modifications["audio-music"] = music_url
# address_input 슬롯은 사전 단계에서도 채워지지만 영상 시점에 재확인
for key in list(modifications.keys()):
if "address_input" in key:
modifications[key] = store_address
logger.info(f"[generate_video] image_match loaded from DB (slots: {len(modifications)}) - task_id: {task_id}")
logger.debug(f"[generate_video] Modifications created - task_id: {task_id}")
subtitle_modifications = marketing_intelligence.subtitle
@@ -391,14 +386,14 @@ async def generate_video(
modifications.update(subtitle_modifications)
# revert thumbnail scene
# thumbnail_modifications = creatomate_service.make_thumbnail_modification(
# brand_name =brand_name,
# region = region,
# brand_concept = brand_concept,
# category_definition= category_definition,
# target_keywords=target_keywords)
thumbnail_modifications = creatomate_service.make_thumbnail_modification(
brand_name =brand_name,
region = region,
brand_concept = brand_concept,
category_definition= category_definition,
target_keywords=target_keywords)
# modifications.update(thumbnail_modifications)
modifications.update(thumbnail_modifications)
# 6-3. elements 수정
new_elements = creatomate_service.modify_element(