live stream test
This commit is contained in:
parent
677648ecdd
commit
c8d51d2e3d
36
stream.py
36
stream.py
@ -220,10 +220,12 @@ try:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.info(e)
|
logger.info(e)
|
||||||
|
|
||||||
def rewrite(current, provider, proxy):
|
async def rewrite(current, provider, proxy):
|
||||||
resp = requests.get(current, proxies=proxy.req)
|
async with proxy.session() as session:
|
||||||
|
resp = await session.get(current)
|
||||||
|
text = await resp.text()
|
||||||
ndata = None
|
ndata = None
|
||||||
if resp.text is not None:
|
if text is not None:
|
||||||
links = []
|
links = []
|
||||||
for line in resp.text.splitlines():
|
for line in resp.text.splitlines():
|
||||||
if line.startswith("#EXT-X-KEY:METHOD="):
|
if line.startswith("#EXT-X-KEY:METHOD="):
|
||||||
@ -244,19 +246,21 @@ def rewrite(current, provider, proxy):
|
|||||||
links.append(ldata)
|
links.append(ldata)
|
||||||
if isinstance(proxy_server, str):
|
if isinstance(proxy_server, str):
|
||||||
ndata = ""
|
ndata = ""
|
||||||
presp = requests.post(proxy_server, json=links)
|
async with proxy.session() as session:
|
||||||
if isinstance(presp.text, str):
|
resp = await session.post(proxy_server, json=links)
|
||||||
links = json.loads(presp.text)
|
link_text = await resp.text()
|
||||||
for line in resp.text.splitlines():
|
if isinstance(link_text, str):
|
||||||
if line.startswith("#EXT-X-KEY:METHOD="):
|
links = json.loads(link_text)
|
||||||
matches = re.findall(r'(?<=URI=").+(?=")', line)
|
for line in text.splitlines():
|
||||||
if len(matches) == 1:
|
if line.startswith("#EXT-X-KEY:METHOD="):
|
||||||
new_url = links.pop(0)
|
matches = re.findall(r'(?<=URI=").+(?=")', line)
|
||||||
ndata += re.sub(r'URI=".+"', f'URI="{new_url}"', line)
|
if len(matches) == 1:
|
||||||
elif line.startswith("#"):
|
new_url = links.pop(0)
|
||||||
ndata += line
|
ndata += re.sub(r'URI=".+"', f'URI="{new_url}"', line)
|
||||||
else:
|
elif line.startswith("#"):
|
||||||
ndata += links.pop(0)
|
ndata += line
|
||||||
|
else:
|
||||||
|
ndata += links.pop(0)
|
||||||
ndata += "\n"
|
ndata += "\n"
|
||||||
return ndata
|
return ndata
|
||||||
class MainHandler(tornado.web.RequestHandler):
|
class MainHandler(tornado.web.RequestHandler):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user