From df153d5a129c8a7defa20335a8d3cab98d070f3c Mon Sep 17 00:00:00 2001 From: Roy Olav Purser Date: Sat, 15 May 2021 09:45:30 +0200 Subject: [PATCH] retry content type --- stream.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/stream.py b/stream.py index b6e794c..7420339 100755 --- a/stream.py +++ b/stream.py @@ -48,14 +48,18 @@ class ProxyElem(): def __repr__(self): return str(self.proxy) async def content_type(self, url): - ctype = "binary/octet-stream" - try: - async with self.session() as session: - resp = await session.head(url) - ctype = resp.headers.get("Content-Type", "binary/octet-stream") - except Exception as e: - logger.info(e) - return ctype + ctype = None + async with self.session() as session: + for i in range(5): + try: + resp = await session.head(url) + ctype = resp.headers.get("Content-Type", None) + except Exception as e: + logger.info(e) + else: + if isinstance(ctype, str): + return ctype + return "binary/octet-type" async def proxy_url(self, current, path): jdata = None data = {} @@ -348,7 +352,6 @@ class MainHandler(tornado.web.RequestHandler): else: upstream_proxy = await handler.proxy.proxy_url(upstream, None) ctype = await handler.proxy.content_type(upstream_proxy) - logger.info(upstream_proxy) data = None if "mpegurl" in ctype.lower(): data = await rewrite(upstream, handler.proxy)