Skip to content

Commit

Permalink
Merge a193896 into feae1e5
Browse files Browse the repository at this point in the history
  • Loading branch information
maxnbk committed Apr 19, 2016
2 parents feae1e5 + a193896 commit 53e789a
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions cdl_convert/parse.py
Expand Up @@ -75,6 +75,7 @@

from ast import literal_eval
import os
import sys
import re
from xml.etree import ElementTree

Expand Down Expand Up @@ -469,19 +470,20 @@ def parse_cmx(input_file): # pylint: disable=R0912,R0914
cdls = []

with open(input_file, 'rb') as edl:
lines = edl.readlines()
lines = '\n'.join(edl.readlines())

filename = os.path.basename(input_file).split('.')[0]

def parse_cmx_clip(cmx_tuple):

"""Parses a three line cmx clip tuple."""
if len(cmx_tuple) != 3:
print(cmx_tuple)
return
title = cmx_tuple[0].split()[1]
title = cmx_tuple[0].split(': ')[1]

sop = re.match(
r'^\*ASC_SOP \(([\d\. -]+)\)\(([\d\. -]+)\)\(([\d\. -]+)\)',
r'^ASC_SOP \(([\d\. -]+)\)\(([\d\. -]+)\)\(([\d\. -]+)\)',
cmx_tuple[1]
)
if not sop:
Expand All @@ -500,18 +502,33 @@ def parse_cmx_clip(cmx_tuple):

return cc

for i, line in enumerate(lines):
if line != '\r\n':
# We only care about newlines when reading CMX, because
# we use those to kick off parsing the next take.
continue
if i + 3 <= len(lines):
cc = parse_cmx_clip(lines[i + 1:i + 4])
'''This regex will avoid caring about extra stuff between
the important lines we care about as long as the important
lines we care about are in the right order'''
if ( ( len(re.findall(r'FROM', lines)) + len(re.findall(r'LOC', lines)) ) * 2) != len(re.findall(r'ASC', lines)):
sys.exit("Inequal amounts of CLIP|LOC, ASC, SAT lines - Exiting")

cc_matcher = re.compile(r'(\n+\d+.*)([\s\S]+?)(\*[\s]*?((ASC_(SOP|SAT).+)|(FROM.*|LOC.*)))([\s\S]+?)(\*[\s]*?((ASC_(SOP|SAT).+)|(FROM.*|LOC.*)))([\s\S]+?)(\*[\s]*?((ASC_(SOP|SAT).+)|(FROM.*|LOC.*)))')
clip_entries = cc_matcher.findall(lines)
for entry in clip_entries:
clip = None
sop = None
sat = None
i = 0
for group in entry:
if ('FROM' in group or 'LOC' in group) and clip is None:
clip = group
if group == 'SOP':
sop = entry[i - 1]
if group == 'SAT':
sat = entry[i - 1]
i += 1
if clip is not None and sop is not None and sat is not None:
colorCorrect = parse_cmx_clip((clip, sop, sat))
cdls.append(colorCorrect)
else:
continue

cdls.append(cc)

ccc = collection.ColorCollection()
ccc.file_in = input_file
ccc.append_children(cdls)
Expand Down

0 comments on commit 53e789a

Please sign in to comment.