Skip to content

Commit a4d4b64

Browse files
committed
Allow for _pt1 postfixes
1 parent 85e7101 commit a4d4b64

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

locatorator/__init__.py

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import typing, enum, re, copy, dataclasses
22
from timecode import Timecode, TimecodeRange
33

4-
PAT_VFX_MARKER = re.compile(r"^\s*[a-z]{2,4}[0-9]{3,4}", re.IGNORECASE)
4+
PAT_VFX_MARKER = re.compile(r"^\s*[a-z]{2,4}[0-9]{3,4}(?:[^\sa-z0-9][a-z0-9]+\b)?", re.IGNORECASE)
55
"""Pattern for matching a VFX ID marker comment"""
6+
# Support: LF1020
7+
# LF1020 and some extraneous stuff
8+
# LF1020_pt1
9+
# LF1020-pt2 and some extraneous stuff
610

711
class MarkerListFormats(enum.Enum):
812
"""Marker list formats supported"""
@@ -16,8 +20,6 @@ class MarkerListFormats(enum.Enum):
1620
}
1721
"""Regex parsers per supported marker list format"""
1822

19-
20-
2123
class MarkerColors(enum.Enum):
2224
"""Avid marker colors"""
2325

@@ -212,10 +214,12 @@ class MarkerChangeReport:
212214
relative_offset:typing.Optional[Timecode] = None
213215
"""Adjusted/relative change between the two lists"""
214216

215-
def is_vfx_marker(marker:Marker) -> bool:
216-
"""Filter VFX markers. For a moment it's hard-coded to format: `ABC1234`"""
217-
218-
return bool(PAT_VFX_MARKER.match(marker.comment))
217+
def vfx_id_from_marker(marker:Marker) -> str|None:
218+
"""Return the VFX ID found in the marker, or `None`"""
219+
220+
match = PAT_VFX_MARKER.match(marker.comment)
221+
222+
return match.group() if match else None
219223

220224
def get_marker_list_from_file(file_input:typing.TextIO) -> typing.List[Marker]:
221225
"""Parse a marker list from a file pointer"""
@@ -233,7 +237,7 @@ def get_marker_list_from_file(file_input:typing.TextIO) -> typing.List[Marker]:
233237
# continue
234238

235239
# NOTE FOR NOW: Hard coding to ABC1234
236-
if is_vfx_marker(marker):
240+
if vfx_id_from_marker(marker):
237241
markers.append(marker)
238242

239243
return markers
@@ -247,7 +251,7 @@ def build_marker_lookup(marker_list:typing.Iterable[Marker]) -> dict[str, Marker
247251

248252

249253
# NOTE: Combine this somehow with is_valid_marker
250-
vfx_id = PAT_VFX_MARKER.match(marker.comment).group()
254+
vfx_id = vfx_id_from_marker(marker)
251255

252256
if not vfx_id:
253257
raise ValueError(f"VFX ID not found in marker: {marker.comment}")
@@ -264,18 +268,15 @@ def build_marker_changes(markers_old:typing.Iterable[Marker], markers_new:typing
264268
# TODO: This still feels like it's doing too much
265269

266270
marker_lookup_old = build_marker_lookup(markers_old)
271+
marker_lookup_new = build_marker_lookup(markers_new)
267272

268273
running_offset = Timecode(0) # The total number of frames offset from the beginning
269274
marker_pairs = []
270275

271-
for marker_new in markers_new:
272-
273-
# TODO: Marker export: Change comment should beginwith VFX ID for
274-
275-
new_vfx_id = PAT_VFX_MARKER.match(marker_new.comment).group()
276+
for vfx_id, marker_new in marker_lookup_new.items():
276277

277278
# TODO: Rework as `if marker_new.comment.lower() not in marker_lookup_old:`?
278-
marker_old = marker_lookup_old.get(new_vfx_id)
279+
marker_old = marker_lookup_old.get(vfx_id)
279280
absolute_offset = marker_new.timecode.start - marker_old.timecode.start if marker_old else 0
280281
relative_offset = absolute_offset-running_offset
281282

@@ -291,7 +292,7 @@ def build_marker_changes(markers_old:typing.Iterable[Marker], markers_new:typing
291292
marker_new = marker_new,
292293
relative_offset = relative_offset
293294
)
294-
del marker_lookup_old[new_vfx_id]
295+
del marker_lookup_old[vfx_id]
295296

296297
if relative_offset != 0:
297298
running_offset = absolute_offset
@@ -319,21 +320,18 @@ def write_change_list(markers_changes:typing.Iterable[MarkerChangeReport], file_
319320
if marker_change.change_type not in change_types:
320321
continue
321322

322-
323+
vfx_id = vfx_id_from_marker(marker_change.marker_new) if marker_change.change_type == ChangeTypes.ADDED else vfx_id_from_marker(marker_change.marker_old)
324+
323325
if marker_change.change_type == ChangeTypes.ADDED:
324-
vfx_id = PAT_VFX_MARKER.match(marker_change.marker_new.comment).group()
325326
comment=f"{vfx_id} - Shot added: {marker_change.marker_new.comment}"
326327

327328
elif marker_change.change_type == ChangeTypes.CHANGED:
328-
vfx_id = PAT_VFX_MARKER.match(marker_change.marker_old.comment).group()
329329
comment=f"{vfx_id} - Cut change near {marker_change.marker_old.comment} ({'+' if marker_change.relative_offset.frame_number > 0 else ''}{marker_change.relative_offset})"
330330

331331
elif marker_change.change_type == ChangeTypes.DELETED:
332-
vfx_id = PAT_VFX_MARKER.match(marker_change.marker_old.comment).group()
333332
comment=f"{vfx_id} - Shot removed since last cut: {marker_change.marker_old.comment}"
334333

335334
elif marker_change.change_type == ChangeTypes.UNCHANGED:
336-
vfx_id = PAT_VFX_MARKER.match(marker_change.marker_old.comment).group()
337335
comment=f"{vfx_id} - Shot unchanged since last cut: {marker_change.marker_old.comment}"
338336

339337
else:

0 commit comments

Comments
 (0)