Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_key_attribute_on_none():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST)
mock_parser_data(obj, {})
assert len(obj.keys) == 0
def test_m3u8_should_propagate_base_uri_to_session_key():
with open(playlists.RELATIVE_PLAYLIST_FILENAME) as f:
content = f.read()
obj = m3u8.M3U8(content, base_uri='/any/path')
assert '../key.bin' == obj.session_keys[0].uri
assert '/any/key.bin' == obj.session_keys[0].absolute_uri
obj.base_uri = '/any/where/'
assert '../key.bin' == obj.session_keys[0].uri
assert '/any/key.bin' == obj.session_keys[0].absolute_uri
def test_iframe_playlists_base_path_update():
obj = m3u8.M3U8(playlists.VARIANT_PLAYLIST_WITH_IFRAME_PLAYLISTS)
assert obj.iframe_playlists[0].uri == 'video-800k-iframes.m3u8'
assert obj.iframe_playlists[0].base_uri == None
obj.base_path = 'http://localhost/base_path'
obj.base_uri = 'http://localhost/base_uri'
assert obj.iframe_playlists[0].uri == 'http://localhost/base_path/video-800k-iframes.m3u8'
assert obj.iframe_playlists[0].base_uri == 'http://localhost/base_uri'
def test_partial_segment_base_path_update():
obj = m3u8.M3U8(playlists.LOW_LATENCY_DELTA_UPDATE_PLAYLIST)
obj.base_path = 'http://localhost/base_path'
obj.base_uri = 'http://localhost/base_uri'
assert obj.segments[2].parts[0].uri == 'http://localhost/base_path/filePart271.0.ts'
assert obj.segments[2].parts[0].base_uri == 'http://localhost/base_uri'
def test_dump_should_work_for_variant_streams():
obj = m3u8.M3U8(playlists.VARIANT_PLAYLIST)
expected = playlists.VARIANT_PLAYLIST.replace(', BANDWIDTH', ',BANDWIDTH').strip()
assert expected == obj.dumps().strip()
def test_should_dump_frame_rate():
obj = m3u8.M3U8(playlists.VARIANT_PLAYLIST_WITH_FRAME_RATE)
expected = playlists.VARIANT_PLAYLIST_WITH_FRAME_RATE.strip()
assert expected == obj.dumps().strip()
def test_independent_segments_should_be_false():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST_WITH_EVENT_PLAYLIST_TYPE)
assert not obj.is_independent_segments
def test_iframe_playlists_attribute():
obj = m3u8.M3U8(playlists.SIMPLE_PLAYLIST)
data = {
'iframe_playlists': [{'uri': '/url/1.m3u8',
'iframe_stream_info': {'program_id': 1,
'bandwidth': 320000,
'resolution': '320x180',
'codecs': 'avc1.4d001f'}},
{'uri': '/url/2.m3u8',
'iframe_stream_info': {'bandwidth': '120000',
'codecs': 'avc1.4d400d'}}]
}
mock_parser_data(obj, data)
assert 2 == len(obj.iframe_playlists)
assert '/url/1.m3u8' == obj.iframe_playlists[0].uri
assert 1 == obj.iframe_playlists[0].iframe_stream_info.program_id
def update(self, use_old_url: bool = False) -> None:
if not use_old_url:
self._url = self._get_playlist_url()
request = get_url(self.url)
self._m3u8 = M3U8(request.text)
if m3u8_obj.is_variant:
for i, playlist in enumerate(m3u8_obj.playlists):
click.echo(
f'{i}: bandwidth={playlist.stream_info.bandwidth} '
f'resolution={playlist.stream_info.resolution} '
f'codecs={playlist.stream_info.codecs} '
)
index = click.prompt(
'Which playlist to download?',
type=click.Choice(list(range(len(m3u8_obj.playlists)))),
value_proc=int,
default=0
)
return await self.download(m3u8_obj.playlists[index].absolute_uri)
else:
tmp_list = m3u8.M3U8()
tmp_list.version = '3'
tmp_list.media_sequence = '0'
tmp_list.target_duration = m3u8_obj.target_duration
tmp_list.is_endlist = True
tasks = []
os.makedirs(self.cache_dir, exist_ok=True)
bar = ShadyBar(self.name, max=len(m3u8_obj.segments), suffix='%(percent).1f%% - %(eta_td)s')
for i, segment in enumerate(m3u8_obj.segments):
tmp_list.add_segment(
m3u8.Segment(
f'{os.path.realpath(self.cache_dir)}/{i}.ts',
duration=segment.duration,
base_uri='file://'
)
)
tasks.append(