def _interval_secs(sections, end_sec_name, begin_index): if end_sec_name == ':end': return audio_slice.audio_len(config['bgm']), sections[begin_index:] end_index, end_section = _find_sec(sections, end_sec_name) if end_index + 1 == len(sections): return audio_slice.audio_len(config['bgm']), sections[begin_index:] if end_index < begin_index: raise ValueError('section disorder') return sections[end_index + 1].start, sections[begin_index: end_index + 1]
def _output(echo): with open(config['sequence'], 'r') as f: sections, total_dur = sequence.parse(f.readlines()) if len(sections) == 0: raise ValueError('no sections') time_off = 0 i = 0 if len(sys.argv) == 2: sec_name = sys.argv[1] for i, s in enumerate(sections): if sec_name == s.name: time_off = s.start break else: raise ValueError('no such section %s' % sec_name) sections = sections[i:] for s in sections: s.start -= time_off for i, s in enumerate(sections[:-1]): echo(i + 1, s, sections[i + 1], sections[i + 1].start) echo(len(sections), sections[-1], None, audio_slice.audio_len(config['bgm']))
def next_section(sec_index, seg_index, expected_len, actual_len): sec = sections[sec_index] print ":.:", sec.name sec_len = 0.0 for seg in sec.segments: seg_len = audio_slice.audio_len(sliced_segs[seg_index]) print " >", seg.duration, seg_len sec_len += seg_len seg_index += 1 actual_len += sec_len if sec_index == len(sections) - 1: expected_len += end_time - sec.start print " :", end_time - sec.start, sec_len, print ":", expected_len, actual_len, actual_len - expected_len return expected_len += sections[sec_index + 1].start - sec.start print " :", sections[sec_index + 1].start - sec.start, sec_len, print ":", expected_len, actual_len, actual_len - expected_len next_section(sec_index + 1, seg_index, expected_len, actual_len)