How to use the m3u8.model.Key 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_replace_segment_key():
    obj = m3u8.M3U8(playlists.PLAYLIST_WITH_MULTIPLE_KEYS_UNENCRYPTED_AND_ENCRYPTED)

    # Replace unencrypted segments with new key
    new_key = Key("AES-128", None, "/hls-key/key0.bin", iv="0Xcafe8f758ca555115584bb5b3c687f52")
    for segment in obj.segments.by_key(None):
        segment.key = new_key

    # Check dump
    expected = playlists.PLAYLIST_WITH_MULTIPLE_KEYS_UNENCRYPTED_AND_ENCRYPTED_UPDATED.strip()

    assert obj.dumps().strip() == expected
github globocom / m3u8 / tests / test_loader.py View on Github external
def test_absolute_uri_should_handle_empty_base_uri_path():
    key = m3u8.model.Key(method='AES', uri='/key.bin',
                         base_uri='http://example.com')
    assert 'http://example.com/key.bin' == key.absolute_uri
github globocom / m3u8 / m3u8 / model.py View on Github external
output.append('URI=' + quoted(self.uri))
        if self.byterange:
            output.append('BYTERANGE=' + self.byterange)
        return "{tag}:{attributes}".format(tag=self.tag, attributes=",".join(output))

    def __eq__(self, other):
        if not other:
            return False
        return self.uri == other.uri and \
            self.byterange == other.byterange and \
            self.base_uri == other.base_uri

    def __ne__(self, other):
        return not self.__eq__(other)

class SessionKey(Key):
    tag = ext_x_session_key

class Playlist(BasePathMixin):
    '''
    Playlist object representing a link to a variant M3U8 with a specific bitrate.

    Attributes:

    `stream_info` is a named tuple containing the attributes: `program_id`,
    `bandwidth`, `average_bandwidth`, `resolution`, `codecs` and `resolution`
    which is a a tuple (w, h) of integers

    `media` is a list of related Media entries.

    More info: http://tools.ietf.org/html/draft-pantos-http-live-streaming-07#section-3.3.10
    '''
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', []) ])