Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.layout_info = "My Layout"
self.caps = CaptionList([1, 2, 3], layout_info=self.layout_info)
def test_rmul(self):
newcaps = 2 * self.caps
self.assertTrue(isinstance(newcaps, CaptionList))
self.assertTrue(newcaps.layout_info == self.layout_info)
def merge_concurrent_captions(caption_set):
"""Merge captions that have the same start and end times"""
for lang in caption_set.get_languages():
captions = caption_set.get_captions(lang)
last_caption = None
concurrent_captions = CaptionList()
merged_captions = CaptionList()
for caption in captions:
if last_caption:
last_timespan = last_caption.start, last_caption.end
current_timespan = caption.start, caption.end
if current_timespan == last_timespan:
concurrent_captions.append(caption)
last_caption = caption
continue
else:
merged_captions.append(merge(concurrent_captions))
concurrent_captions = [caption]
last_caption = caption
if concurrent_captions:
merged_captions.append(merge(concurrent_captions))
def merge_concurrent_captions(caption_set):
"""Merge captions that have the same start and end times"""
for lang in caption_set.get_languages():
captions = caption_set.get_captions(lang)
last_caption = None
concurrent_captions = CaptionList()
merged_captions = CaptionList()
for caption in captions:
if last_caption:
last_timespan = last_caption.start, last_caption.end
current_timespan = caption.start, caption.end
if current_timespan == last_timespan:
concurrent_captions.append(caption)
last_caption = caption
continue
else:
merged_captions.append(merge(concurrent_captions))
concurrent_captions = [caption]
last_caption = caption
if concurrent_captions:
merged_captions.append(merge(concurrent_captions))
if merged_captions:
def get_all(self):
"""Returns the Caption collection as a CaptionList
:rtype: CaptionList
"""
caption_list = CaptionList()
for precap in self._collection:
caption_list.append(precap.to_real_caption())
return caption_list
def _parse(self, lines):
captions = CaptionList()
start = None
end = None
nodes = []
layout_info = None
found_timing = False
for i, line in enumerate(lines):
if '-->' in line:
found_timing = True
timing_line = i
last_start_time = captions[-1].start if captions else 0
try:
start, end, layout_info = self._parse_timing_line(
line, last_start_time)
except CaptionReadError as e:
def _translate_div(self, div):
return CaptionList(
[self._translate_p_tag(p_tag) for p_tag in div.find_all('p')],
div.layout_info
)
def adjust_caption_timing(self, offset=0, rate_skew=1.0):
"""
Adjust the timing according to offset and rate_skew.
Skew is applied first, then offset.
e.g. if skew == 1.1, and offset is 5, a caption originally
displayed from 10-11 seconds would instead be at 16-17.1
"""
for lang in self.get_languages():
captions = self.get_captions(lang)
out_captions = CaptionList()
for caption in captions:
caption.start = caption.start * rate_skew + offset
caption.end = caption.end * rate_skew + offset
if caption.start >= 0:
out_captions.append(caption)
self.set_captions(lang, out_captions)
def __mul__(self, other):
return CaptionList(
list.__mul__(self, other), layout_info=self.layout_info)