Handle 404 from master endpoints
authorJakob Cornell <jakob+gpg@jcornell.net>
Tue, 6 Oct 2020 03:22:57 +0000 (22:22 -0500)
committerJakob Cornell <jakob+gpg@jcornell.net>
Tue, 6 Oct 2020 03:22:57 +0000 (22:22 -0500)
hls_watch/__main__.py

index 0450a25a4e59d8776b5b1ed68695973dead62e61..638eea9aa6a75bb39fbfce4105bad641ee88e97a 100644 (file)
@@ -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()))