|
|
@ -21,7 +21,6 @@ from py_mini_racer import MiniRacer
|
|
|
|
from protobuf.douyin import *
|
|
|
|
from protobuf.douyin import *
|
|
|
|
from message_processor import *
|
|
|
|
from message_processor import *
|
|
|
|
from helper import resource_path, PromptQueue, MessageType
|
|
|
|
from helper import resource_path, PromptQueue, MessageType
|
|
|
|
from settings import live_talking_host, Backend
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
@contextmanager
|
|
|
@ -87,7 +86,7 @@ def generateMsToken(length=107):
|
|
|
|
|
|
|
|
|
|
|
|
class DouyinLiveWebFetcher:
|
|
|
|
class DouyinLiveWebFetcher:
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, live_id, ws_open_event, queue: PromptQueue):
|
|
|
|
def __init__(self, ws_open_event, queue: PromptQueue):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
直播间弹幕抓取对象
|
|
|
|
直播间弹幕抓取对象
|
|
|
|
:param live_id: 直播间的直播id,打开直播间web首页的链接如:https://live.douyin.com/261378947940,
|
|
|
|
:param live_id: 直播间的直播id,打开直播间web首页的链接如:https://live.douyin.com/261378947940,
|
|
|
@ -95,7 +94,7 @@ class DouyinLiveWebFetcher:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
self.__ttwid = None
|
|
|
|
self.__ttwid = None
|
|
|
|
self.__room_id = None
|
|
|
|
self.__room_id = None
|
|
|
|
self.live_id = live_id
|
|
|
|
self.live_id = LiveChatConfig().live_id
|
|
|
|
self.live_url = "https://live.douyin.com/"
|
|
|
|
self.live_url = "https://live.douyin.com/"
|
|
|
|
self.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
|
|
|
self.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) " \
|
|
|
|
"Chrome/120.0.0.0 Safari/537.36"
|
|
|
|
"Chrome/120.0.0.0 Safari/537.36"
|
|
|
@ -329,7 +328,7 @@ class DouyinLiveWebReply:
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
def _gen():
|
|
|
|
def _gen():
|
|
|
|
response = requests.post(f'{Backend.backend_host}{Backend.ollama_uri}', json=payload,
|
|
|
|
response = requests.post(f'{self.live_chat_config.ollama_address}/live-digital-avatar-manage/ollama/generate', json=payload,
|
|
|
|
headers={'Authorization': f'Bearer {self.live_chat_config.backend_token}'},
|
|
|
|
headers={'Authorization': f'Bearer {self.live_chat_config.backend_token}'},
|
|
|
|
stream=True)
|
|
|
|
stream=True)
|
|
|
|
buffer = ''
|
|
|
|
buffer = ''
|
|
|
@ -352,7 +351,7 @@ class DouyinLiveWebReply:
|
|
|
|
if stream:
|
|
|
|
if stream:
|
|
|
|
return _gen()
|
|
|
|
return _gen()
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
response = requests.post(f'{Backend.backend_host}{Backend.ollama_uri}', json=payload,
|
|
|
|
response = requests.post(f'{self.live_chat_config.ollama_address}/live-digital-avatar-manage/ollama/generate', json=payload,
|
|
|
|
headers={'Authorization': f'Bearer {self.live_chat_config.backend_token}'},
|
|
|
|
headers={'Authorization': f'Bearer {self.live_chat_config.backend_token}'},
|
|
|
|
timeout=10).content.decode()[5:]
|
|
|
|
timeout=10).content.decode()[5:]
|
|
|
|
response = json.loads(response)
|
|
|
|
response = json.loads(response)
|
|
|
@ -368,7 +367,7 @@ class DouyinLiveWebReply:
|
|
|
|
async def post_to_human(self, text: str):
|
|
|
|
async def post_to_human(self, text: str):
|
|
|
|
async with httpx.AsyncClient() as client:
|
|
|
|
async with httpx.AsyncClient() as client:
|
|
|
|
await client.post(
|
|
|
|
await client.post(
|
|
|
|
f'{live_talking_host}/human',
|
|
|
|
f'{self.live_chat_config.livetalking_address}/human',
|
|
|
|
json={
|
|
|
|
json={
|
|
|
|
"type": "echo",
|
|
|
|
"type": "echo",
|
|
|
|
"sessionid": self.session_id,
|
|
|
|
"sessionid": self.session_id,
|
|
|
@ -384,7 +383,7 @@ class DouyinLiveWebReply:
|
|
|
|
live_chat_config.update_chat_enable_status()
|
|
|
|
live_chat_config.update_chat_enable_status()
|
|
|
|
while True:
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
is_speaking = requests.post(f'{live_talking_host}/is_speaking', json={'sessionid': self.session_id},
|
|
|
|
is_speaking = requests.post(f'{self.live_chat_config.livetalking_address}/is_speaking', json={'sessionid': self.session_id},
|
|
|
|
timeout=5).json()['data']
|
|
|
|
timeout=5).json()['data']
|
|
|
|
if is_speaking:
|
|
|
|
if is_speaking:
|
|
|
|
time.sleep(0.1)
|
|
|
|
time.sleep(0.1)
|
|
|
|