precompile regex hls
This commit is contained in:
parent
6cd4acd9c3
commit
1cff970ecf
@ -218,7 +218,6 @@ except Exception as e:
|
|||||||
logger.info(e)
|
logger.info(e)
|
||||||
|
|
||||||
async def rewrite(upstream, current, proxy):
|
async def rewrite(upstream, current, proxy):
|
||||||
rewrite_start = (time.time_ns() // 1_000_000)
|
|
||||||
ndata = None
|
ndata = None
|
||||||
text = None
|
text = None
|
||||||
try:
|
try:
|
||||||
@ -230,9 +229,11 @@ async def rewrite(upstream, current, proxy):
|
|||||||
if text is not None:
|
if text is not None:
|
||||||
lines = text.splitlines()
|
lines = text.splitlines()
|
||||||
links = []
|
links = []
|
||||||
|
pattern_match = re.compile(r'(?<=URI=").+(?=")')
|
||||||
|
pattern_sub = re.compile(r'URI=".+"')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("#EXT-X-KEY:METHOD="):
|
if line.startswith("#EXT-X-KEY:METHOD="):
|
||||||
matches = re.findall(r'(?<=URI=").+(?=")', line)
|
matches = pattern_match.findall(line)
|
||||||
if len(matches) == 1:
|
if len(matches) == 1:
|
||||||
ldata = {}
|
ldata = {}
|
||||||
ldata["upstream"] = urllib.parse.urljoin(current, matches[0])
|
ldata["upstream"] = urllib.parse.urljoin(current, matches[0])
|
||||||
@ -260,17 +261,15 @@ async def rewrite(upstream, current, proxy):
|
|||||||
links = json.loads(link_text)
|
links = json.loads(link_text)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
if line.startswith("#EXT-X-KEY:METHOD="):
|
if line.startswith("#EXT-X-KEY:METHOD="):
|
||||||
matches = re.findall(r'(?<=URI=").+(?=")', line)
|
matches = pattern_match.findall(line)
|
||||||
if len(matches) == 1:
|
if len(matches) == 1:
|
||||||
new_url = links.pop(0)
|
new_url = links.pop(0)
|
||||||
ndata += re.sub(r'URI=".+"', f'URI="{new_url}"', line)
|
ndata += pattern_sub.sub(f'URI="{new_url}"', line)
|
||||||
elif line.startswith("#"):
|
elif line.startswith("#"):
|
||||||
ndata += line
|
ndata += line
|
||||||
else:
|
else:
|
||||||
ndata += links.pop(0)
|
ndata += links.pop(0)
|
||||||
ndata += "\n"
|
ndata += "\n"
|
||||||
rewrite_stop = (time.time_ns() // 1_000_000)
|
|
||||||
logger.info(str(rewrite_stop - rewrite_start))
|
|
||||||
return ndata
|
return ndata
|
||||||
|
|
||||||
class MainHandler(tornado.web.RequestHandler):
|
class MainHandler(tornado.web.RequestHandler):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user