번역오류 수정 및 CTA적용
This commit is contained in:
commit
788e76ef76
8 files changed
+216
-37
No files matched your search
+106
-11
@@ -273,6 +273,31 @@ AUDIO_TRACK = 2
|
||||
SUBTITLE_TRACK = 3
|
||||
KEYWORD_TRACK = 4
|
||||
|
||||
|
||||
def is_fixed_slot_name(name: str) -> bool:
|
||||
"""이름이 '-fixed'로 끝나는 요소인지 판별합니다.
|
||||
|
||||
템플릿 명명 규칙상 마지막 토큰이 'fixed'인 요소(예: 'brand-cta-bi_logo-
|
||||
factual-fixed', 'brand-cta-contact_phone-factual-fixed')는 회사 연락처
|
||||
문구·로고 등 매 영상마다 절대 바뀌면 안 되는 고정 콘텐츠다. 이런 요소는
|
||||
이미지 배정/자막 생성 대상에서 제외하고 템플릿에 이미 설정된 값을 그대로
|
||||
보존해야 한다.
|
||||
"""
|
||||
if not name:
|
||||
return False
|
||||
return name.rsplit("-", 1)[-1] == "fixed"
|
||||
|
||||
# 언어별 대체 폰트 (Google Fonts — Creatomate 기본 지원).
|
||||
# 템플릿 기본 폰트(GyeonggiTitleOTF/Pretendard)는 한글·라틴 전용이라 여기 있는
|
||||
# 언어는 렌더 직전 전체 텍스트 폰트를 교체한다. 매핑에 없는 언어(Korean,
|
||||
# English 등)는 템플릿 원본 폰트를 유지한다. 중국어는 간체(SC) 기준.
|
||||
LANGUAGE_FONT_MAP = {
|
||||
"Japanese": "Noto Sans JP",
|
||||
"Chinese": "Noto Sans SC",
|
||||
"Thai": "Noto Sans Thai",
|
||||
"Vietnamese": "Noto Sans",
|
||||
}
|
||||
|
||||
def select_template(
|
||||
orientation: OrientationType,
|
||||
industry: str | None = None,
|
||||
@@ -508,13 +533,23 @@ class CreatomateService:
|
||||
template : dict,
|
||||
target_template_type : str
|
||||
) -> list:
|
||||
"""target_template_type 요소 개수를 셉니다.
|
||||
|
||||
target_template_type이 "image"인 경우, 고정 자산('-fixed' 명명) 및
|
||||
5토큰 명명 규칙을 따르지 않는 요소(고정 워터마크 등)는 콘텐츠 슬롯이
|
||||
아니므로 카운트에서 제외합니다 (template_matching_taged_image의
|
||||
image_slots 필터링과 동일 기준).
|
||||
"""
|
||||
source_elements = template["source"]["elements"]
|
||||
template_component_data = self.parse_template_component_name(source_elements)
|
||||
count = 0
|
||||
|
||||
for _, (_, template_type) in enumerate(template_component_data.items()):
|
||||
if template_type == target_template_type:
|
||||
count += 1
|
||||
for name, template_type in template_component_data.items():
|
||||
if template_type != target_template_type:
|
||||
continue
|
||||
if target_template_type == "image" and (is_fixed_slot_name(name) or self.parse_slot_name_to_tag(name) is None):
|
||||
continue
|
||||
count += 1
|
||||
return count
|
||||
|
||||
def template_matching_taged_image(
|
||||
@@ -557,7 +592,14 @@ class CreatomateService:
|
||||
assigned: dict = {} # {슬롯명: image_tag} — 자막 컨텍스트용
|
||||
|
||||
# 이미지 슬롯과 텍스트 슬롯 분리
|
||||
image_slots = [name for name, t in template_component_data.items() if t == "image"]
|
||||
# 고정 자산(이름이 '-fixed'로 끝나는 로고 등) 및 5토큰 명명 규칙을 따르지
|
||||
# 않는 image 요소는 콘텐츠 슬롯이 아니므로 배정 대상에서 제외 — 그렇지
|
||||
# 않으면 파싱 실패로 0점 처리되어 "가장 까다로운 슬롯"으로 취급되고
|
||||
# 무작위 이미지로 덮어써진다.
|
||||
image_slots = [
|
||||
name for name, t in template_component_data.items()
|
||||
if t == "image" and not is_fixed_slot_name(name) and self.parse_slot_name_to_tag(name) is not None
|
||||
]
|
||||
text_slots = [(name, t) for name, t in template_component_data.items() if t == "text"]
|
||||
|
||||
if not pool:
|
||||
@@ -776,20 +818,26 @@ class CreatomateService:
|
||||
return modifications
|
||||
|
||||
def modify_element(self, elements: list, modification: dict) -> list:
|
||||
"""elements의 source를 modification에 따라 수정합니다."""
|
||||
"""elements의 source를 modification에 따라 수정합니다.
|
||||
|
||||
modification에 없는 image/text 요소(예: '-fixed' 명명의 고정 로고·
|
||||
연락처 문구처럼 배정/자막 생성 대상에서 제외된 고정 콘텐츠)는 템플릿에
|
||||
이미 설정된 source/text를 그대로 보존한다 (KeyError·빈 문자열로
|
||||
렌더가 깨지지 않도록).
|
||||
"""
|
||||
|
||||
def recursive_modify(element: dict) -> None:
|
||||
if "name" in element:
|
||||
match element["type"]:
|
||||
case "image":
|
||||
element["source"] = modification[element["name"]]
|
||||
element["source"] = modification.get(element["name"], element.get("source"))
|
||||
case "audio":
|
||||
element["source"] = modification.get(element["name"], "")
|
||||
case "video":
|
||||
element["source"] = modification[element["name"]]
|
||||
case "text":
|
||||
#element["source"] = modification[element["name"]]
|
||||
element["text"] = modification.get(element["name"], "")
|
||||
element["text"] = modification.get(element["name"], element.get("text", ""))
|
||||
case "composition":
|
||||
for minor in element["elements"]:
|
||||
recursive_modify(minor)
|
||||
@@ -1127,12 +1175,38 @@ class CreatomateService:
|
||||
case "horizontal":
|
||||
return autotext_template_h_1
|
||||
|
||||
def apply_language_font(self, template: dict, language: str) -> dict:
|
||||
"""출력 언어에 맞춰 템플릿 내 모든 텍스트 요소의 폰트를 교체합니다.
|
||||
|
||||
템플릿 기본 폰트(GyeonggiTitleOTF/Pretendard)는 한글·라틴 전용이라
|
||||
CJK/태국어 글리프가 없다. LANGUAGE_FONT_MAP에 있는 언어는 전체 텍스트
|
||||
폰트를 해당 언어 지원 폰트(Google Fonts)로 교체하고, 매핑에 없는
|
||||
언어(Korean, English 등)는 템플릿 원본 폰트를 유지한다.
|
||||
"""
|
||||
font_family = LANGUAGE_FONT_MAP.get(language)
|
||||
if not font_family:
|
||||
return template
|
||||
|
||||
def recursive_apply(element: dict) -> None:
|
||||
if element.get("type") == "text":
|
||||
element["font_family"] = font_family
|
||||
for minor in element.get("elements") or []:
|
||||
recursive_apply(minor)
|
||||
|
||||
for elem in template["source"]["elements"]:
|
||||
recursive_apply(elem)
|
||||
|
||||
logger.info(
|
||||
f"[apply_language_font] 텍스트 폰트 교체 완료 - language: {language}, font: {font_family}"
|
||||
)
|
||||
return template
|
||||
|
||||
def extract_text_format_from_template(self, template:dict):
|
||||
keyword_list = []
|
||||
subtitle_list = []
|
||||
for elem in template["source"]["elements"]:
|
||||
try: #최상위 내 텍스트만 검사
|
||||
if elem["type"] == "text":
|
||||
if elem["type"] == "text" and not is_fixed_slot_name(elem["name"]):
|
||||
if elem["track"] == SUBTITLE_TRACK:
|
||||
subtitle_list.append(elem["name"])
|
||||
elif elem["track"] == KEYWORD_TRACK:
|
||||
@@ -1146,20 +1220,41 @@ class CreatomateService:
|
||||
assert(len(keyword_list)==len(subtitle_list))
|
||||
except Exception as E:
|
||||
logger.error("this template does not have same amount of keyword and subtitle.")
|
||||
pitching_list = keyword_list + subtitle_list
|
||||
|
||||
# 썸네일 텍스트(thumb-*)는 전용 트랙이 아닌 thumbnail-composition 내부에
|
||||
# 중첩되어 있어 위 최상위 트랙 스캔에 잡히지 않는다. 다국어 자막 생성에
|
||||
# 함께 포함되도록 재귀 파싱으로 수집한다.
|
||||
component_data = self.parse_template_component_name(
|
||||
template["source"]["elements"]
|
||||
)
|
||||
thumbnail_list = [
|
||||
name
|
||||
for name, elem_type in component_data.items()
|
||||
if elem_type == "text" and name.startswith("thumb-")
|
||||
]
|
||||
|
||||
pitching_list = keyword_list + subtitle_list + thumbnail_list
|
||||
return pitching_list
|
||||
|
||||
|
||||
def make_thumbnail_modification(self, brand_name : str, region : str, category_definition : str, target_keywords : list[str]):
|
||||
def make_thumbnail_modification(self, brand_name : str, region : str, category_definition : str, target_keywords : list[str], detail_region_info : str = ""):
|
||||
|
||||
len_keywords = len(target_keywords) if len(target_keywords) < 3 else 3
|
||||
|
||||
hashtaged_target_keywords = [f"#{tk}" for tk in target_keywords[:len_keywords]]
|
||||
|
||||
# 지역 표기: 상세주소의 공백 기준 앞 두 마디 사용
|
||||
# (예: "전북 군산시 절골길 18" → "전북 군산시").
|
||||
# 상세주소가 없으면 기존 region 정규화 표기로 폴백.
|
||||
if detail_region_info and detail_region_info.strip():
|
||||
region_display = " ".join(detail_region_info.split()[:2])
|
||||
else:
|
||||
region_display = normalize_location(region)
|
||||
|
||||
mod_dict = {
|
||||
"thumb-hashtag-primary" : ' '.join(hashtaged_target_keywords),
|
||||
"thumb-headline-brand_name-factual" : brand_name,
|
||||
"thumb-subheadline-local_info-factual" : normalize_location(region),
|
||||
"thumb-subheadline-local_info-factual" : region_display,
|
||||
"thumb-badge-category" : category_definition,
|
||||
}
|
||||
return mod_dict
|
||||
Reference in new issue
Block a user