이미지 크롤링 로직 변경 및 자막 이미지 매칭 보완
This commit is contained in:
1 parent
4d8462651a
commit
b8be2a355a
16 files changed
+212
-74
No files matched your search
+45
-9
@@ -895,6 +895,20 @@ class CreatomateService:
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
@staticmethod
|
||||
def _entrance_transition_offset(elem: dict) -> float:
|
||||
"""요소의 entrance transition(transition=true, time==0) duration 합을 반환합니다.
|
||||
|
||||
순차 배치 시 이 값만큼 이전 요소와 겹치도록 시작점이 앞당겨집니다.
|
||||
"""
|
||||
offset = 0.0
|
||||
for animation in elem.get("animations", []):
|
||||
if "reversed" in animation:
|
||||
continue
|
||||
if "transition" in animation and animation["transition"] and animation.get("time", 0) == 0:
|
||||
offset += animation["duration"]
|
||||
return offset
|
||||
|
||||
def calc_scene_duration(self, template: dict) -> float:
|
||||
"""템플릿의 전체 장면 duration을 계산합니다."""
|
||||
total_template_duration = 0.0
|
||||
@@ -908,15 +922,7 @@ class CreatomateService:
|
||||
if elem["track"] not in track_maximum_duration:
|
||||
continue
|
||||
if "time" not in elem or elem["time"] == 0: # elem is auto / 만약 마지막 elem이 auto인데 그 앞에 time이 있는 elem 일 시 버그 발생 확률 있음
|
||||
track_maximum_duration[elem["track"]] += elem["duration"]
|
||||
|
||||
if "animations" not in elem:
|
||||
continue
|
||||
for animation in elem["animations"]:
|
||||
if "reversed" in animation:
|
||||
continue
|
||||
if "transition" in animation and animation["transition"] and animation.get("time", 0) == 0:
|
||||
track_maximum_duration[elem["track"]] -= animation["duration"]
|
||||
track_maximum_duration[elem["track"]] += elem["duration"] - self._entrance_transition_offset(elem)
|
||||
else:
|
||||
track_maximum_duration[elem["track"]] = max(track_maximum_duration[elem["track"]], elem["time"] + elem["duration"])
|
||||
|
||||
@@ -928,6 +934,36 @@ class CreatomateService:
|
||||
|
||||
return total_template_duration
|
||||
|
||||
def calc_track_time_ranges(self, template: dict, track: int) -> list[tuple[str, float, float]]:
|
||||
"""최상위 요소 중 지정 track의 (name, start, end) 시간 범위를 계산합니다.
|
||||
|
||||
Creatomate 규칙에 따라 `time`이 없거나 0인 요소는 같은 트랙의 이전 요소 뒤에
|
||||
순차 배치되며, entrance transition duration만큼 이전 요소와 겹치도록
|
||||
시작점을 앞당깁니다(calc_scene_duration의 차감 규칙과 동치).
|
||||
`time`이 명시된 요소는 해당 시각에서 시작하고, 커서는 그 요소의 끝으로 이동합니다.
|
||||
"""
|
||||
ranges: list[tuple[str, float, float]] = []
|
||||
cursor = 0.0
|
||||
for elem in template["source"]["elements"]:
|
||||
try:
|
||||
if elem.get("track") != track:
|
||||
continue
|
||||
duration = elem["duration"]
|
||||
|
||||
if "time" not in elem or elem["time"] == 0: # 순차 배치(auto)
|
||||
start = max(0.0, cursor - self._entrance_transition_offset(elem))
|
||||
else:
|
||||
start = elem["time"]
|
||||
|
||||
end = start + duration
|
||||
cursor = end
|
||||
ranges.append((elem.get("name", ""), start, end))
|
||||
except Exception as e:
|
||||
logger.debug(traceback.format_exc())
|
||||
logger.error(f"[calc_track_time_ranges] Error processing element: {elem}, {e}")
|
||||
|
||||
return ranges
|
||||
|
||||
def extend_template_duration(self, template: dict, target_duration: float) -> dict:
|
||||
"""템플릿의 duration을 target_duration으로 확장합니다."""
|
||||
# template["duration"] = target_duration + 0.5 # 늘린것보단 짧게
|
||||
|
||||
Reference in new issue
Block a user