How to use the pycaption.base.CaptionList function in pycaption

To help you get started, we’ve selected a few pycaption examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pbs / pycaption / tests / test_base.py View on Github external
def setUp(self):
        self.layout_info = "My Layout"
        self.caps = CaptionList([1, 2, 3], layout_info=self.layout_info)
github pbs / pycaption / tests / test_base.py View on Github external
def test_rmul(self):
        newcaps = 2 * self.caps
        self.assertTrue(isinstance(newcaps, CaptionList))
        self.assertTrue(newcaps.layout_info == self.layout_info)
github pbs / pycaption / pycaption / base.py View on Github external
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))
github pbs / pycaption / pycaption / base.py View on Github external
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:
github pbs / pycaption / pycaption / scc / specialized_collections.py View on Github external
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
github pbs / pycaption / pycaption / webvtt.py View on Github external
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:
github pbs / pycaption / pycaption / dfxp / base.py View on Github external
def _translate_div(self, div):
        return CaptionList(
            [self._translate_p_tag(p_tag) for p_tag in div.find_all('p')],
            div.layout_info
        )
github pbs / pycaption / pycaption / base.py View on Github external
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)
github pbs / pycaption / pycaption / base.py View on Github external
def __mul__(self, other):
        return CaptionList(
            list.__mul__(self, other), layout_info=self.layout_info)