From f27cec57e42e007b14017f0ebc631d6264baf861 Mon Sep 17 00:00:00 2001 From: Jakob Cornell Date: Mon, 5 Oct 2020 22:22:57 -0500 Subject: [PATCH] Handle 404 from master endpoints --- hls_watch/__main__.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/hls_watch/__main__.py b/hls_watch/__main__.py index 0450a25..638eea9 100644 --- a/hls_watch/__main__.py +++ b/hls_watch/__main__.py @@ -89,16 +89,17 @@ if __name__ == '__main__': ) if locate_stream: with opener.open(master_url) as resp: - assert resp.status == 200 - lines = resp.read().decode('utf-8').splitlines() + if resp.status == 200: + lines = resp.read().decode('utf-8').splitlines() + streams = parse_master(lines) + if streams: + winner = max(streams, key = lambda s: s.attrs['RESOLUTION'].vertical) + (ep, curr_variant) = re.match(r'(.*)_(.*?)\.m3u8$', winner.uri).groups() + assert ep == stream_spec.endpoint + else: + assert resp.status == 404 time.sleep(_DELAY.total_seconds()) - streams = parse_master(lines) - if streams: - winner = max(streams, key = lambda s: s.attrs['RESOLUTION'].vertical) - (ep, curr_variant) = re.match(r'(.*)_(.*?)\.m3u8$', winner.uri).groups() - assert ep == stream_spec.endpoint - if curr_variant is not None: writer.stream = stream_spec._replace(variant = curr_variant) media_url = url_for_stream('{}.m3u8'.format(writer.stream.full())) -- 2.30.2