How to use the m3u8.model.Segment function in m3u8

To help you get started, we’ve selected a few m3u8 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 globocom / m3u8 / tests / test_model.py View on Github external
def test_add_segment_to_playlist():
    obj = m3u8.M3U8()

    obj.add_segment(
        Segment(
            'entire.ts',
            'http://1.2/',
            duration=1
        )
github globocom / m3u8 / tests / test_model.py View on Github external
def test_add_part_to_segment():
    obj = Segment(
        uri='fileSequence271.ts',
        duration=4.00008
    )

    obj.add_part(
        PartialSegment(
            None,
            'filePart271.0.ts',
            0.33334
        )
    )

    result = obj.dumps(None)
    expected = '#EXT-X-PART:DURATION=0.33334,URI="filePart271.0.ts"'

    assert expected in result
github globocom / m3u8 / tests / test_model.py View on Github external
def test_base_path_should_just_return_uri_if_absolute():
    segment = Segment('http://1.2/entire.ts', '')
    assert 'http://1.2/entire.ts' == segment.absolute_uri
github globocom / m3u8 / tests / test_model.py View on Github external
def test_should_correctly_update_base_path_if_its_blank():
    segment = Segment('entire.ts', 'http://1.2/')
    assert not segment.base_path
    segment.base_path = "base_path"
    assert "http://1.2/base_path/entire.ts" == segment.absolute_uri
github globocom / m3u8 / tests / test_model.py View on Github external
def test_segment_str_method():
    segment = Segment('entire.ts', 'http://1.2/', duration=1)

    expected = '#EXTINF:1,\nentire.ts'
    result = str(segment).strip()

    assert result == expected
github globocom / m3u8 / m3u8 / model.py View on Github external
def _initialize_attributes(self):
        self.keys = [ Key(base_uri=self.base_uri, **params) if params else None
                      for params in self.data.get('keys', []) ]
        self.segments = SegmentList([ Segment(base_uri=self.base_uri, keyobject=find_key(segment.get('key', {}), self.keys), **segment)
                                      for segment in self.data.get('segments', []) ])
        #self.keys = get_uniques([ segment.key for segment in self.segments ])
        for attr, param in self.simple_attributes:
            setattr(self, attr, self.data.get(param))

        self.files = []
        for key in self.keys:
            # Avoid None key, it could be the first one, don't repeat them
            if key and key.uri not in self.files:
                self.files.append(key.uri)
        self.files.extend(self.segments.uri)

        self.media = MediaList([ Media(base_uri=self.base_uri, **media)
                                 for media in self.data.get('media', []) ])

        self.playlists = PlaylistList([ Playlist(base_uri=self.base_uri, media=self.media, **playlist)
github globocom / m3u8 / m3u8 / model.py View on Github external
def base_path(self):
        return super(Segment, self).base_path