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)