create all links at once
This commit is contained in:
parent
b77e0a11cc
commit
9f8a966edb
26
stream.py
26
stream.py
@ -84,16 +84,38 @@ def rewrite(current, provider):
|
|||||||
ndata = None
|
ndata = None
|
||||||
if resp.text is not None:
|
if resp.text is not None:
|
||||||
ndata = ""
|
ndata = ""
|
||||||
|
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="):
|
||||||
matches = re.findall(r'(?<=URI=").+(?=")', line)
|
matches = re.findall(r'(?<=URI=").+(?=")', line)
|
||||||
if len(matches) == 1:
|
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)
|
ndata += re.sub(r'URI=".+"', f'URI="{new_url}"', line)
|
||||||
elif line.startswith("#"):
|
elif line.startswith("#"):
|
||||||
ndata += line
|
ndata += line
|
||||||
else:
|
else:
|
||||||
ndata += get_proxy_url(proxy, current, line)
|
ndata += links.pop(0)
|
||||||
ndata += "\n"
|
ndata += "\n"
|
||||||
return ndata
|
return ndata
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user