log to stdout

This commit is contained in:
Roy Olav Purser 2021-05-14 18:57:26 +02:00
parent fa8eec1769
commit bca13c0d4a
Signed by: roypur
GPG Key ID: E14D26A036F21656

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import json import json
import sys
import urllib.parse import urllib.parse
import re import re
import os import os
@ -11,7 +12,7 @@ import tornado.routing
import aiohttp import aiohttp
import aiohttp_socks import aiohttp_socks
logging.basicConfig(format='[%(filename)s:%(lineno)d] %(message)s', level=logging.INFO) logging.basicConfig(format='[%(filename)s:%(lineno)d] %(message)s', stream=sys.stdout, level=logging.INFO)
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
providers = {} providers = {}
@ -247,8 +248,9 @@ async def rewrite(current, proxy):
except Exception as e: except Exception as e:
logger.info(e) logger.info(e)
if text is not None: if text is not None:
lines = text.splitlines()
links = [] links = []
for line in text.splitlines(): 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 = re.findall(r'(?<=URI=").+(?=")', line)
if len(matches) == 1: if len(matches) == 1:
@ -276,7 +278,7 @@ async def rewrite(current, proxy):
else: else:
if isinstance(link_text, str): if isinstance(link_text, str):
links = json.loads(link_text) links = json.loads(link_text)
for line in text.splitlines(): 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 = re.findall(r'(?<=URI=").+(?=")', line)
if len(matches) == 1: if len(matches) == 1:
@ -339,8 +341,6 @@ class MainHandler(tornado.web.RequestHandler):
else: else:
upstream_proxy = await handler.proxy.proxy_url(upstream, None) upstream_proxy = await handler.proxy.proxy_url(upstream, None)
ctype = await handler.proxy.content_type(upstream_proxy) ctype = await handler.proxy.content_type(upstream_proxy)
logger.info(ctype)
logger.info(upstream)
data = None data = None
if "mpegurl" in ctype.lower(): if "mpegurl" in ctype.lower():
data = await rewrite(upstream, handler.proxy) data = await rewrite(upstream, handler.proxy)