diff --git a/cdl_convert/parse.py b/cdl_convert/parse.py index 1c59e86..93ded1a 100644 --- a/cdl_convert/parse.py +++ b/cdl_convert/parse.py @@ -469,16 +469,15 @@ 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\. -]+)\)', @@ -500,17 +499,27 @@ 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 + ccMatcher = re.compile(r'(\d*.+)(\n*.*)(\*\ *FROM.+)(\n*.*)(\*\ *ASC_(SOP|SAT).+)(\n*.*)(\*\ *ASC_(SOP|SAT).+)') + clipEntries = ccMatcher.findall(lines) + for entry in clipEntries: + clip = entry[2] + sop = None + sat = None + i=0 + for group in entry: + 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: + cc = parse_cmx_clip((clip, sop, sat)) + cdls.append(cc) else: continue - cdls.append(cc) ccc = collection.ColorCollection() ccc.file_in = input_file