How to use the m3u8.model.Media 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_base_path_with_optional_uri_should_do_nothing():
    media = Media(type='AUDIO', group_id='audio-group', name='English')
    assert media.uri is None
    assert media.base_uri is None
    media.base_path = "base_path"
    assert media.absolute_uri is None
    assert media.base_path is None
github globocom / m3u8 / tests / test_model.py View on Github external
def test_medialist_uri_method():
    langs = ['English', 'French', 'German']
    ml = MediaList()
    for lang in langs:
        ml.append(Media(type='AUDIO', group_id='audio-group', name=lang, uri=('/%s.m3u8' % lang)))

    assert len(ml.uri) == len(langs)
    assert ml.uri[0] == '/%s.m3u8' % langs[0]
    assert ml.uri[1] == '/%s.m3u8' % langs[1]
    assert ml.uri[2] == '/%s.m3u8' % langs[2]
github globocom / m3u8 / m3u8 / model.py View on Github external
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)
                                        for playlist in self.data.get('playlists', []) ])

        self.iframe_playlists = PlaylistList()
        for ifr_pl in self.data.get('iframe_playlists', []):
            self.iframe_playlists.append(IFramePlaylist(base_uri=self.base_uri,
                                         uri=ifr_pl['uri'],
                                         iframe_stream_info=ifr_pl['iframe_stream_info'])
                                        )
        self.segment_map = self.data.get('segment_map')

        start = self.data.get('start', None)
        self.start = start and Start(**start)