create all links at once
This commit is contained in:
parent
b77e0a11cc
commit
9f8a966edb
28
stream.py
28
stream.py
@ -84,18 +84,40 @@ def rewrite(current, provider):
|
||||
ndata = None
|
||||
if resp.text is not None:
|
||||
ndata = ""
|
||||
links = []
|
||||
for line in resp.text.splitlines():
|
||||
if line.startswith("#EXT-X-KEY:METHOD="):
|
||||
matches = re.findall(r'(?<=URI=").+(?=")', line)
|
||||
if len(matches) == 1:
|
||||
new_url = get_proxy_url(proxy, current, matches[0])
|
||||
ldata = {}
|
||||
ldata["upstream"] = urllib.parse.urljoin(current, matches[0])
|
||||
ldata["proxy"] = proxy
|
||||
ldata["proxied"] = isinstance(proxy, str)
|
||||
links.append(ldata)
|
||||
elif line.startswith("#"):
|
||||
pass
|
||||
else:
|
||||
ldata = {}
|
||||
ldata["upstream"] = urllib.parse.urljoin(current, line)
|
||||
ldata["proxy"] = proxy
|
||||
ldata["proxied"] = isinstance(proxy, str)
|
||||
links.append(ldata)
|
||||
presp = requests.post(proxy_server, json=links)
|
||||
if isinstance(presp.text, str):
|
||||
print(presp.text)
|
||||
links = json.loads(presp.text)
|
||||
for line in resp.text.splitlines():
|
||||
if line.startswith("#EXT-X-KEY:METHOD="):
|
||||
matches = re.findall(r'(?<=URI=").+(?=")', line)
|
||||
if len(matches) == 1:
|
||||
new_url = links.pop(0)
|
||||
ndata += re.sub(r'URI=".+"', f'URI="{new_url}"', line)
|
||||
elif line.startswith("#"):
|
||||
ndata += line
|
||||
else:
|
||||
ndata += get_proxy_url(proxy, current, line)
|
||||
ndata += links.pop(0)
|
||||
ndata += "\n"
|
||||
return ndata
|
||||
return ndata
|
||||
|
||||
class MainHandler(tornado.web.RequestHandler):
|
||||
def handle_any(self, write):
|
||||
|
Loading…
Reference in New Issue
Block a user