def merge_subtitle(sub_a, sub_b, delta): out = WebVTTFile() intervals = [item.start.ordinal for item in sub_a] intervals.extend([item.end.ordinal for item in sub_a]) intervals.extend([item.start.ordinal for item in sub_b]) intervals.extend([item.end.ordinal for item in sub_b]) intervals.sort() j = k = 0 for i in xrange(1, len(intervals)): start = WebVTTTime.from_ordinal(intervals[i - 1]) end = WebVTTTime.from_ordinal(intervals[i]) if (end - start) > delta: text_a, j = find_subtitle(sub_a, start, end, j) text_b, k = find_subtitle(sub_b, start, end, k) text = join_lines(text_a, text_b) if len(text) > 0: item = WebVTTItem(0, start, end, text) out.append(item) out.clean_indexes() return out
def merge_subtitle(sub_a, sub_b, delta): out = WebVTTFile() intervals = [item.start.ordinal for item in sub_a] intervals.extend([item.end.ordinal for item in sub_a]) intervals.extend([item.start.ordinal for item in sub_b]) intervals.extend([item.end.ordinal for item in sub_b]) intervals.sort() j = k = 0 for i in xrange(1, len(intervals)): start = WebVTTTime.from_ordinal(intervals[i - 1]) end = WebVTTTime.from_ordinal(intervals[i]) if (end-start) > delta: text_a, j = find_subtitle(sub_a, start, end, j) text_b, k = find_subtitle(sub_b, start, end, k) text = join_lines(text_a, text_b) if len(text) > 0: item = WebVTTItem(0, start, end, text) out.append(item) out.clean_indexes() return out
def test_from_ordinal(self): self.assertEqual(WebVTTTime.from_ordinal(3600000), {'hours': 1}) self.assertEqual(WebVTTTime(1), 3600000)
def test_from_ordinal(self): self.assertEqual(WebVTTTime.from_ordinal(3600000), {'hours': 1}) self.assertEqual(WebVTTTime(1), 3600000)