尝试大改,可读性有点差的版本,基本做到能实时处理弹幕

This commit is contained in:
2022-06-03 23:08:43 +08:00
parent 3f95b07009
commit 74a15849ab
16 changed files with 181 additions and 204 deletions

View File

@ -1,16 +1,23 @@
# ! IMPORT ! make sure you ran mitmproxy with this script,
# eg: `/path/to/mitmproxy -s mitmproxy.py`
import uuid
import time
from mitmproxy import http
import re
import requests
import base64
session = requests.session()
class Writer:
def websocket_message(self, flow: http.HTTPFlow) :
re_c = re.search('webcast3-ws-web-.*\.douyin\.com', flow.request.host)
if re_c :
with open('/Users/geng/douyin_live/' + uuid.uuid4().hex, 'wb') as f:
mess = flow.websocket.messages[-1].content
f.write(bytes(mess))
def websocket_message(self, flow: http.HTTPFlow):
re_c = re.search('webcast\d-ws-web-.*\.douyin\.com', flow.request.host)
if re_c:
message = flow.websocket.messages[-1].content
session.post("http://127.0.0.1:5000/message", data=message, headers={
"X-MITM_TS": str(time.time()),
"X_REFERER": flow.request.host
}, timeout=(1, 1))
addons = [Writer()]