improve the way lines are pulled from fountain file
This commit is contained in:
@@ -15,7 +15,7 @@ punc_list = ['.', '!', '?', ';', '--']
|
||||
re_punc_list = [re.escape(punc) for punc in punc_list]
|
||||
|
||||
fountain_file = util.arg(1, usage)
|
||||
character = util.arg(2, usage)
|
||||
character = util.arg(2, usage).upper()
|
||||
audio_filenames = util.args(3, usage)
|
||||
|
||||
lines = ""
|
||||
@@ -27,56 +27,34 @@ fmap = util.FuzzyMap()
|
||||
all_partials = {}
|
||||
prev_found = {}
|
||||
|
||||
idx = 0
|
||||
while idx < len(lines) - 1:
|
||||
line = lines[idx].strip()
|
||||
idx += 1
|
||||
for idx, line in enumerate(lines):
|
||||
if not line.startswith(character):
|
||||
continue
|
||||
|
||||
# If it ends with punctuation, it's probably a screen line!
|
||||
for punc in punc_list:
|
||||
if line.endswith(punc):
|
||||
continue
|
||||
|
||||
if len(line) == 0:
|
||||
continue
|
||||
|
||||
# If it has lower-case letters, it's not a speech name
|
||||
tokens = line.split(" ")
|
||||
all_upper = True
|
||||
for token in tokens:
|
||||
if token.upper() != token:
|
||||
all_upper = False
|
||||
while idx < len(lines) - 1:
|
||||
next_line = lines[idx+1]
|
||||
if len(next_line.strip()) == 0:
|
||||
break
|
||||
|
||||
# It's probably a speech name
|
||||
if all_upper:
|
||||
name = line
|
||||
if '(' in name:
|
||||
name = name[:name.find('(')].strip()
|
||||
|
||||
line = lines[idx].strip()
|
||||
idx += 1
|
||||
|
||||
# Skip wryly lines
|
||||
if line.startswith('('):
|
||||
line = line[line.find(')') + 1:].strip()
|
||||
if len(line) == 0:
|
||||
line = lines[idx].strip()
|
||||
idx += 1
|
||||
|
||||
if character.upper() != name:
|
||||
continue
|
||||
|
||||
# Put the line in the map
|
||||
fmap.put(line, [])
|
||||
# TODO this is experimental:
|
||||
# Put each part of the line in the map, so we can try to catch partial parts!
|
||||
partials = re.split('|'.join(re_punc_list), line)
|
||||
if len(partials) > 1:
|
||||
for part in partials:
|
||||
part = part.strip()
|
||||
fmap.put(part, [])
|
||||
all_partials[part] = True
|
||||
if next_line.startswith('('):
|
||||
next_line = next_line[next_line.find(')') + 1:].strip()
|
||||
if len(next_line) != 0:
|
||||
# Put the line in the map
|
||||
fmap.put(next_line, [])
|
||||
# TODO this is experimental:
|
||||
# Put each part of the line in the map, so we can try to catch partial parts!
|
||||
partials = re.split('|'.join(re_punc_list), next_line)
|
||||
if len(partials) > 1:
|
||||
for part in partials:
|
||||
part = part.strip()
|
||||
fmap.put(part, [])
|
||||
all_partials[part] = True
|
||||
idx += 1
|
||||
|
||||
map = fmap.map
|
||||
print(map)
|
||||
|
||||
Reference in New Issue
Block a user