Skip to content

Commit

Permalink
Merge pull request #13 from klementng/dev
Browse files Browse the repository at this point in the history
Fix postprocessing of position tags + update dependencies
  • Loading branch information
klementng authored Jul 17, 2024
2 parents c079e79 + 3883827 commit 6456f3e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
30 changes: 28 additions & 2 deletions actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def styles_select_top(ssafile: SSAFile, **kwargs):
return [ssafile.styles.get(key)]


def styles_action_scale(ssafile: SSAFile, style: SSAStyle, **kwargs):
def styles_action_scale_margins(ssafile: SSAFile, style: SSAStyle, **kwargs):

y_ratio = float(kwargs["y_new"]) / float(kwargs["y_old"])
x_ratio = float(kwargs["x_new"]) / float(kwargs["x_old"])
Expand All @@ -50,7 +50,27 @@ def styles_action_scale(ssafile: SSAFile, style: SSAStyle, **kwargs):
return style


def events_action_scale(ssafile: SSAFile, event: SSAEvent, **kwargs):
def styles_action_scale(ssafile: SSAFile, style: SSAStyle, **kwargs):
return styles_action_scale_margins(ssafile, style, **kwargs)


def events_action_scale_position(ssafile: SSAFile, event: SSAEvent, **kwargs):

y_ratio = float(kwargs["y_new"]) / float(kwargs["y_old"])
x_ratio = float(kwargs["x_new"]) / float(kwargs["x_old"])

m: re.Match
for m in re.finditer(r"\\pos\(([0-9\.]+),([0-9\.]+)\)", str(event.text)):
x_pos = float(m.group(1)) * x_ratio
y_pos = float(m.group(2)) * y_ratio

new_pos = f"\\pos({x_pos:.1f},{y_pos:.1f})"
event.text = event.text.replace(str(m.group(0)), new_pos)

return event


def events_action_scale_margins(ssafile: SSAFile, event: SSAEvent, **kwargs):

y_ratio = float(kwargs["y_new"]) / float(kwargs["y_old"])
x_ratio = float(kwargs["x_new"]) / float(kwargs["x_old"])
Expand All @@ -62,6 +82,12 @@ def events_action_scale(ssafile: SSAFile, event: SSAEvent, **kwargs):
return event


def events_action_scale(ssafile: SSAFile, event: SSAEvent, **kwargs):
events_action_scale_margins(ssafile, event, **kwargs)
events_action_scale_position(ssafile, event, **kwargs)
return event


def styles_action_update_properties(ssafile: SSAFile, style: SSAStyle, **kwargs):
style.__dict__.update(kwargs)

Expand Down
11 changes: 9 additions & 2 deletions postprocess.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ ass:
- uses: styles_select_all
actions:
# Scales Existing font / margins with new player resolution
- uses: styles_action_scale
- uses: styles_action_scale_margins
with:
x_old: "{{outputs['old_info'][0]['PlayResX']}}"
y_old: "{{outputs['old_info'][0]['PlayResY']}}"
Expand Down Expand Up @@ -69,7 +69,14 @@ ass:
- uses: events_select_all

actions:
- uses: events_action_scale
- uses: events_action_scale_margins
with:
x_old: "{{outputs['old_info'][0]['PlayResX']}}"
y_old: "{{outputs['old_info'][0]['PlayResY']}}"
x_new: "{{outputs['info'][0]['PlayResX']}}"
y_new: "{{outputs['info'][0]['PlayResY']}}"

- uses: events_action_scale_position
with:
x_old: "{{outputs['old_info'][0]['PlayResX']}}"
y_old: "{{outputs['old_info'][0]['PlayResY']}}"
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
babelfish==0.6.1
cachetools==5.3.3
cachetools==5.4.0
pgsrip==0.1.11
pysubs2==1.6.1
pysubs2==1.7.2
PyYAML==6.0.1
tqdm_loggable==0.2
watchdog==4.0.1

0 comments on commit 6456f3e

Please sign in to comment.