가사 템플릿 업데이트, 폰트 선택 기능 추가, 주소 injection업데이트

This commit is contained in:
dhlim committed 2026-02-04 10:28:47 +00:00
1 parent 9d92b5d42c
commit 32c6c210a0
3 files changed
+57 -17

No files matched your search

+45 -14
View File
@@ -122,7 +122,38 @@ text_template_v_2 = {
}
]
}
text_template_v_3 = {
"type": "composition",
"track": 3,
"elements": [
{
"type": "text",
"time": 0,
"x": "0%",
"y": "80%",
"width": "100%",
"height": "15%",
"x_anchor": "0%",
"y_anchor": "0%",
"x_alignment": "50%",
"y_alignment": "50%",
"font_family": "Noto Sans",
"font_weight": "700",
"font_size_maximum": "7 vmin",
"fill_color": "#ffffff",
"animations": [
{
"time": 0,
"duration": 1,
"easing": "quadratic-out",
"type": "text-wave",
"split": "line",
"overlap": "50%"
}
]
}
]
}
text_template_h_1 = {
"type": "composition",
"track": 3,
@@ -408,6 +439,7 @@ class CreatomateService:
image_url_list: list[str],
lyric: str,
music_url: str,
address: str = None
) -> dict:
"""템플릿 정보와 이미지/가사/음악 리소스를 매핑합니다.
@@ -434,9 +466,8 @@ class CreatomateService:
idx % len(image_url_list)
]
case "text":
modifications[template_component_name] = lyric_splited[
idx % len(lyric_splited)
]
if "address_input" in template_component_name:
modifications[template_component_name] = address
modifications["audio-music"] = music_url
@@ -448,12 +479,11 @@ class CreatomateService:
image_url_list: list[str],
lyric: str,
music_url: str,
address: str = None
) -> dict:
"""elements 정보와 이미지/가사/음악 리소스를 매핑합니다."""
template_component_data = self.parse_template_component_name(elements)
lyric = lyric.replace("\r", "")
lyric_splited = lyric.split("\n")
modifications = {}
for idx, (template_component_name, template_type) in enumerate(
@@ -465,9 +495,8 @@ class CreatomateService:
idx % len(image_url_list)
]
case "text":
modifications[template_component_name] = lyric_splited[
idx % len(lyric_splited)
]
if "address_input" in template_component_name:
modifications[template_component_name] = address
modifications["audio-music"] = music_url
@@ -486,7 +515,8 @@ class CreatomateService:
case "video":
element["source"] = modification[element["name"]]
case "text":
element["source"] = modification.get(element["name"], "")
#element["source"] = modification[element["name"]]
element["text"] = modification.get(element["name"], "")
case "composition":
for minor in element["elements"]:
recursive_modify(minor)
@@ -704,8 +734,8 @@ class CreatomateService:
def extend_template_duration(self, template: dict, target_duration: float) -> dict:
"""템플릿의 duration을 target_duration으로 확장합니다."""
target_duration += 0.1 # 수동으로 직접 변경 및 테스트 필요 : 파란박스 생기는것
template["duration"] = target_duration
template["duration"] = target_duration + 0.5 # 늘린것보단 짧게
target_duration += 1 # 수동으로 직접 변경 및 테스트 필요 : 파란박스 생기는것
total_template_duration = self.calc_scene_duration(template)
extend_rate = target_duration / total_template_duration
new_template = copy.deepcopy(template)
@@ -727,7 +757,7 @@ class CreatomateService:
return new_template
def lining_lyric(self, text_template: dict, lyric_index: int, lyric_text: str, start_sec: float, end_sec: float) -> dict:
def lining_lyric(self, text_template: dict, lyric_index: int, lyric_text: str, start_sec: float, end_sec: float, font_family: str = "Noto Sans") -> dict:
duration = end_sec - start_sec
text_scene = copy.deepcopy(text_template)
text_scene["name"] = f"Caption-{lyric_index}"
@@ -735,6 +765,7 @@ class CreatomateService:
text_scene["time"] = start_sec
text_scene["elements"][0]["name"] = f"lyric-{lyric_index}"
text_scene["elements"][0]["text"] = lyric_text
text_scene["elements"][0]["font_family"] = font_family
return text_scene
def auto_lyric(self, auto_text_template : dict):
@@ -744,7 +775,7 @@ class CreatomateService:
def get_text_template(self):
match self.orientation:
case "vertical":
return text_template_v_2
return text_template_v_3
case "horizontal":
return text_template_h_1