follow redirect for content-type detection
This commit is contained in:
parent
aad477ef90
commit
8832958112
@ -223,19 +223,8 @@ class MainHandler(tornado.web.RequestHandler):
|
||||
video_info = {}
|
||||
video_info["upstream"] = proxied[0]
|
||||
video_info["poster"] = proxied[1]
|
||||
|
||||
if isinstance(provider_data.ctype(), str):
|
||||
video_info["ctype"] = provider_data.ctype()
|
||||
else:
|
||||
try:
|
||||
async with handler.proxy.local() as session:
|
||||
resp = await session.head(proxied[0])
|
||||
ctype = resp.headers.get("Content-Type", None)
|
||||
if isinstance(ctype, str):
|
||||
video_info["ctype"] = ctype
|
||||
except Exception as e:
|
||||
logger.info(e)
|
||||
|
||||
video_info["ctype"] = provider_data.ctype()
|
||||
|
||||
script = template_script.generate(info=json.dumps(video_info))
|
||||
b64 = str(base64.b64encode(script), "ascii")
|
||||
script_file = f'data:text/javascript;charset=utf-8;base64,{b64}'
|
||||
|
@ -117,18 +117,20 @@ class StreamProvider():
|
||||
proxies = {}
|
||||
proxies["http"] = "socks5://" + self.proxy
|
||||
proxies["https"] = "socks5://" + self.proxy
|
||||
ctype = "binary/octet-stream"
|
||||
ctype = None
|
||||
upstream = data.upstream()
|
||||
try:
|
||||
resp = requests.head(data.upstream(), proxies=proxies, timeout=5)
|
||||
resp = requests.head(data.upstream(), proxies=proxies, timeout=5, allow_redirects=True)
|
||||
except Exception as e:
|
||||
self.logger.info("%s <%s>", e, self.upstream)
|
||||
else:
|
||||
ctype = resp.headers.get("Content-Type", "text/plain").lower()
|
||||
if ctype.startswith("text"):
|
||||
self.logger.info("Bad Content-Type %s", data.upstream())
|
||||
ctype = None
|
||||
elif "mpegurl" in ctype:
|
||||
ctype = "application/vnd.apple.mpegurl"
|
||||
if resp.ok:
|
||||
upstream = resp.url
|
||||
ctype = resp.headers.get("Content-Type", "text/plain").lower()
|
||||
if ctype.startswith("text"):
|
||||
ctype = None
|
||||
elif "mpegurl" in ctype:
|
||||
ctype = "application/vnd.apple.mpegurl"
|
||||
return StreamData(data.upstream(), ctype, data.thumbnail(), data.title(), data.description(), data.override)
|
||||
async def run(self):
|
||||
data = None
|
||||
|
Loading…
Reference in New Issue
Block a user